@singularsystems/neo-core 1.0.0-alpha.2 → 1.0.0-alpha.4

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 (296) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/ApiClient/ApiClientBase.d.ts +5 -5
  3. package/dist/ApiClient/ApiClientBase.js +13 -13
  4. package/dist/ApiClient/ReadApiClient.d.ts +16 -16
  5. package/dist/ApiClient/ReadApiClient.js +24 -24
  6. package/dist/ApiClient/UpdateableApiClient.d.ts +28 -28
  7. package/dist/ApiClient/UpdateableApiClient.js +33 -33
  8. package/dist/AppServices/AppService.d.ts +46 -46
  9. package/dist/AppServices/AppService.js +25 -25
  10. package/dist/AppServices/Config/ConfigModel.d.ts +21 -20
  11. package/dist/AppServices/Config/ConfigModel.js +28 -17
  12. package/dist/AppServices/Config/ConfigService.d.ts +15 -15
  13. package/dist/AppServices/Config/ConfigService.js +49 -53
  14. package/dist/AppServices/Module.d.ts +11 -11
  15. package/dist/AppServices/Module.js +13 -13
  16. package/dist/AppServices/NeoContainer.d.ts +22 -22
  17. package/dist/AppServices/NeoContainer.js +42 -42
  18. package/dist/AppServices/NeoModule.d.ts +3 -3
  19. package/dist/AppServices/NeoModule.js +30 -30
  20. package/dist/AppServices/NeoTypes.d.ts +61 -61
  21. package/dist/AppServices/NeoTypes.js +42 -42
  22. package/dist/AppServices/ServiceIdentifier.d.ts +23 -23
  23. package/dist/AppServices/ServiceIdentifier.js +38 -39
  24. package/dist/AppServices/index.d.ts +7 -7
  25. package/dist/AppServices/index.js +7 -7
  26. package/dist/Components/AnimationHelper.d.ts +69 -69
  27. package/dist/Components/AnimationHelper.js +182 -182
  28. package/dist/Components/BootstrapHelpers.d.ts +8 -8
  29. package/dist/Components/BootstrapHelpers.js +30 -30
  30. package/dist/Components/BootstrapTypes.d.ts +35 -35
  31. package/dist/Components/BootstrapTypes.js +1 -1
  32. package/dist/Components/ButtonOptions.d.ts +63 -61
  33. package/dist/Components/ButtonOptions.js +1 -1
  34. package/dist/Components/ContextMenu/ContextMenu.d.ts +16 -16
  35. package/dist/Components/ContextMenu/ContextMenu.js +1 -1
  36. package/dist/Components/ContextMenu/MenuUtils.d.ts +16 -16
  37. package/dist/Components/ContextMenu/MenuUtils.js +34 -34
  38. package/dist/Components/DatePicker/DatePicker.d.ts +70 -69
  39. package/dist/Components/DatePicker/DatePicker.js +502 -487
  40. package/dist/Components/DatePicker/DatePickerOptions.d.ts +43 -34
  41. package/dist/Components/DatePicker/DatePickerOptions.js +33 -33
  42. package/dist/Components/ErrorHandler.d.ts +59 -55
  43. package/dist/Components/ErrorHandler.js +210 -138
  44. package/dist/Components/FileManager/BoundFileManager.d.ts +18 -18
  45. package/dist/Components/FileManager/BoundFileManager.js +60 -60
  46. package/dist/Components/FileManager/FileManager.d.ts +80 -78
  47. package/dist/Components/FileManager/FileManager.js +277 -257
  48. package/dist/Components/FileManager/FileUploadBatch.d.ts +37 -37
  49. package/dist/Components/FileManager/FileUploadBatch.js +83 -82
  50. package/dist/Components/FileManager/IFileManagerOptions.d.ts +42 -42
  51. package/dist/Components/FileManager/IFileManagerOptions.js +1 -1
  52. package/dist/Components/FormOptions.d.ts +34 -34
  53. package/dist/Components/FormOptions.js +1 -1
  54. package/dist/Components/ICollapsableOptions.d.ts +11 -11
  55. package/dist/Components/ICollapsableOptions.js +1 -1
  56. package/dist/Components/Modal/ModalHelper.d.ts +31 -31
  57. package/dist/Components/Modal/ModalHelper.js +174 -174
  58. package/dist/Components/Modal/ModalOptions.d.ts +61 -61
  59. package/dist/Components/Modal/ModalOptions.js +1 -1
  60. package/dist/Components/Modal/ModalStore.d.ts +32 -32
  61. package/dist/Components/Modal/ModalStore.js +82 -82
  62. package/dist/Components/Modal/ModalUtils.d.ts +61 -61
  63. package/dist/Components/Modal/ModalUtils.js +109 -109
  64. package/dist/Components/Notifications/INotificationHelper.d.ts +56 -56
  65. package/dist/Components/Notifications/INotificationHelper.js +1 -1
  66. package/dist/Components/Notifications/Notification.d.ts +32 -32
  67. package/dist/Components/Notifications/Notification.js +26 -27
  68. package/dist/Components/Notifications/NotificationHelper.d.ts +63 -63
  69. package/dist/Components/Notifications/NotificationHelper.js +111 -112
  70. package/dist/Components/Notifications/NotificationStore.d.ts +34 -34
  71. package/dist/Components/Notifications/NotificationStore.js +78 -79
  72. package/dist/Components/PositionHelper.d.ts +10 -10
  73. package/dist/Components/PositionHelper.js +43 -43
  74. package/dist/Components/TaskRunner/Decorators.d.ts +6 -6
  75. package/dist/Components/TaskRunner/Decorators.js +24 -24
  76. package/dist/Components/TaskRunner/ProgressState.d.ts +22 -22
  77. package/dist/Components/TaskRunner/ProgressState.js +71 -72
  78. package/dist/Components/TaskRunner/TaskRunner.d.ts +114 -114
  79. package/dist/Components/TaskRunner/TaskRunner.js +253 -244
  80. package/dist/Components/TooltipOptions.d.ts +8 -8
  81. package/dist/Components/TooltipOptions.js +1 -1
  82. package/dist/Components/index.d.ts +22 -22
  83. package/dist/Components/index.js +13 -13
  84. package/dist/ConnectionManager.d.ts +45 -45
  85. package/dist/ConnectionManager.js +60 -61
  86. package/dist/Data/ApiDataSource.d.ts +46 -46
  87. package/dist/Data/ApiDataSource.js +140 -144
  88. package/dist/Data/AsyncDataSource.d.ts +35 -35
  89. package/dist/Data/AsyncDataSource.js +79 -80
  90. package/dist/Data/CacheService.d.ts +40 -40
  91. package/dist/Data/CacheService.js +63 -64
  92. package/dist/Data/DataCacheEntry.d.ts +42 -42
  93. package/dist/Data/DataCacheEntry.js +80 -80
  94. package/dist/Data/DataView.d.ts +43 -43
  95. package/dist/Data/DataView.js +173 -172
  96. package/dist/Data/Deserialiser.d.ts +42 -42
  97. package/dist/Data/Deserialiser.js +255 -255
  98. package/dist/Data/Paging/PageManager.d.ts +167 -167
  99. package/dist/Data/Paging/PageManager.js +323 -323
  100. package/dist/Data/Paging/PageRequest.d.ts +24 -24
  101. package/dist/Data/Paging/PageRequest.js +38 -39
  102. package/dist/Data/Paging/PageResult.d.ts +10 -10
  103. package/dist/Data/Paging/PageResult.js +14 -14
  104. package/dist/Data/Serialiser.d.ts +41 -41
  105. package/dist/Data/Serialiser.js +201 -201
  106. package/dist/Data/SortOperation.d.ts +8 -8
  107. package/dist/Data/SortOperation.js +26 -26
  108. package/dist/Data/StaticDataSource.d.ts +9 -9
  109. package/dist/Data/StaticDataSource.js +27 -27
  110. package/dist/Data/WindowedDataView.d.ts +8 -8
  111. package/dist/Data/WindowedDataView.js +49 -50
  112. package/dist/Data/index.d.ts +15 -15
  113. package/dist/Data/index.js +15 -15
  114. package/dist/Dates/DateUtils.d.ts +47 -47
  115. package/dist/Dates/DateUtils.js +226 -226
  116. package/dist/Dates/TimeSpan.d.ts +24 -24
  117. package/dist/Dates/TimeSpan.js +46 -46
  118. package/dist/DebounceHelper.d.ts +44 -38
  119. package/dist/DebounceHelper.js +122 -95
  120. package/dist/Extensions.d.ts +82 -82
  121. package/dist/Extensions.js +182 -182
  122. package/dist/FileUtils.d.ts +6 -6
  123. package/dist/FileUtils.js +37 -37
  124. package/dist/Globals.d.ts +19 -19
  125. package/dist/Globals.js +41 -41
  126. package/dist/JsonSchema/ClassMetadata.d.ts +25 -25
  127. package/dist/JsonSchema/ClassMetadata.js +53 -53
  128. package/dist/JsonSchema/JsonData.d.ts +16 -16
  129. package/dist/JsonSchema/JsonData.js +97 -97
  130. package/dist/JsonSchema/JsonSchemaTypes.d.ts +37 -37
  131. package/dist/JsonSchema/JsonSchemaTypes.js +1 -1
  132. package/dist/JsonSchema/PropertyMetadata.d.ts +8 -8
  133. package/dist/JsonSchema/PropertyMetadata.js +8 -8
  134. package/dist/JsonSchema/TypeCache.d.ts +16 -16
  135. package/dist/JsonSchema/TypeCache.js +44 -44
  136. package/dist/JsonSchema/TypeMetadata.d.ts +45 -45
  137. package/dist/JsonSchema/TypeMetadata.js +170 -170
  138. package/dist/JsonSchema/index.d.ts +7 -7
  139. package/dist/JsonSchema/index.js +6 -6
  140. package/dist/Localisation/ILocalisationService.d.ts +11 -11
  141. package/dist/Localisation/ILocalisationService.js +1 -1
  142. package/dist/Localisation/LocalisationService.d.ts +4 -4
  143. package/dist/Localisation/LocalisationService.js +17 -17
  144. package/dist/Localisation/index.d.ts +1 -1
  145. package/dist/Localisation/index.js +1 -1
  146. package/dist/Misc.d.ts +6 -6
  147. package/dist/Misc.js +6 -6
  148. package/dist/Model/BaseModels/AuditValues.d.ts +12 -12
  149. package/dist/Model/BaseModels/AuditValues.js +46 -48
  150. package/dist/Model/BaseModels/CriteriaBase.d.ts +18 -16
  151. package/dist/Model/BaseModels/CriteriaBase.js +45 -34
  152. package/dist/Model/BaseModels/FileDescriptorBase.d.ts +12 -12
  153. package/dist/Model/BaseModels/FileDescriptorBase.js +22 -22
  154. package/dist/Model/BaseModels/ReasonedUserEvent.d.ts +5 -4
  155. package/dist/Model/BaseModels/ReasonedUserEvent.js +23 -19
  156. package/dist/Model/BaseModels/UserEvent.d.ts +9 -8
  157. package/dist/Model/BaseModels/UserEvent.js +36 -32
  158. package/dist/Model/BindableBase.d.ts +46 -40
  159. package/dist/Model/BindableBase.js +79 -76
  160. package/dist/Model/Decorators.d.ts +47 -44
  161. package/dist/Model/Decorators.js +182 -177
  162. package/dist/Model/EnumHelper.d.ts +54 -54
  163. package/dist/Model/EnumHelper.js +104 -100
  164. package/dist/Model/IAutoRunner.d.ts +5 -5
  165. package/dist/Model/IAutoRunner.js +1 -1
  166. package/dist/Model/IModelBase.d.ts +92 -79
  167. package/dist/Model/IModelBase.js +1 -1
  168. package/dist/Model/IModelCreatorBase.d.ts +9 -9
  169. package/dist/Model/IModelCreatorBase.js +1 -1
  170. package/dist/Model/List.d.ts +79 -77
  171. package/dist/Model/List.js +208 -198
  172. package/dist/Model/LookupBase.d.ts +13 -6
  173. package/dist/Model/LookupBase.js +19 -10
  174. package/dist/Model/Misc.d.ts +83 -81
  175. package/dist/Model/Misc.js +59 -59
  176. package/dist/Model/ModelBase.d.ts +88 -86
  177. package/dist/Model/ModelBase.js +182 -180
  178. package/dist/Model/ModelCreatorBase.d.ts +24 -23
  179. package/dist/Model/ModelCreatorBase.js +92 -92
  180. package/dist/Model/ModelFieldInfo.d.ts +29 -12
  181. package/dist/Model/ModelFieldInfo.js +35 -26
  182. package/dist/Model/ModelGraphTraverser.d.ts +35 -35
  183. package/dist/Model/ModelGraphTraverser.js +101 -99
  184. package/dist/Model/NeoModel.d.ts +6 -6
  185. package/dist/Model/NeoModel.js +13 -13
  186. package/dist/Model/NeoTypeInfo.d.ts +52 -41
  187. package/dist/Model/NeoTypeInfo.js +300 -250
  188. package/dist/Model/ObservableProperty.d.ts +8 -8
  189. package/dist/Model/ObservableProperty.js +41 -41
  190. package/dist/Model/ObservableValue.d.ts +9 -9
  191. package/dist/Model/ObservableValue.js +25 -26
  192. package/dist/Model/PropertyInfo.d.ts +83 -81
  193. package/dist/Model/PropertyInfo.js +138 -137
  194. package/dist/Model/PropertyInstance.d.ts +84 -48
  195. package/dist/Model/PropertyInstance.js +173 -113
  196. package/dist/Model/ValueObject.d.ts +3 -3
  197. package/dist/Model/ValueObject.js +10 -10
  198. package/dist/Model/index.d.ts +15 -14
  199. package/dist/Model/index.js +13 -12
  200. package/dist/NumberUtils.d.ts +63 -49
  201. package/dist/NumberUtils.js +247 -197
  202. package/dist/Routing/IMenuItemProvider.d.ts +9 -9
  203. package/dist/Routing/IMenuItemProvider.js +1 -1
  204. package/dist/Routing/IMenuRoute.d.ts +18 -18
  205. package/dist/Routing/IMenuRoute.js +1 -1
  206. package/dist/Routing/INavigationHelper.d.ts +7 -7
  207. package/dist/Routing/INavigationHelper.js +1 -1
  208. package/dist/Routing/IPageLeaveHandler.d.ts +23 -23
  209. package/dist/Routing/IPageLeaveHandler.js +7 -7
  210. package/dist/Routing/IRoute.d.ts +27 -27
  211. package/dist/Routing/IRoute.js +1 -1
  212. package/dist/Routing/IRouteSecurityService.d.ts +14 -14
  213. package/dist/Routing/IRouteSecurityService.js +1 -1
  214. package/dist/Routing/MenuItemProvider.d.ts +17 -17
  215. package/dist/Routing/MenuItemProvider.js +53 -54
  216. package/dist/Routing/RouteSecurityService.d.ts +18 -18
  217. package/dist/Routing/RouteSecurityService.js +35 -36
  218. package/dist/Routing/index.d.ts +7 -7
  219. package/dist/Routing/index.js +3 -3
  220. package/dist/Security/IAuthenticationService.d.ts +41 -36
  221. package/dist/Security/IAuthenticationService.js +1 -1
  222. package/dist/Security/IAuthorisationService.d.ts +11 -11
  223. package/dist/Security/IAuthorisationService.js +1 -1
  224. package/dist/Security/ILoginErrorHandler.d.ts +4 -4
  225. package/dist/Security/ILoginErrorHandler.js +1 -1
  226. package/dist/Security/ISecurityService.d.ts +10 -10
  227. package/dist/Security/ISecurityService.js +1 -1
  228. package/dist/Security/IUser.d.ts +10 -10
  229. package/dist/Security/IUser.js +1 -1
  230. package/dist/Security/IUserRole.d.ts +6 -6
  231. package/dist/Security/IUserRole.js +1 -1
  232. package/dist/Security/LoginErrorHandler.d.ts +15 -15
  233. package/dist/Security/LoginErrorHandler.js +97 -98
  234. package/dist/Security/Oidc/OidcAuthService.d.ts +67 -60
  235. package/dist/Security/Oidc/OidcAuthService.js +216 -189
  236. package/dist/Security/Oidc/OidcTypes.d.ts +46 -29
  237. package/dist/Security/Oidc/OidcTypes.js +1 -1
  238. package/dist/Security/Oidc/OidcUser.d.ts +9 -9
  239. package/dist/Security/Oidc/OidcUser.js +33 -33
  240. package/dist/Security/SecurityService.d.ts +12 -12
  241. package/dist/Security/SecurityService.js +33 -34
  242. package/dist/Security/SignInResult.d.ts +13 -13
  243. package/dist/Security/SignInResult.js +8 -8
  244. package/dist/Security/User.d.ts +12 -12
  245. package/dist/Security/User.js +24 -24
  246. package/dist/Security/index.d.ts +10 -10
  247. package/dist/Security/index.js +5 -5
  248. package/dist/Settings.d.ts +71 -57
  249. package/dist/Settings.js +100 -87
  250. package/dist/SignalR/HubBase.d.ts +70 -70
  251. package/dist/SignalR/HubBase.js +164 -164
  252. package/dist/SignalR/HubReceiver.d.ts +11 -11
  253. package/dist/SignalR/HubReceiver.js +25 -25
  254. package/dist/SignalR/HubSubscription.d.ts +12 -12
  255. package/dist/SignalR/HubSubscription.js +14 -14
  256. package/dist/SignalR/index.d.ts +3 -3
  257. package/dist/SignalR/index.js +1 -1
  258. package/dist/StringUtils.d.ts +7 -7
  259. package/dist/StringUtils.js +24 -24
  260. package/dist/Utils.d.ts +81 -80
  261. package/dist/Utils.js +220 -218
  262. package/dist/Validation/Decorators.d.ts +12 -12
  263. package/dist/Validation/Decorators.js +52 -52
  264. package/dist/Validation/DisplayHelper.d.ts +20 -19
  265. package/dist/Validation/DisplayHelper.js +104 -104
  266. package/dist/Validation/Misc.d.ts +10 -10
  267. package/dist/Validation/Misc.js +11 -11
  268. package/dist/Validation/ModelProxy.d.ts +20 -20
  269. package/dist/Validation/ModelProxy.js +46 -46
  270. package/dist/Validation/RuleContext.d.ts +86 -86
  271. package/dist/Validation/RuleContext.js +130 -130
  272. package/dist/Validation/Rules.d.ts +70 -70
  273. package/dist/Validation/Rules.js +177 -177
  274. package/dist/Validation/ValidationHelpers.d.ts +12 -12
  275. package/dist/Validation/ValidationHelpers.js +57 -57
  276. package/dist/Validation/ValidationRules.d.ts +18 -18
  277. package/dist/Validation/ValidationRules.js +34 -34
  278. package/dist/Validation/ValidationState.d.ts +42 -42
  279. package/dist/Validation/ValidationState.js +74 -74
  280. package/dist/Validation/Validators/IModelValidator.d.ts +28 -24
  281. package/dist/Validation/Validators/IModelValidator.js +1 -1
  282. package/dist/Validation/Validators/IPropertyValidator.d.ts +21 -21
  283. package/dist/Validation/Validators/IPropertyValidator.js +15 -15
  284. package/dist/Validation/Validators/ModelValidator.d.ts +46 -45
  285. package/dist/Validation/Validators/ModelValidator.js +143 -137
  286. package/dist/Validation/Validators/PropertyValidator.d.ts +21 -21
  287. package/dist/Validation/Validators/PropertyValidator.js +64 -67
  288. package/dist/Validation/Validators/RuleValidator.d.ts +19 -19
  289. package/dist/Validation/Validators/RuleValidator.js +51 -55
  290. package/dist/Validation/index.d.ts +9 -9
  291. package/dist/Validation/index.js +7 -7
  292. package/dist/Views/IViewBase.d.ts +5 -5
  293. package/dist/Views/IViewBase.js +1 -1
  294. package/dist/index.d.ts +37 -36
  295. package/dist/index.js +44 -43
  296. package/package.json +11 -10
@@ -1,487 +1,502 @@
1
- import DateUtils from '../../Dates/DateUtils';
2
- import AnimationHelper from '../AnimationHelper';
3
- import { YearsInYearView, ProcessedDatePickerOptions } from './DatePickerOptions';
4
- import PositionHelper from '../PositionHelper';
5
- import { Utils } from '../../Utils';
6
- // TODO: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
7
- // TODO: Allow input to be shown with inline picker, and specify position.
8
- var ViewType;
9
- (function (ViewType) {
10
- ViewType[ViewType["Days"] = 1] = "Days";
11
- ViewType[ViewType["Months"] = 2] = "Months";
12
- ViewType[ViewType["Years"] = 3] = "Years";
13
- })(ViewType || (ViewType = {}));
14
- var DatePicker = /** @class */ (function () {
15
- function DatePicker(container, options) {
16
- this.container = container;
17
- this.isReadOnly = false;
18
- this.inputHasChanged = false;
19
- this.canAutoSetDate = false;
20
- this.suspendLayout = false;
21
- this.currentBindValue = null;
22
- this.boundDateNoTime = null;
23
- this.options = ProcessedDatePickerOptions.fromPartial(options || {});
24
- this.inputFocused = this.inputFocused.bind(this);
25
- this.inputBlurred = this.inputBlurred.bind(this);
26
- this.inputChanged = this.inputChanged.bind(this);
27
- this.inputKeyDown = this.inputKeyDown.bind(this);
28
- if (!this.options.alwaysShow) {
29
- this.input = this.container.getElementsByTagName('input')[0];
30
- this.input.addEventListener("focus", this.inputFocused);
31
- this.input.addEventListener("mousedown", this.inputFocused);
32
- this.input.addEventListener("blur", this.inputBlurred);
33
- this.input.addEventListener("input", this.inputChanged);
34
- this.input.addEventListener("keydown", this.inputKeyDown);
35
- if (this.options.timeOnly) {
36
- this.input.placeholder = "hh:mm" + (this.options.formatString.indexOf("s") > 0 ? ":ss" : "");
37
- }
38
- }
39
- }
40
- DatePicker.prototype.inputFocused = function (e) {
41
- if (!this.popup && !this.isReadOnly) {
42
- this.show();
43
- }
44
- if (window.innerWidth <= 576 && !this.options.timeOnly) {
45
- // Stop keyboard showing on phones.
46
- this.input.readOnly = true;
47
- }
48
- };
49
- DatePicker.prototype.inputBlurred = function () {
50
- if (this.inputHasChanged) {
51
- if (this.input.value) {
52
- // if this is time only, use the existing value to preserve the date.
53
- var refDate = this.options.timeOnly && this.bindProperty.value;
54
- var parsedDate = DateUtils.tryParse(this.input.value, this.options.formatString, false, refDate || new Date());
55
- if (parsedDate) {
56
- this.setBindValueAndClose(parsedDate, false);
57
- }
58
- else {
59
- this.setBindValueAndClose(this.bindProperty.value, false);
60
- }
61
- }
62
- else {
63
- this.setBindValueAndClose(null, true);
64
- }
65
- }
66
- else {
67
- if (this.options.autoClose)
68
- this.removePopup(true);
69
- }
70
- this.input.readOnly = this.isReadOnly;
71
- };
72
- DatePicker.prototype.inputChanged = function () {
73
- this.inputHasChanged = true;
74
- if (!this.options.timeOnly) {
75
- // Update the displayed date as the user types.
76
- var parsedDate = DateUtils.tryParse(this.input.value, this.options.formatString, false, this.bindProperty.value);
77
- if (parsedDate) {
78
- this.setCurrentViewDate(parsedDate);
79
- this.populateContentContainer(true);
80
- }
81
- }
82
- };
83
- DatePicker.prototype.inputKeyDown = function (e) {
84
- // TODO: find better way to check key. Maybe util class with KeyHelper.IsXXXKey(e)
85
- if (e.key === "Escape") {
86
- // Revert to previous value
87
- e.preventDefault();
88
- this.setBindValueAndClose(this.bindProperty.value, false);
89
- }
90
- else if (e.key === "Enter") {
91
- // Set date to today if the current value is null
92
- e.preventDefault();
93
- if (!this.bindProperty.value) {
94
- this.setBindValueAndClose(new Date(), true);
95
- }
96
- }
97
- };
98
- DatePicker.prototype.removePopup = function (animate) {
99
- if (this.popup) {
100
- if (animate) {
101
- AnimationHelper.scale(this.popup, DatePicker.AnimationClassName, 1, 0);
102
- AnimationHelper.beginRemove(this.container, this.popup);
103
- }
104
- else {
105
- this.container.removeChild(this.popup);
106
- }
107
- this.currentHeaderLabel = null;
108
- this.currentContentTable = null;
109
- this.popup = null;
110
- }
111
- };
112
- DatePicker.prototype.setBindValueAndClose = function (dateValue, preserveTime) {
113
- this.inputHasChanged = false;
114
- var oldValue = this.bindProperty.value;
115
- if (oldValue && dateValue && preserveTime) {
116
- // preserve the time component of the original date.
117
- dateValue.setHours(oldValue.getHours(), oldValue.getMinutes(), oldValue.getSeconds(), oldValue.getMilliseconds());
118
- }
119
- // Note: this may have the side effect of calling update().
120
- this.setBindProperty(dateValue, false);
121
- this.setInputValue();
122
- if (!this.options.alwaysShow) {
123
- this.removePopup(true);
124
- }
125
- };
126
- DatePicker.prototype.setBindProperty = function (dateValue, suspend) {
127
- var _this = this;
128
- if (dateValue) {
129
- dateValue = DateUtils.max(DateUtils.min(dateValue, this.options.maxDate), this.options.minDate);
130
- }
131
- if (suspend)
132
- this.suspendLayout = true;
133
- this.bindProperty.value = dateValue;
134
- if (suspend)
135
- Utils.nextTick(function () { return _this.suspendLayout = false; });
136
- };
137
- DatePicker.prototype.setInputValue = function () {
138
- if (!this.options.alwaysShow) {
139
- var displayValue = "";
140
- if (this.bindProperty.value) {
141
- displayValue = DateUtils.format(this.bindProperty.value, this.options.formatString);
142
- }
143
- this.input.value = displayValue;
144
- }
145
- };
146
- DatePicker.prototype.show = function () {
147
- if (!this.options.timeOnly) {
148
- this.resetCurrentViewDate();
149
- this.createComponents();
150
- this.positionPopup(true);
151
- AnimationHelper.fade(this.popup, DatePicker.AnimationClassName, true);
152
- }
153
- };
154
- DatePicker.prototype.positionPopup = function (fromBottom) {
155
- if (this.popup) {
156
- PositionHelper.checkScreenBounds(this.container, this.popup, fromBottom);
157
- }
158
- };
159
- /**
160
- * Updates the date picker options. This also updates the input value of the input element. Update should be called by the Vue / React component on each render.
161
- * @param options New options.
162
- */
163
- DatePicker.prototype.update = function (options, bindProperty, isReadOnly) {
164
- if (bindProperty && bindProperty !== this.bindProperty) {
165
- this.bindProperty = bindProperty;
166
- }
167
- if (options) {
168
- this.options = ProcessedDatePickerOptions.fromPartial(options);
169
- }
170
- this.isReadOnly = isReadOnly;
171
- this.today = DateUtils.today();
172
- if (this.currentBindValue !== (bindProperty === null || bindProperty === void 0 ? void 0 : bindProperty.value)) {
173
- this.currentBindValue = bindProperty === null || bindProperty === void 0 ? void 0 : bindProperty.value;
174
- this.resetCurrentViewDate();
175
- if (this.options.alwaysShow) {
176
- if (!this.suspendLayout) {
177
- this.createComponents();
178
- }
179
- }
180
- else {
181
- this.setInputValue();
182
- }
183
- }
184
- };
185
- DatePicker.prototype.resetCurrentViewDate = function () {
186
- this.setCurrentViewDate(this.bindProperty.value);
187
- this.currentViewType = this.options.monthView ? ViewType.Months : (this.options.yearView ? ViewType.Years : ViewType.Days);
188
- };
189
- DatePicker.prototype.setCurrentViewDate = function (fromDate) {
190
- if (fromDate) {
191
- this.boundDateNoTime = DateUtils.stripTime(fromDate);
192
- if (this.inputHasChanged) {
193
- // if the user is typing, show the selected date within the range of min and max date.
194
- this.boundDateNoTime = DateUtils.max(DateUtils.min(this.boundDateNoTime, this.options.maxDateNoTime), this.options.minDateNoTime);
195
- }
196
- this.currentViewDate = new Date(this.boundDateNoTime);
197
- }
198
- else {
199
- this.boundDateNoTime = null;
200
- this.currentViewDate = DateUtils.today();
201
- this.currentViewDate = DateUtils.max(DateUtils.min(this.currentViewDate, this.options.maxDateNoTime), this.options.minDateNoTime);
202
- }
203
- this.currentViewDate.setDate(1);
204
- if (this.options.yearView) {
205
- this.currentViewDate.setMonth(0);
206
- }
207
- };
208
- DatePicker.prototype.createComponents = function () {
209
- var _this = this;
210
- if (!this.popup) {
211
- this.popup = this.createAndAppend(this.container, "div", "neo-datepicker-popup");
212
- if (this.options.alwaysShow) {
213
- this.popup.classList.add("neo-datepicker-inline");
214
- }
215
- else {
216
- this.popup.addEventListener("mouseenter", function () { return _this.positionPopup(false); });
217
- this.popup.addEventListener("mouseleave", function () { return _this.positionPopup(true); });
218
- }
219
- this.createHeader();
220
- this.createContentContainer();
221
- }
222
- else {
223
- this.populateContentContainer(true);
224
- }
225
- };
226
- DatePicker.prototype.createHeader = function () {
227
- var header = this.createAndAppend(this.popup, "div", "neo-datepicker-header");
228
- this.prevButton = this.createAndAppend(header, "button", "left-button");
229
- this.prevButton.type = "button";
230
- this.prevButton.innerText = "<";
231
- this.prevButton.tabIndex = -1;
232
- this.prevButton.addEventListener("mousedown", this.previousClick.bind(this));
233
- this.headerContainer = this.createAndAppend(header, "div", "header-text-container");
234
- this.headerContainer.addEventListener("mousedown", this.headerClick.bind(this));
235
- this.headerAnimationHelper = new AnimationHelper(this.headerContainer, DatePicker.AnimationClassName);
236
- this.nextButton = this.createAndAppend(header, "button", "right-button");
237
- this.nextButton.type = "button";
238
- this.nextButton.innerText = ">";
239
- this.nextButton.tabIndex = -1;
240
- this.nextButton.addEventListener("mousedown", this.nextClick.bind(this));
241
- };
242
- DatePicker.prototype.createHeaderLabel = function () {
243
- this.currentHeaderLabel = this.createAndAppend(this.headerContainer, "div", "header-text");
244
- if (this.currentViewType == ViewType.Days) {
245
- this.currentHeaderLabel.innerText = DateUtils.format(this.currentViewDate, "MMMM yyyy");
246
- }
247
- else if (this.currentViewType == ViewType.Months) {
248
- this.currentHeaderLabel.innerText = DateUtils.format(this.currentViewDate, "yyyy");
249
- }
250
- else {
251
- this.currentHeaderLabel.innerText = this.currentViewDate.getFullYear() + " - " + (this.currentViewDate.getFullYear() + YearsInYearView - 1);
252
- }
253
- if (this.currentViewType < ViewType.Years && !(this.prevButton.disabled && this.nextButton.disabled)) {
254
- this.currentHeaderLabel.className += " selectable";
255
- }
256
- this.headerAnimationHelper.addChild(this.currentHeaderLabel, false);
257
- this.headerAnimationHelper.fade();
258
- };
259
- DatePicker.prototype.createContentContainer = function () {
260
- this.contentContainer = this.createAndAppend(this.popup, "div", "neo-datepicker-content");
261
- this.contentContainer.addEventListener("mousedown", this.contentClick.bind(this));
262
- this.contentAnimationHelper = new AnimationHelper(this.contentContainer, DatePicker.AnimationClassName);
263
- this.populateContentContainer(!!this.options.alwaysShow);
264
- };
265
- /**
266
- * Populates a new d/m/y view and replaces the old view
267
- * @param displayImmediately True if the new content must be displayed without animation.
268
- * @param sameViewType True if the view type is not changing. E.g. scrolling left and right.
269
- */
270
- DatePicker.prototype.populateContentContainer = function (displayImmediately, sameViewType) {
271
- if (this.currentViewType == ViewType.Days) {
272
- this.createDaysView();
273
- }
274
- else if (this.currentViewType == ViewType.Months) {
275
- this.createMonthsView();
276
- }
277
- else {
278
- if (!sameViewType)
279
- this.currentViewDate.setFullYear(this.currentViewDate.getFullYear() - this.options.yearsBeforeInYearView);
280
- this.createYearsView();
281
- }
282
- this.createHeaderLabel();
283
- this.contentAnimationHelper.addChild(this.currentContentTable, true);
284
- if (displayImmediately) {
285
- this.contentAnimationHelper.replace();
286
- }
287
- };
288
- DatePicker.prototype.createDaysView = function () {
289
- this.currentContentTable = this.createAndAppend(this.contentContainer, "table", "day-view");
290
- var tHead = this.createAndAppend(this.currentContentTable, "thead");
291
- var tBody = this.createAndAppend(this.currentContentTable, "tbody");
292
- var trHead = this.createAndAppend(tHead, "tr");
293
- var trBody = this.createAndAppend(tBody, "tr");
294
- var currentDate = new Date(this.currentViewDate);
295
- var lastDayOfMonth = DateUtils.monthEnd(currentDate);
296
- this.prevButton.disabled = this.options.minDateNoTime.getTime() >= currentDate.getTime();
297
- if (this.canAutoSetDate && this.options.autoChangeDate == "start") {
298
- this.setBindProperty(currentDate, true);
299
- }
300
- this.nextButton.disabled = this.options.maxDateNoTime.getTime() <= lastDayOfMonth.getTime();
301
- if (this.canAutoSetDate && this.options.autoChangeDate == "end") {
302
- this.setBindProperty(lastDayOfMonth, true);
303
- }
304
- // Start with the first Sunday before the first of the month.
305
- currentDate.setDate(currentDate.getDate() - currentDate.getDay());
306
- var first = true;
307
- while (true) {
308
- for (var i = 0; i < 7; i++) {
309
- if (first) {
310
- var dayHeader = DateUtils.i18n.dayNames[currentDate.getDay()];
311
- if (!this.options.display3DayLetters)
312
- dayHeader = dayHeader.substring(0, 2);
313
- this.createAndAppend(trHead, "th").innerText = dayHeader;
314
- }
315
- var cell = this.createAndAppend(trBody, "td");
316
- var date = currentDate.getDate();
317
- var month = currentDate.getMonth();
318
- cell.innerText = date.toString();
319
- this.setupCell(cell, currentDate.getFullYear() + "," + month + "," + date, currentDate.getTime() >= this.options.minDateNoTime.getTime() && currentDate.getTime() <= this.options.maxDateNoTime.getTime(), currentDate.getTime() == this.today.getTime(), this.boundDateNoTime != null && currentDate.getTime() == this.boundDateNoTime.getTime());
320
- if (month != this.currentViewDate.getMonth()) {
321
- cell.classList.add("outside-month");
322
- }
323
- currentDate.setDate(date + 1);
324
- }
325
- trBody = this.createAndAppend(tBody, "tr");
326
- first = false;
327
- if (currentDate.getMonth() != this.currentViewDate.getMonth())
328
- break;
329
- }
330
- this.canAutoSetDate = false;
331
- };
332
- DatePicker.prototype.createMonthsView = function () {
333
- this.currentContentTable = this.createAndAppend(this.contentContainer, "table", "month-view");
334
- var tBody = this.createAndAppend(this.currentContentTable, "tbody");
335
- var trBody;
336
- var year = this.currentViewDate.getFullYear();
337
- for (var i = 0; i < 12; i++) {
338
- var monthStartDate = new Date(year, i, 1).getTime();
339
- var monthEndDate = new Date(year, i + 1, 1).getTime();
340
- if (i % 4 == 0) {
341
- trBody = this.createAndAppend(tBody, "tr");
342
- }
343
- var cell = this.createAndAppend(trBody, "td");
344
- cell.innerText = DateUtils.i18n.monthNames[i];
345
- this.setupCell(cell, i, monthEndDate > this.options.minDateNoTime.getTime() && monthStartDate <= this.options.maxDateNoTime.getTime(), this.today.getFullYear() == year && this.today.getMonth() == i, this.boundDateNoTime != null && this.boundDateNoTime.getFullYear() == year && this.boundDateNoTime.getMonth() == i);
346
- }
347
- this.prevButton.disabled = this.options.minDateNoTime.getFullYear() >= year;
348
- this.nextButton.disabled = this.options.maxDateNoTime.getFullYear() <= year;
349
- };
350
- DatePicker.prototype.createYearsView = function () {
351
- this.currentContentTable = this.createAndAppend(this.contentContainer, "table", "year-view");
352
- var tBody = this.createAndAppend(this.currentContentTable, "tbody");
353
- var trBody;
354
- var year = this.currentViewDate.getFullYear();
355
- for (var i = 0; i < YearsInYearView; i++) {
356
- if (i % 4 == 0) {
357
- trBody = this.createAndAppend(tBody, "tr");
358
- }
359
- var cell = this.createAndAppend(trBody, "td");
360
- cell.innerText = (year + i).toString();
361
- this.setupCell(cell, cell.innerText, year + i >= this.options.minDateNoTime.getFullYear() && year + i <= this.options.maxDateNoTime.getFullYear(), this.today.getFullYear() == year + i, this.boundDateNoTime != null && this.boundDateNoTime.getFullYear() == year + i);
362
- }
363
- this.prevButton.disabled = this.options.minDateNoTime.getFullYear() >= year;
364
- this.nextButton.disabled = this.options.maxDateNoTime.getFullYear() < year + YearsInYearView;
365
- };
366
- DatePicker.prototype.setupCell = function (cell, data, selectable, current, isSelected) {
367
- if (selectable) {
368
- cell.classList.add("selectable");
369
- cell.dataset["date"] = data;
370
- }
371
- else {
372
- cell.classList.add("disabled");
373
- }
374
- if (current) {
375
- cell.classList.add("today");
376
- }
377
- if (isSelected) {
378
- cell.classList.add("selected");
379
- }
380
- };
381
- DatePicker.prototype.contentClick = function (e) {
382
- e.preventDefault();
383
- if (e.target) {
384
- if (this.currentViewType == ViewType.Days) {
385
- this.dayClicked(e.target);
386
- }
387
- else if (this.currentViewType == ViewType.Months) {
388
- this.monthClicked(e.target);
389
- }
390
- else {
391
- this.yearClicked(e.target);
392
- }
393
- }
394
- };
395
- DatePicker.prototype.dayClicked = function (element) {
396
- var datePartsString = element.dataset["date"];
397
- if (datePartsString) {
398
- var dateParts = datePartsString.split(",");
399
- this.setBindValueAndClose(new Date(parseInt(dateParts[0]), parseInt(dateParts[1]), parseInt(dateParts[2])), true);
400
- }
401
- };
402
- DatePicker.prototype.monthClicked = function (element) {
403
- var monthString = element.dataset["date"];
404
- if (monthString) {
405
- this.currentViewDate.setMonth(parseInt(monthString));
406
- if (this.options.monthView) {
407
- this.setBindValueAndClose(this.currentViewDate, true);
408
- }
409
- else {
410
- this.currentViewType = ViewType.Days;
411
- this.canAutoSetDate = true;
412
- this.populateContentContainer(false);
413
- this.contentAnimationHelper.fadeAndScale(true);
414
- }
415
- }
416
- };
417
- DatePicker.prototype.yearClicked = function (element) {
418
- var yearString = element.dataset["date"];
419
- if (yearString) {
420
- this.currentViewDate.setFullYear(parseInt(yearString));
421
- if (this.options.yearView) {
422
- this.setBindValueAndClose(this.currentViewDate, true);
423
- }
424
- else {
425
- this.currentViewType = ViewType.Months;
426
- this.populateContentContainer(false);
427
- this.contentAnimationHelper.fadeAndScale(true);
428
- }
429
- }
430
- };
431
- DatePicker.prototype.headerClick = function (e) {
432
- e.preventDefault();
433
- if (this.currentHeaderLabel.classList.contains("selectable")) {
434
- if (this.currentViewType == ViewType.Days) {
435
- this.currentViewType = ViewType.Months;
436
- }
437
- else if (this.currentViewType == ViewType.Months) {
438
- this.currentViewType = ViewType.Years;
439
- }
440
- else {
441
- return;
442
- }
443
- this.populateContentContainer(false);
444
- this.contentAnimationHelper.fadeAndScale(false);
445
- }
446
- };
447
- DatePicker.prototype.previousClick = function (e) {
448
- e.preventDefault();
449
- this.moveCurrent(-1);
450
- };
451
- DatePicker.prototype.nextClick = function (e) {
452
- e.preventDefault();
453
- this.moveCurrent(1);
454
- };
455
- DatePicker.prototype.moveCurrent = function (delta) {
456
- if (this.currentViewType == ViewType.Days) {
457
- this.canAutoSetDate = true;
458
- this.currentViewDate.setMonth(this.currentViewDate.getMonth() + delta, 1);
459
- }
460
- else {
461
- this.currentViewDate.setFullYear(this.currentViewDate.getFullYear() + delta * (this.currentViewType == ViewType.Months ? 1 : YearsInYearView));
462
- }
463
- this.populateContentContainer(false, true);
464
- this.contentAnimationHelper.slide(delta, true);
465
- };
466
- DatePicker.prototype.createAndAppend = function (parent, elementType, className) {
467
- if (className === void 0) { className = ""; }
468
- var newElement = document.createElement(elementType);
469
- if (className)
470
- newElement.className = className;
471
- parent.appendChild(newElement);
472
- return newElement;
473
- };
474
- DatePicker.prototype.destroy = function () {
475
- if (this.input) {
476
- this.input.removeEventListener("focus", this.inputFocused);
477
- this.input.removeEventListener("mousedown", this.inputFocused);
478
- this.input.removeEventListener("blur", this.inputBlurred);
479
- this.input.removeEventListener("input", this.inputChanged);
480
- this.input.removeEventListener("keydown", this.inputKeyDown);
481
- }
482
- this.removePopup(false);
483
- };
484
- DatePicker.AnimationClassName = "neo-datepicker-animate";
485
- return DatePicker;
486
- }());
487
- export default DatePicker;
1
+ import DateUtils from '../../Dates/DateUtils';
2
+ import AnimationHelper from '../AnimationHelper';
3
+ import { YearsInYearView, ProcessedDatePickerOptions } from './DatePickerOptions';
4
+ import PositionHelper from '../PositionHelper';
5
+ import { Utils } from '../../Utils';
6
+ // TODO: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
7
+ // TODO: Allow input to be shown with inline picker, and specify position.
8
+ var ViewType;
9
+ (function (ViewType) {
10
+ ViewType[ViewType["Days"] = 1] = "Days";
11
+ ViewType[ViewType["Months"] = 2] = "Months";
12
+ ViewType[ViewType["Years"] = 3] = "Years";
13
+ })(ViewType || (ViewType = {}));
14
+ var DatePicker = /** @class */ (function () {
15
+ function DatePicker(container, options) {
16
+ this.container = container;
17
+ this.isReadOnly = false;
18
+ this.inputHasChanged = false;
19
+ this.canAutoSetDate = false;
20
+ this.suspendLayout = false;
21
+ this.currentBindValue = null;
22
+ this.boundDateNoTime = null;
23
+ this.options = ProcessedDatePickerOptions.fromPartial(options || {});
24
+ this.inputFocused = this.inputFocused.bind(this);
25
+ this.inputBlurred = this.inputBlurred.bind(this);
26
+ this.inputChanged = this.inputChanged.bind(this);
27
+ this.inputKeyDown = this.inputKeyDown.bind(this);
28
+ if (!this.options.alwaysShow) {
29
+ this.input = this.container.getElementsByTagName('input')[0];
30
+ this.input.addEventListener("focus", this.inputFocused);
31
+ this.input.addEventListener("mousedown", this.inputFocused);
32
+ this.input.addEventListener("blur", this.inputBlurred);
33
+ this.input.addEventListener("input", this.inputChanged);
34
+ this.input.addEventListener("keydown", this.inputKeyDown);
35
+ if (this.options.timeOnly) {
36
+ this.input.placeholder = "hh:mm" + (this.options.formatString.indexOf("s") > 0 ? ":ss" : "");
37
+ }
38
+ }
39
+ }
40
+ DatePicker.prototype.inputFocused = function (e) {
41
+ if (!this.popup && !this.isReadOnly) {
42
+ this.show();
43
+ }
44
+ if (window.innerWidth <= 576 && !this.options.timeOnly) {
45
+ // Stop keyboard showing on phones.
46
+ this.input.readOnly = true;
47
+ }
48
+ };
49
+ DatePicker.prototype.inputBlurred = function () {
50
+ this.onInputBlurred(true);
51
+ };
52
+ DatePicker.prototype.onInputBlurred = function (closePopup) {
53
+ if (this.inputHasChanged) {
54
+ if (this.input.value) {
55
+ // if this is time only, use the existing value to preserve the date.
56
+ var refDate = this.options.timeOnly && this.bindProperty.value;
57
+ var parsedDate = DateUtils.tryParse(this.input.value, this.options.formatString, false, refDate || new Date());
58
+ if (parsedDate) {
59
+ this.setBindValue(parsedDate, { preserveTime: false, close: closePopup });
60
+ }
61
+ else {
62
+ this.setBindValue(this.bindProperty.value, { preserveTime: false, close: closePopup });
63
+ }
64
+ }
65
+ else {
66
+ this.setBindValue(null, { preserveTime: true, close: closePopup });
67
+ }
68
+ }
69
+ else {
70
+ if (this.options.autoClose && closePopup)
71
+ this.removePopup(true);
72
+ }
73
+ this.input.readOnly = this.isReadOnly;
74
+ };
75
+ DatePicker.prototype.inputChanged = function () {
76
+ this.inputHasChanged = true;
77
+ if (!this.options.timeOnly) {
78
+ // Update the displayed date as the user types.
79
+ var parsedDate = DateUtils.tryParse(this.input.value, this.options.formatString, false, this.bindProperty.value);
80
+ if (parsedDate) {
81
+ this.setCurrentViewDate(parsedDate);
82
+ this.populateContentContainer(true);
83
+ }
84
+ if (!this.popup) {
85
+ this.show();
86
+ }
87
+ }
88
+ };
89
+ DatePicker.prototype.inputKeyDown = function (e) {
90
+ // TODO: find better way to check key. Maybe util class with KeyHelper.IsXXXKey(e)
91
+ if (e.key === "Escape") {
92
+ // Revert to previous value
93
+ e.preventDefault();
94
+ this.setBindValue(this.bindProperty.value, { preserveTime: false, close: false });
95
+ }
96
+ else if (e.key === "Enter") {
97
+ var prevValue = this.input.value;
98
+ if (!this.bindProperty.value && !this.input.value) {
99
+ // Set date to today if the current value is null
100
+ this.setBindValue(new Date(), { preserveTime: true, close: false });
101
+ }
102
+ else {
103
+ this.onInputBlurred(false);
104
+ }
105
+ if (this.input.value !== prevValue) {
106
+ e.preventDefault();
107
+ }
108
+ else {
109
+ this.removePopup(true);
110
+ }
111
+ }
112
+ };
113
+ DatePicker.prototype.removePopup = function (animate) {
114
+ if (this.popup) {
115
+ if (animate) {
116
+ AnimationHelper.scale(this.popup, DatePicker.AnimationClassName, 1, 0);
117
+ AnimationHelper.beginRemove(this.container, this.popup);
118
+ }
119
+ else {
120
+ this.container.removeChild(this.popup);
121
+ }
122
+ this.currentHeaderLabel = null;
123
+ this.currentContentTable = null;
124
+ this.popup = null;
125
+ }
126
+ };
127
+ DatePicker.prototype.setBindValue = function (dateValue, options) {
128
+ this.inputHasChanged = false;
129
+ var oldValue = this.bindProperty.value;
130
+ if (oldValue && dateValue && options.preserveTime) {
131
+ // preserve the time component of the original date.
132
+ dateValue.setHours(oldValue.getHours(), oldValue.getMinutes(), oldValue.getSeconds(), oldValue.getMilliseconds());
133
+ }
134
+ // Note: this may have the side effect of calling update().
135
+ this.setBindProperty(dateValue, false);
136
+ this.setInputValue();
137
+ if (!this.options.alwaysShow && options.close) {
138
+ this.removePopup(true);
139
+ }
140
+ };
141
+ DatePicker.prototype.setBindProperty = function (dateValue, suspend) {
142
+ var _this = this;
143
+ if (dateValue) {
144
+ dateValue = DateUtils.max(DateUtils.min(dateValue, this.options.maxDate), this.options.minDate);
145
+ }
146
+ if (suspend)
147
+ this.suspendLayout = true;
148
+ this.bindProperty.value = dateValue;
149
+ if (suspend)
150
+ Utils.nextTick(function () { return _this.suspendLayout = false; });
151
+ if (this.options.onDateSelected !== undefined) {
152
+ this.options.onDateSelected(!suspend);
153
+ }
154
+ };
155
+ DatePicker.prototype.setInputValue = function () {
156
+ if (!this.options.alwaysShow) {
157
+ var displayValue = "";
158
+ if (this.bindProperty.value) {
159
+ displayValue = DateUtils.format(this.bindProperty.value, this.options.formatString);
160
+ }
161
+ this.input.value = displayValue;
162
+ }
163
+ };
164
+ DatePicker.prototype.show = function () {
165
+ if (!this.options.timeOnly) {
166
+ this.resetCurrentViewDate();
167
+ this.createComponents();
168
+ this.positionPopup(true);
169
+ AnimationHelper.fade(this.popup, DatePicker.AnimationClassName, true);
170
+ }
171
+ };
172
+ DatePicker.prototype.positionPopup = function (fromBottom) {
173
+ if (this.popup) {
174
+ PositionHelper.checkScreenBounds(this.container, this.popup, fromBottom, this.options.popupAlignRight);
175
+ }
176
+ };
177
+ /**
178
+ * Updates the date picker options. This also updates the input value of the input element. Update should be called by the Vue / React component on each render.
179
+ * @param options New options.
180
+ */
181
+ DatePicker.prototype.update = function (options, bindProperty, isReadOnly) {
182
+ if (bindProperty && bindProperty !== this.bindProperty) {
183
+ this.bindProperty = bindProperty;
184
+ }
185
+ if (options) {
186
+ this.options = ProcessedDatePickerOptions.fromPartial(options);
187
+ }
188
+ this.isReadOnly = isReadOnly;
189
+ this.today = DateUtils.today();
190
+ if (this.currentBindValue !== (bindProperty === null || bindProperty === void 0 ? void 0 : bindProperty.value)) {
191
+ this.currentBindValue = bindProperty === null || bindProperty === void 0 ? void 0 : bindProperty.value;
192
+ this.resetCurrentViewDate();
193
+ if (this.options.alwaysShow) {
194
+ if (!this.suspendLayout) {
195
+ this.createComponents();
196
+ }
197
+ }
198
+ else {
199
+ this.setInputValue();
200
+ }
201
+ }
202
+ };
203
+ DatePicker.prototype.resetCurrentViewDate = function () {
204
+ this.setCurrentViewDate(this.bindProperty.value);
205
+ this.currentViewType = this.options.monthView ? ViewType.Months : (this.options.yearView ? ViewType.Years : ViewType.Days);
206
+ };
207
+ DatePicker.prototype.setCurrentViewDate = function (fromDate) {
208
+ if (fromDate) {
209
+ this.boundDateNoTime = DateUtils.stripTime(fromDate);
210
+ if (this.inputHasChanged) {
211
+ // if the user is typing, show the selected date within the range of min and max date.
212
+ this.boundDateNoTime = DateUtils.max(DateUtils.min(this.boundDateNoTime, this.options.maxDateNoTime), this.options.minDateNoTime);
213
+ }
214
+ this.currentViewDate = new Date(this.boundDateNoTime);
215
+ }
216
+ else {
217
+ this.boundDateNoTime = null;
218
+ this.currentViewDate = DateUtils.today();
219
+ this.currentViewDate = DateUtils.max(DateUtils.min(this.currentViewDate, this.options.maxDateNoTime), this.options.minDateNoTime);
220
+ }
221
+ this.currentViewDate.setDate(1);
222
+ if (this.options.yearView) {
223
+ this.currentViewDate.setMonth(0);
224
+ }
225
+ };
226
+ DatePicker.prototype.createComponents = function () {
227
+ var _this = this;
228
+ if (!this.popup) {
229
+ this.popup = this.createAndAppend(this.container, "div", "neo-datepicker-popup");
230
+ if (this.options.alwaysShow) {
231
+ this.popup.classList.add("neo-datepicker-inline");
232
+ }
233
+ else {
234
+ this.popup.addEventListener("mouseenter", function () { return _this.positionPopup(false); });
235
+ this.popup.addEventListener("mouseleave", function () { return _this.positionPopup(true); });
236
+ }
237
+ this.createHeader();
238
+ this.createContentContainer();
239
+ }
240
+ else {
241
+ this.populateContentContainer(true);
242
+ }
243
+ };
244
+ DatePicker.prototype.createHeader = function () {
245
+ var header = this.createAndAppend(this.popup, "div", "neo-datepicker-header");
246
+ this.prevButton = this.createAndAppend(header, "button", "left-button");
247
+ this.prevButton.type = "button";
248
+ this.prevButton.innerText = "<";
249
+ this.prevButton.tabIndex = -1;
250
+ this.prevButton.addEventListener("mousedown", this.previousClick.bind(this));
251
+ this.headerContainer = this.createAndAppend(header, "div", "header-text-container");
252
+ this.headerContainer.addEventListener("mousedown", this.headerClick.bind(this));
253
+ this.headerAnimationHelper = new AnimationHelper(this.headerContainer, DatePicker.AnimationClassName);
254
+ this.nextButton = this.createAndAppend(header, "button", "right-button");
255
+ this.nextButton.type = "button";
256
+ this.nextButton.innerText = ">";
257
+ this.nextButton.tabIndex = -1;
258
+ this.nextButton.addEventListener("mousedown", this.nextClick.bind(this));
259
+ };
260
+ DatePicker.prototype.createHeaderLabel = function () {
261
+ this.currentHeaderLabel = this.createAndAppend(this.headerContainer, "div", "header-text");
262
+ if (this.currentViewType == ViewType.Days) {
263
+ this.currentHeaderLabel.innerText = DateUtils.format(this.currentViewDate, "MMMM yyyy");
264
+ }
265
+ else if (this.currentViewType == ViewType.Months) {
266
+ this.currentHeaderLabel.innerText = DateUtils.format(this.currentViewDate, "yyyy");
267
+ }
268
+ else {
269
+ this.currentHeaderLabel.innerText = this.currentViewDate.getFullYear() + " - " + (this.currentViewDate.getFullYear() + YearsInYearView - 1);
270
+ }
271
+ if (this.currentViewType < ViewType.Years && !(this.prevButton.disabled && this.nextButton.disabled)) {
272
+ this.currentHeaderLabel.className += " selectable";
273
+ }
274
+ this.headerAnimationHelper.addChild(this.currentHeaderLabel, false);
275
+ this.headerAnimationHelper.fade();
276
+ };
277
+ DatePicker.prototype.createContentContainer = function () {
278
+ this.contentContainer = this.createAndAppend(this.popup, "div", "neo-datepicker-content");
279
+ this.contentContainer.addEventListener("mousedown", this.contentClick.bind(this));
280
+ this.contentAnimationHelper = new AnimationHelper(this.contentContainer, DatePicker.AnimationClassName);
281
+ this.populateContentContainer(!!this.options.alwaysShow);
282
+ };
283
+ /**
284
+ * Populates a new d/m/y view and replaces the old view
285
+ * @param displayImmediately True if the new content must be displayed without animation.
286
+ * @param sameViewType True if the view type is not changing. E.g. scrolling left and right.
287
+ */
288
+ DatePicker.prototype.populateContentContainer = function (displayImmediately, sameViewType) {
289
+ if (this.currentViewType == ViewType.Days) {
290
+ this.createDaysView();
291
+ }
292
+ else if (this.currentViewType == ViewType.Months) {
293
+ this.createMonthsView();
294
+ }
295
+ else {
296
+ if (!sameViewType)
297
+ this.currentViewDate.setFullYear(this.currentViewDate.getFullYear() - this.options.yearsBeforeInYearView);
298
+ this.createYearsView();
299
+ }
300
+ this.createHeaderLabel();
301
+ this.contentAnimationHelper.addChild(this.currentContentTable, true);
302
+ if (displayImmediately) {
303
+ this.contentAnimationHelper.replace();
304
+ }
305
+ };
306
+ DatePicker.prototype.createDaysView = function () {
307
+ this.currentContentTable = this.createAndAppend(this.contentContainer, "table", "day-view");
308
+ var tHead = this.createAndAppend(this.currentContentTable, "thead");
309
+ var tBody = this.createAndAppend(this.currentContentTable, "tbody");
310
+ var trHead = this.createAndAppend(tHead, "tr");
311
+ var trBody = this.createAndAppend(tBody, "tr");
312
+ var currentDate = new Date(this.currentViewDate);
313
+ var lastDayOfMonth = DateUtils.monthEnd(currentDate);
314
+ this.prevButton.disabled = this.options.minDateNoTime.getTime() >= currentDate.getTime();
315
+ if (this.canAutoSetDate && this.options.autoChangeDate == "start") {
316
+ this.setBindProperty(currentDate, true);
317
+ }
318
+ this.nextButton.disabled = this.options.maxDateNoTime.getTime() <= lastDayOfMonth.getTime();
319
+ if (this.canAutoSetDate && this.options.autoChangeDate == "end") {
320
+ this.setBindProperty(lastDayOfMonth, true);
321
+ }
322
+ // Start with the first Sunday before the first of the month.
323
+ currentDate.setDate(currentDate.getDate() - currentDate.getDay());
324
+ var first = true;
325
+ while (true) {
326
+ for (var i = 0; i < 7; i++) {
327
+ if (first) {
328
+ var dayHeader = DateUtils.i18n.dayNames[currentDate.getDay()];
329
+ if (!this.options.display3DayLetters)
330
+ dayHeader = dayHeader.substring(0, 2);
331
+ this.createAndAppend(trHead, "th").innerText = dayHeader;
332
+ }
333
+ var cell = this.createAndAppend(trBody, "td");
334
+ var date = currentDate.getDate();
335
+ var month = currentDate.getMonth();
336
+ this.setupCell(cell, date.toString(), currentDate.getFullYear() + "," + month + "," + date, currentDate.getTime() >= this.options.minDateNoTime.getTime() && currentDate.getTime() <= this.options.maxDateNoTime.getTime(), currentDate.getTime() == this.today.getTime(), this.boundDateNoTime != null && currentDate.getTime() == this.boundDateNoTime.getTime());
337
+ if (month != this.currentViewDate.getMonth()) {
338
+ cell.classList.add("outside-month");
339
+ }
340
+ currentDate.setDate(date + 1);
341
+ }
342
+ trBody = this.createAndAppend(tBody, "tr");
343
+ first = false;
344
+ if (currentDate.getMonth() != this.currentViewDate.getMonth())
345
+ break;
346
+ }
347
+ this.canAutoSetDate = false;
348
+ };
349
+ DatePicker.prototype.createMonthsView = function () {
350
+ this.currentContentTable = this.createAndAppend(this.contentContainer, "table", "month-view");
351
+ var tBody = this.createAndAppend(this.currentContentTable, "tbody");
352
+ var trBody;
353
+ var year = this.currentViewDate.getFullYear();
354
+ for (var i = 0; i < 12; i++) {
355
+ var monthStartDate = new Date(year, i, 1).getTime();
356
+ var monthEndDate = new Date(year, i + 1, 1).getTime();
357
+ if (i % 4 == 0) {
358
+ trBody = this.createAndAppend(tBody, "tr");
359
+ }
360
+ var cell = this.createAndAppend(trBody, "td");
361
+ this.setupCell(cell, DateUtils.i18n.monthNames[i], i, monthEndDate > this.options.minDateNoTime.getTime() && monthStartDate <= this.options.maxDateNoTime.getTime(), this.today.getFullYear() == year && this.today.getMonth() == i, this.boundDateNoTime != null && this.boundDateNoTime.getFullYear() == year && this.boundDateNoTime.getMonth() == i);
362
+ }
363
+ this.prevButton.disabled = this.options.minDateNoTime.getFullYear() >= year;
364
+ this.nextButton.disabled = this.options.maxDateNoTime.getFullYear() <= year;
365
+ };
366
+ DatePicker.prototype.createYearsView = function () {
367
+ this.currentContentTable = this.createAndAppend(this.contentContainer, "table", "year-view");
368
+ var tBody = this.createAndAppend(this.currentContentTable, "tbody");
369
+ var trBody;
370
+ var year = this.currentViewDate.getFullYear();
371
+ for (var i = 0; i < YearsInYearView; i++) {
372
+ if (i % 4 == 0) {
373
+ trBody = this.createAndAppend(tBody, "tr");
374
+ }
375
+ var cell = this.createAndAppend(trBody, "td");
376
+ this.setupCell(cell, (year + i).toString(), (year + i).toString(), year + i >= this.options.minDateNoTime.getFullYear() && year + i <= this.options.maxDateNoTime.getFullYear(), this.today.getFullYear() == year + i, this.boundDateNoTime != null && this.boundDateNoTime.getFullYear() == year + i);
377
+ }
378
+ this.prevButton.disabled = this.options.minDateNoTime.getFullYear() >= year;
379
+ this.nextButton.disabled = this.options.maxDateNoTime.getFullYear() < year + YearsInYearView;
380
+ };
381
+ DatePicker.prototype.setupCell = function (cell, innerText, data, selectable, current, isSelected) {
382
+ if (selectable) {
383
+ cell.classList.add("selectable");
384
+ cell.dataset["date"] = data;
385
+ }
386
+ else {
387
+ cell.classList.add("disabled");
388
+ }
389
+ if (current) {
390
+ cell.classList.add("today");
391
+ }
392
+ if (isSelected) {
393
+ cell.classList.add("selected");
394
+ }
395
+ var cellContent = this.createAndAppend(cell, "span");
396
+ cellContent.innerText = innerText;
397
+ };
398
+ DatePicker.prototype.contentClick = function (e) {
399
+ e.preventDefault();
400
+ if (e.target) {
401
+ var element = e.target;
402
+ if (!element.dataset["date"]) {
403
+ element = element.parentElement;
404
+ }
405
+ var dateString = element === null || element === void 0 ? void 0 : element.dataset["date"];
406
+ if (dateString) {
407
+ if (this.currentViewType == ViewType.Days) {
408
+ this.dayClicked(dateString);
409
+ }
410
+ else if (this.currentViewType == ViewType.Months) {
411
+ this.monthClicked(dateString);
412
+ }
413
+ else {
414
+ this.yearClicked(dateString);
415
+ }
416
+ }
417
+ }
418
+ };
419
+ DatePicker.prototype.dayClicked = function (datePartsString) {
420
+ var dateParts = datePartsString.split(",");
421
+ this.setBindValue(new Date(parseInt(dateParts[0]), parseInt(dateParts[1]), parseInt(dateParts[2])), { preserveTime: true, close: true });
422
+ };
423
+ DatePicker.prototype.monthClicked = function (monthString) {
424
+ this.currentViewDate.setMonth(parseInt(monthString));
425
+ if (this.options.monthView) {
426
+ this.setBindValue(this.currentViewDate, { preserveTime: true, close: true });
427
+ }
428
+ else {
429
+ this.currentViewType = ViewType.Days;
430
+ this.canAutoSetDate = true;
431
+ this.populateContentContainer(false);
432
+ this.contentAnimationHelper.fadeAndScale(true);
433
+ }
434
+ };
435
+ DatePicker.prototype.yearClicked = function (yearString) {
436
+ this.currentViewDate.setFullYear(parseInt(yearString));
437
+ if (this.options.yearView) {
438
+ this.setBindValue(this.currentViewDate, { preserveTime: true, close: true });
439
+ }
440
+ else {
441
+ this.currentViewType = ViewType.Months;
442
+ this.populateContentContainer(false);
443
+ this.contentAnimationHelper.fadeAndScale(true);
444
+ }
445
+ };
446
+ DatePicker.prototype.headerClick = function (e) {
447
+ e.preventDefault();
448
+ if (this.currentHeaderLabel.classList.contains("selectable")) {
449
+ if (this.currentViewType == ViewType.Days) {
450
+ this.currentViewType = ViewType.Months;
451
+ }
452
+ else if (this.currentViewType == ViewType.Months) {
453
+ this.currentViewType = ViewType.Years;
454
+ }
455
+ else {
456
+ return;
457
+ }
458
+ this.populateContentContainer(false);
459
+ this.contentAnimationHelper.fadeAndScale(false);
460
+ }
461
+ };
462
+ DatePicker.prototype.previousClick = function (e) {
463
+ e.preventDefault();
464
+ this.moveCurrent(-1);
465
+ };
466
+ DatePicker.prototype.nextClick = function (e) {
467
+ e.preventDefault();
468
+ this.moveCurrent(1);
469
+ };
470
+ DatePicker.prototype.moveCurrent = function (delta) {
471
+ if (this.currentViewType == ViewType.Days) {
472
+ this.canAutoSetDate = true;
473
+ this.currentViewDate.setMonth(this.currentViewDate.getMonth() + delta, 1);
474
+ }
475
+ else {
476
+ this.currentViewDate.setFullYear(this.currentViewDate.getFullYear() + delta * (this.currentViewType == ViewType.Months ? 1 : YearsInYearView));
477
+ }
478
+ this.populateContentContainer(false, true);
479
+ this.contentAnimationHelper.slide(delta, true);
480
+ };
481
+ DatePicker.prototype.createAndAppend = function (parent, elementType, className) {
482
+ if (className === void 0) { className = ""; }
483
+ var newElement = document.createElement(elementType);
484
+ if (className)
485
+ newElement.className = className;
486
+ parent.appendChild(newElement);
487
+ return newElement;
488
+ };
489
+ DatePicker.prototype.destroy = function () {
490
+ if (this.input) {
491
+ this.input.removeEventListener("focus", this.inputFocused);
492
+ this.input.removeEventListener("mousedown", this.inputFocused);
493
+ this.input.removeEventListener("blur", this.inputBlurred);
494
+ this.input.removeEventListener("input", this.inputChanged);
495
+ this.input.removeEventListener("keydown", this.inputKeyDown);
496
+ }
497
+ this.removePopup(false);
498
+ };
499
+ DatePicker.AnimationClassName = "neo-datepicker-animate";
500
+ return DatePicker;
501
+ }());
502
+ export default DatePicker;