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