@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,246 +1,260 @@
1
- import { __assign, __decorate, __extends, __metadata } from "tslib";
2
- import * as React from 'react';
3
- import { BindPropsHelper } from './PropTypes';
4
- import { FormContext } from './FormContext';
5
- import { Misc, NumberUtils, Utils } from '@singularsystems/neo-core';
6
- import Decimal from 'decimal.js-light';
7
- import { InputHelpers } from './InputHelpers';
8
- import { observer } from 'mobx-react';
9
- import memoize from 'memoize-one';
10
- import ComponentBase from './ComponentBase';
11
- var FormatState = /** @class */ (function () {
12
- function FormatState(isPercent, hasExternalPercentSymbol, formatString, zeroText) {
13
- this.isPercent = isPercent;
14
- this.hasExternalPercentSymbol = hasExternalPercentSymbol;
15
- this.formatString = formatString;
16
- this.zeroText = zeroText;
17
- }
18
- FormatState.create = function (numericType, numProps, appendText) {
19
- var isPercent = false;
20
- var hasExternalPercentSymbol = false;
21
- var formatString = numProps ? numProps.formatString : "";
22
- if (!formatString) {
23
- if (numProps && numProps.format) {
24
- formatString = NumberUtils.getFormatString(numProps.format, numProps.currencySymbol);
25
- }
26
- else {
27
- var hasDecimals = numericType === Misc.DataType.Float || numericType === Misc.DataType.Decimal;
28
- var format = (numProps === null || numProps === void 0 ? void 0 : numProps.currencySymbol) ?
29
- (hasDecimals ? Misc.NumberFormat.CurrencyDecimals : Misc.NumberFormat.CurrencyNoDecimals) :
30
- (hasDecimals ? Misc.NumberFormat.Decimals : Misc.NumberFormat.NoDecimals);
31
- formatString = NumberUtils.getFormatString(format, numProps === null || numProps === void 0 ? void 0 : numProps.currencySymbol);
32
- }
33
- }
34
- if (formatString.indexOf("%") < 0 && appendText === "%") {
35
- hasExternalPercentSymbol = true;
36
- }
37
- if (formatString.indexOf("%") >= 0 || appendText === "%") {
38
- isPercent = true;
39
- }
40
- return new FormatState(isPercent, hasExternalPercentSymbol, formatString, numProps === null || numProps === void 0 ? void 0 : numProps.zeroText);
41
- };
42
- FormatState.prototype.getFormattedValue = function (value) {
43
- if (!value && this.zeroText !== undefined) {
44
- return this.zeroText;
45
- }
46
- if (value !== undefined && value !== null) {
47
- if (value instanceof Misc.Globals.decimalType) {
48
- value = value.toNumber();
49
- }
50
- if (typeof value === "number") {
51
- if (this.hasExternalPercentSymbol) {
52
- value *= 100;
53
- }
54
- return NumberUtils.format(value, this.formatString);
55
- }
56
- else {
57
- return value;
58
- }
59
- }
60
- else {
61
- return "";
62
- }
63
- };
64
- return FormatState;
65
- }());
66
- export { FormatState };
67
- // Taken from https://github.com/MikeMcl/decimal.js-light/blob/master/decimal.js since it is not exported.
68
- var validDecimalRegex = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
69
- var NumberInput = /** @class */ (function (_super) {
70
- __extends(NumberInput, _super);
71
- function NumberInput(props) {
72
- var _this = _super.call(this, props) || this;
73
- _this.hasFocus = false;
74
- _this.isReadOnly = false;
75
- _this.recalcFormatState = memoize(FormatState.create);
76
- _this.numericType = _this.props.bind.propertyInfo.propertyType;
77
- _this.inputElement = React.createRef();
78
- _this.onChanged = _this.onChanged.bind(_this);
79
- _this.onFocus = _this.onFocus.bind(_this);
80
- _this.onBlur = _this.onBlur.bind(_this);
81
- _this.onKeyDown = _this.onKeyDown.bind(_this);
82
- return _this;
83
- }
84
- NumberInput.prototype.onChanged = function (e) {
85
- var newValue;
86
- if (e.target.value !== "") {
87
- var testValue = e.target.value;
88
- if (testValue[0] === "-") {
89
- testValue = testValue.substring(1);
90
- }
91
- if (isNaN(parseFloat(testValue)) || !validDecimalRegex.test(testValue)) {
92
- return;
93
- }
94
- }
95
- if (e.target.value == "") {
96
- newValue = this.props.bind.propertyInfo.allowNulls ? null : new Decimal(0);
97
- }
98
- else if (this.formatState.isPercent && NumberUtils.transformPercent) {
99
- newValue = new Decimal(e.target.value).dividedBy(100);
100
- }
101
- else if (this.numericType === Misc.DataType.Float || this.numericType === Misc.DataType.Decimal) {
102
- newValue = new Decimal(e.target.value);
103
- }
104
- else {
105
- // Rounds to zero.
106
- newValue = new Decimal(e.target.value).toDecimalPlaces(0, Decimal.ROUND_DOWN);
107
- }
108
- if (newValue === null) {
109
- this.props.bind.value = newValue;
110
- }
111
- else {
112
- if (!this.props.numProps || this.props.numProps.autoRound !== false) {
113
- newValue = NumberUtils.roundUsingFormat(newValue, this.formatState.formatString, this.formatState.hasExternalPercentSymbol);
114
- }
115
- if (this.numericType === Misc.DataType.Decimal) {
116
- this.props.bind.value = newValue;
117
- }
118
- else {
119
- this.props.bind.value = newValue.toNumber();
120
- }
121
- }
122
- };
123
- NumberInput.prototype.onFocus = function () {
124
- var element = this.inputElement.current;
125
- if (element && !element.disabled) {
126
- this.setFocusedText(element);
127
- element.select();
128
- }
129
- };
130
- NumberInput.prototype.getBindValueAsNumber = function () {
131
- var propertyValue = this.props.bind.value;
132
- if (propertyValue instanceof Misc.Globals.decimalType) {
133
- return propertyValue.toNumber();
134
- }
135
- else {
136
- return propertyValue;
137
- }
138
- };
139
- NumberInput.prototype.setFocusedText = function (element) {
140
- this.hasFocus = true;
141
- var numberValue = this.getBindValueAsNumber();
142
- var stringValue;
143
- if (!numberValue) {
144
- if ((this.props.bind.propertyInfo.allowNulls || element.readOnly) && numberValue === 0) {
145
- stringValue = "0";
146
- }
147
- else {
148
- stringValue = "";
149
- }
150
- }
151
- else {
152
- if (element.readOnly || !this.props.numProps || this.props.numProps.autoRound !== false) {
153
- stringValue = NumberUtils.formatRaw(numberValue, this.formatState.formatString, this.formatState.hasExternalPercentSymbol);
154
- }
155
- else {
156
- if (this.formatState.isPercent && NumberUtils.transformPercent) {
157
- numberValue *= 100;
158
- }
159
- stringValue = numberValue.toString();
160
- }
161
- }
162
- element.value = stringValue;
163
- };
164
- NumberInput.prototype.onBlur = function (e) {
165
- this.hasFocus = false;
166
- if (this.inputElement.current) {
167
- this.inputElement.current.value = this.formatState.getFormattedValue(this.props.bind.value);
168
- }
169
- };
170
- NumberInput.prototype.onKeyDown = function (e) {
171
- var element = this.inputElement.current;
172
- if (!this.isReadOnly && element && (e.keyCode === 38 || e.keyCode === 40)) {
173
- var value = this.getBindValueAsNumber();
174
- if (value !== null) {
175
- var selectionIndex = element.selectionEnd;
176
- var deltaValue = 1;
177
- var decimalIndex = element.value.indexOf(".");
178
- if (decimalIndex < 0) {
179
- decimalIndex = element.value.indexOf(",");
180
- }
181
- if (decimalIndex > 0 && selectionIndex && selectionIndex > decimalIndex) {
182
- deltaValue = 0.01;
183
- }
184
- if (this.formatState.isPercent && NumberUtils.transformPercent) {
185
- deltaValue /= 100;
186
- }
187
- if (e.keyCode === 38) {
188
- // Up
189
- value += deltaValue;
190
- }
191
- else if (e.keyCode === 40) {
192
- // Down
193
- value -= deltaValue;
194
- }
195
- if (this.numericType === Misc.DataType.Decimal) {
196
- this.props.bind.value = new Decimal(value);
197
- }
198
- else {
199
- this.props.bind.value = value;
200
- }
201
- this.setFocusedText(element);
202
- if (selectionIndex !== null) {
203
- element.selectionStart = element.selectionEnd = selectionIndex;
204
- }
205
- e.preventDefault();
206
- }
207
- }
208
- };
209
- NumberInput.prototype.componentDidMount = function () {
210
- if (this.inputElement.current) {
211
- this.inputElement.current.addEventListener("keydown", this.onKeyDown);
212
- }
213
- };
214
- NumberInput.prototype.componentWillUnmount = function () {
215
- if (this.inputElement.current) {
216
- this.inputElement.current.removeEventListener("keydown", this.onKeyDown);
217
- }
218
- };
219
- NumberInput.prototype.render = function () {
220
- var splitProps = BindPropsHelper.normaliseEditorProps(this, this.props);
221
- var domProps = BindPropsHelper.autoSetDomProperties(splitProps, this.context, this.onBlur, this.onFocus);
222
- domProps.className = Utils.joinWithSpaces(domProps.className, splitProps.isBootstrap ? "form-control" : "neo-forms-editor", "numeric-input");
223
- var editorProps = splitProps.editor;
224
- var displayInfo = this.props.bind.validator.getDisplayState(this.context.validationDisplayMode);
225
- displayInfo.applyToDom(domProps, !splitProps.inGroup);
226
- this.formatState = this.recalcFormatState(this.numericType, splitProps.numProps, editorProps.appendText);
227
- this.isReadOnly = domProps.readOnly === true;
228
- if (editorProps.inputElement) {
229
- this.inputElement = editorProps.inputElement;
230
- }
231
- // Don't update the elements value if it is focused
232
- if (!this.hasFocus) {
233
- if (this.inputElement.current) {
234
- this.inputElement.current.value = this.formatState.getFormattedValue(editorProps.bind.value);
235
- }
236
- }
237
- return (InputHelpers.surroundWithInputGroup(React.createElement("input", __assign({}, domProps, { defaultValue: this.formatState.getFormattedValue(editorProps.bind.value), type: "text", onChange: this.onChanged, ref: this.inputElement })), editorProps));
238
- };
239
- NumberInput.contextType = FormContext;
240
- NumberInput = __decorate([
241
- observer,
242
- __metadata("design:paramtypes", [Object])
243
- ], NumberInput);
244
- return NumberInput;
245
- }(ComponentBase));
246
- export default NumberInput;
1
+ import { __assign, __decorate, __extends, __metadata } from "tslib";
2
+ import * as React from 'react';
3
+ import { BindPropsHelper } from './PropTypes';
4
+ import { FormContext } from './FormContext';
5
+ import { Misc, NumberUtils, Utils } from '@singularsystems/neo-core';
6
+ import Decimal from 'decimal.js-light';
7
+ import { InputHelpers } from './InputHelpers';
8
+ import { observer } from 'mobx-react';
9
+ import memoize from 'memoize-one';
10
+ import ComponentBase from './ComponentBase';
11
+ var FormatState = /** @class */ (function () {
12
+ function FormatState(isPercent, hasExternalPercentSymbol, formatString,
13
+ /** How many decimals the value is allowed. */
14
+ allowedDecimals, zeroText, useNative) {
15
+ this.isPercent = isPercent;
16
+ this.hasExternalPercentSymbol = hasExternalPercentSymbol;
17
+ this.formatString = formatString;
18
+ this.allowedDecimals = allowedDecimals;
19
+ this.zeroText = zeroText;
20
+ this.useNative = useNative;
21
+ }
22
+ FormatState.create = function (propertyInfo, numericType, numProps, appendText) {
23
+ var isPercent = false;
24
+ var hasExternalPercentSymbol = false;
25
+ var formatString = numProps ? numProps.formatString : "";
26
+ var displayDecimals = 2;
27
+ if ((formatString && formatString.indexOf("%") >= 0)
28
+ || appendText === "%"
29
+ || (numProps === null || numProps === void 0 ? void 0 : numProps.format) === Misc.NumberFormat.PercentDecimals || (numProps === null || numProps === void 0 ? void 0 : numProps.format) === Misc.NumberFormat.PercentNoDecimals) {
30
+ isPercent = true;
31
+ }
32
+ if (propertyInfo.allowedDecimals !== undefined) {
33
+ displayDecimals = propertyInfo.allowedDecimals - (isPercent ? 2 : 0);
34
+ }
35
+ else if (numProps === null || numProps === void 0 ? void 0 : numProps.formatString) {
36
+ displayDecimals = NumberUtils.getDecimalPlaces(numProps.formatString);
37
+ }
38
+ if (!formatString) {
39
+ if (numProps && numProps.format) {
40
+ formatString = NumberUtils.getFormatString(numProps.format, numProps.currencySymbol, displayDecimals);
41
+ }
42
+ else {
43
+ var hasDecimals = numericType === Misc.DataType.Float || numericType === Misc.DataType.Decimal;
44
+ var format = (numProps === null || numProps === void 0 ? void 0 : numProps.currencySymbol) ?
45
+ (hasDecimals ? Misc.NumberFormat.CurrencyDecimals : Misc.NumberFormat.CurrencyNoDecimals) :
46
+ (hasDecimals ? Misc.NumberFormat.Decimals : Misc.NumberFormat.NoDecimals);
47
+ formatString = NumberUtils.getFormatString(format, numProps === null || numProps === void 0 ? void 0 : numProps.currencySymbol, displayDecimals);
48
+ }
49
+ }
50
+ if (formatString.indexOf("%") < 0 && appendText === "%") {
51
+ hasExternalPercentSymbol = true;
52
+ }
53
+ return new FormatState(isPercent, hasExternalPercentSymbol, formatString, displayDecimals + (isPercent ? 2 : 0), numProps === null || numProps === void 0 ? void 0 : numProps.zeroText, numProps === null || numProps === void 0 ? void 0 : numProps.native);
54
+ };
55
+ FormatState.prototype.getFormattedValue = function (value) {
56
+ if (!value && this.zeroText !== undefined) {
57
+ return this.zeroText;
58
+ }
59
+ if (value !== undefined && value !== null) {
60
+ if (value instanceof Misc.Globals.decimalType) {
61
+ value = value.toNumber();
62
+ }
63
+ if (typeof value === "number") {
64
+ if (this.hasExternalPercentSymbol) {
65
+ value *= 100;
66
+ }
67
+ return this.useNative ? NumberUtils.formatRaw(value, this.formatString, false) : NumberUtils.format(value, this.formatString);
68
+ }
69
+ else {
70
+ return value;
71
+ }
72
+ }
73
+ else {
74
+ return "";
75
+ }
76
+ };
77
+ return FormatState;
78
+ }());
79
+ export { FormatState };
80
+ // Taken from https://github.com/MikeMcl/decimal.js-light/blob/master/decimal.js since it is not exported.
81
+ var validDecimalRegex = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
82
+ var NumberInput = /** @class */ (function (_super) {
83
+ __extends(NumberInput, _super);
84
+ function NumberInput(props) {
85
+ var _this = _super.call(this, props) || this;
86
+ _this.hasFocus = false;
87
+ _this.isReadOnly = false;
88
+ _this.recalcFormatState = memoize(FormatState.create);
89
+ _this.numericType = _this.props.bind.propertyInfo.propertyType;
90
+ _this.inputElement = React.createRef();
91
+ _this.onChanged = _this.onChanged.bind(_this);
92
+ _this.onFocus = _this.onFocus.bind(_this);
93
+ _this.onBlur = _this.onBlur.bind(_this);
94
+ _this.onKeyDown = _this.onKeyDown.bind(_this);
95
+ return _this;
96
+ }
97
+ NumberInput.prototype.onChanged = function (e) {
98
+ var newValue;
99
+ if (e.target.value !== "") {
100
+ var testValue = e.target.value;
101
+ if (testValue[0] === "-") {
102
+ testValue = testValue.substring(1);
103
+ }
104
+ if (isNaN(parseFloat(testValue)) || !validDecimalRegex.test(testValue)) {
105
+ return;
106
+ }
107
+ }
108
+ if (e.target.value == "") {
109
+ newValue = this.props.bind.propertyInfo.allowNulls ? null : new Decimal(0);
110
+ }
111
+ else if (this.formatState.isPercent && NumberUtils.transformPercent) {
112
+ newValue = new Decimal(e.target.value).dividedBy(100);
113
+ }
114
+ else if (this.numericType === Misc.DataType.Float || this.numericType === Misc.DataType.Decimal) {
115
+ newValue = new Decimal(e.target.value);
116
+ }
117
+ else {
118
+ // Rounds to zero.
119
+ newValue = new Decimal(e.target.value).toDecimalPlaces(0, Decimal.ROUND_DOWN);
120
+ }
121
+ if (newValue === null) {
122
+ this.props.bind.value = newValue;
123
+ }
124
+ else {
125
+ if (!this.props.numProps || this.props.numProps.autoRound !== false) {
126
+ newValue = NumberUtils.round(newValue, this.formatState.allowedDecimals);
127
+ }
128
+ if (this.numericType === Misc.DataType.Decimal) {
129
+ this.props.bind.value = newValue;
130
+ }
131
+ else {
132
+ this.props.bind.value = newValue.toNumber();
133
+ }
134
+ }
135
+ };
136
+ NumberInput.prototype.onFocus = function () {
137
+ var element = this.inputElement.current;
138
+ if (element && !element.disabled) {
139
+ this.setFocusedText(element);
140
+ element.select();
141
+ }
142
+ };
143
+ NumberInput.prototype.getBindValueAsNumber = function () {
144
+ var propertyValue = this.props.bind.value;
145
+ if (propertyValue instanceof Misc.Globals.decimalType) {
146
+ return propertyValue.toNumber();
147
+ }
148
+ else {
149
+ return propertyValue;
150
+ }
151
+ };
152
+ NumberInput.prototype.setFocusedText = function (element) {
153
+ this.hasFocus = true;
154
+ var numberValue = this.getBindValueAsNumber();
155
+ var stringValue;
156
+ if (numberValue === null || numberValue === undefined) {
157
+ stringValue = "";
158
+ }
159
+ else {
160
+ if (element.readOnly || !this.props.numProps || this.props.numProps.autoRound !== false) {
161
+ stringValue = NumberUtils.formatRaw(numberValue, this.formatState.formatString, this.formatState.hasExternalPercentSymbol, this.formatState.allowedDecimals);
162
+ }
163
+ else {
164
+ if (this.formatState.isPercent && NumberUtils.transformPercent) {
165
+ numberValue *= 100;
166
+ }
167
+ stringValue = numberValue.toString();
168
+ }
169
+ }
170
+ element.value = stringValue;
171
+ };
172
+ NumberInput.prototype.onBlur = function (e) {
173
+ this.hasFocus = false;
174
+ if (this.inputElement.current) {
175
+ this.inputElement.current.value = this.formatState.getFormattedValue(this.props.bind.value);
176
+ }
177
+ };
178
+ NumberInput.prototype.onKeyDown = function (e) {
179
+ var element = this.inputElement.current;
180
+ if (!this.isReadOnly && element && (e.keyCode === 38 || e.keyCode === 40)) {
181
+ var value = this.getBindValueAsNumber();
182
+ if (value !== null) {
183
+ var selectionIndex = element.selectionEnd;
184
+ var deltaValue = 1;
185
+ var decimalIndex = element.value.indexOf(".");
186
+ if (decimalIndex < 0) {
187
+ decimalIndex = element.value.indexOf(",");
188
+ }
189
+ if (decimalIndex > 0 && selectionIndex && selectionIndex > decimalIndex) {
190
+ deltaValue = 0.01;
191
+ }
192
+ if (this.formatState.isPercent && NumberUtils.transformPercent) {
193
+ deltaValue /= 100;
194
+ }
195
+ if (e.keyCode === 38) {
196
+ // Up
197
+ value += deltaValue;
198
+ }
199
+ else if (e.keyCode === 40) {
200
+ // Down
201
+ value -= deltaValue;
202
+ }
203
+ if (this.numericType === Misc.DataType.Decimal) {
204
+ this.props.bind.value = new Decimal(value);
205
+ }
206
+ else {
207
+ this.props.bind.value = value;
208
+ }
209
+ this.setFocusedText(element);
210
+ if (selectionIndex !== null) {
211
+ element.selectionStart = element.selectionEnd = selectionIndex;
212
+ }
213
+ e.preventDefault();
214
+ }
215
+ }
216
+ };
217
+ NumberInput.prototype.componentDidMount = function () {
218
+ if (this.inputElement.current) {
219
+ this.inputElement.current.addEventListener("keydown", this.onKeyDown);
220
+ }
221
+ };
222
+ NumberInput.prototype.componentWillUnmount = function () {
223
+ if (this.inputElement.current) {
224
+ this.inputElement.current.removeEventListener("keydown", this.onKeyDown);
225
+ }
226
+ };
227
+ NumberInput.prototype.render = function () {
228
+ var _a;
229
+ var splitProps = BindPropsHelper.normaliseEditorProps(this, this.props);
230
+ var domProps = BindPropsHelper.autoSetDomProperties(splitProps, this.context, this.onBlur, this.onFocus);
231
+ domProps.className = Utils.joinWithSpaces(domProps.className, splitProps.isBootstrap ? "form-control" : "neo-forms-editor", "numeric-input");
232
+ var editorProps = splitProps.editor;
233
+ var useNative = (_a = splitProps.numProps) === null || _a === void 0 ? void 0 : _a.native;
234
+ var displayInfo = this.props.bind.validator.getDisplayState(this.context.validationDisplayMode);
235
+ displayInfo.applyToDom(domProps, !splitProps.inGroup);
236
+ this.formatState = this.recalcFormatState(this.props.bind.propertyInfo, this.numericType, splitProps.numProps, editorProps.appendText);
237
+ this.isReadOnly = domProps.readOnly === true;
238
+ if (editorProps.inputElement) {
239
+ this.inputElement = editorProps.inputElement;
240
+ }
241
+ // Don't update the elements value if it is focused
242
+ if (!this.hasFocus) {
243
+ if (this.inputElement.current) {
244
+ this.inputElement.current.value = this.formatState.getFormattedValue(editorProps.bind.value);
245
+ }
246
+ }
247
+ if (useNative && !domProps.step) {
248
+ var decimals = NumberUtils.getDecimalPlaces(this.formatState.formatString);
249
+ domProps.step = decimals === 0 ? "1" : "0.".concat("0".repeat(decimals - 1), "1");
250
+ }
251
+ return (InputHelpers.surroundWithInputGroup(React.createElement("input", __assign({}, domProps, { defaultValue: this.formatState.getFormattedValue(editorProps.bind.value), type: useNative ? "number" : "text", onChange: this.onChanged, ref: this.inputElement })), editorProps));
252
+ };
253
+ NumberInput.contextType = FormContext;
254
+ NumberInput = __decorate([
255
+ observer,
256
+ __metadata("design:paramtypes", [Object])
257
+ ], NumberInput);
258
+ return NumberInput;
259
+ }(ComponentBase));
260
+ export default NumberInput;
@@ -1,25 +1,26 @@
1
- import React from 'react';
2
- import { Data } from "@singularsystems/neo-core";
3
- export interface IPagerControlsProps extends React.HTMLProps<HTMLUListElement> {
4
- /** Page manager to control. */
5
- pageManager: Data.IPageManager;
6
- /** No of buttons to show */
7
- noOfButtons?: number;
8
- /** Alignment of buttons. End (right) by default. */
9
- alignment?: "start" | "center" | "end" | "";
10
- /** Text of the first button. */
11
- firstText?: string;
12
- /** Text of the prev button. */
13
- prevText?: string;
14
- /** Text of the next button. */
15
- nextText?: string;
16
- /** Text of the last button. */
17
- lastText?: string;
18
- /** Hides the pager if there is only one page. True by default. */
19
- autoHide?: boolean;
20
- /** Causes the page size control to show, with this label. */
21
- pageSizeLabel?: string | JSX.Element;
22
- }
23
- export default class SimplePagerControls extends React.Component<IPagerControlsProps> {
24
- render(): false | JSX.Element;
25
- }
1
+ import React from 'react';
2
+ import { Data } from "@singularsystems/neo-core";
3
+ export interface IPagerControlsProps extends React.HTMLProps<HTMLUListElement> {
4
+ /** Page manager to control. */
5
+ pageManager: Data.IPageManager;
6
+ /** No of buttons to show */
7
+ noOfButtons?: number;
8
+ /** Alignment of buttons. End (right) by default. */
9
+ alignment?: "start" | "center" | "end" | "";
10
+ /** Text of the first button. */
11
+ firstText?: string;
12
+ /** Text of the prev button. */
13
+ prevText?: string;
14
+ /** Text of the next button. */
15
+ nextText?: string;
16
+ /** Text of the last button. */
17
+ lastText?: string;
18
+ /** Hides the pager if there is only one page. True by default. */
19
+ autoHide?: boolean;
20
+ /** Causes the page size control to show, with this label. */
21
+ pageSizeLabel?: string | JSX.Element;
22
+ }
23
+ export default class SimplePagerControls extends React.Component<IPagerControlsProps> {
24
+ private iconFactory;
25
+ render(): false | JSX.Element;
26
+ }