d2coreui 21.0.33 → 23.0.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 (295) hide show
  1. package/components/clipboard/clipboardUtils.d.ts +4 -3
  2. package/components/clipboard/clipboardUtils.js +47 -22
  3. package/components/clipboard/clipboardUtils.js.map +1 -1
  4. package/components/codemirror/SyntaxHighlighter.d.ts +21 -21
  5. package/components/codemirror/SyntaxHighlighter.js +45 -44
  6. package/components/codemirror/SyntaxHighlighter.js.map +1 -1
  7. package/components/collapse/expandable.d.ts +13 -12
  8. package/components/collapse/expandable.js +20 -20
  9. package/components/collapse/expandable.js.map +1 -1
  10. package/components/color/colorPicker.d.ts +20 -20
  11. package/components/color/colorPicker.js +53 -53
  12. package/components/color/colorPicker.js.map +1 -1
  13. package/components/color/colorSwatch.d.ts +13 -12
  14. package/components/color/colorSwatch.js +62 -62
  15. package/components/color/colorSwatch.js.map +1 -1
  16. package/components/color/colorUtils.d.ts +7 -7
  17. package/components/color/colorUtils.js +43 -43
  18. package/components/color/colorUtils.js.map +1 -1
  19. package/components/date/dateRangeInput.d.ts +66 -64
  20. package/components/date/dateRangeInput.js +292 -297
  21. package/components/date/dateRangeInput.js.map +1 -1
  22. package/components/date/dateRangeInputAdvancedPanel.d.ts +27 -26
  23. package/components/date/dateRangeInputAdvancedPanel.js +130 -115
  24. package/components/date/dateRangeInputAdvancedPanel.js.map +1 -1
  25. package/components/date/dateRangeInputConfirm.d.ts +31 -29
  26. package/components/date/dateRangeInputConfirm.js +132 -121
  27. package/components/date/dateRangeInputConfirm.js.map +1 -1
  28. package/components/date/dateTimeInput.d.ts +72 -69
  29. package/components/date/dateTimeInput.js +440 -412
  30. package/components/date/dateTimeInput.js.map +1 -1
  31. package/components/date/durationInput.d.ts +59 -56
  32. package/components/date/durationInput.js +269 -280
  33. package/components/date/durationInput.js.map +1 -1
  34. package/components/form/NiceFormItem.d.ts +14 -14
  35. package/components/form/NiceFormItem.js +28 -31
  36. package/components/form/NiceFormItem.js.map +1 -1
  37. package/components/grid/cell/beanAccessor.d.ts +9 -0
  38. package/components/grid/cell/beanAccessor.js +13 -0
  39. package/components/grid/cell/beanAccessor.js.map +1 -0
  40. package/components/grid/cell/cellEditorUtils.d.ts +4 -4
  41. package/components/grid/cell/cellEditorUtils.js +8 -8
  42. package/components/grid/cell/customEnumCellEditor.d.ts +4 -26
  43. package/components/grid/cell/customEnumCellEditor.js +82 -91
  44. package/components/grid/cell/customEnumCellEditor.js.map +1 -1
  45. package/components/grid/cell/dataGridCellEditorComponent.d.ts +14 -0
  46. package/components/grid/cell/dataGridCellEditorComponent.js +49 -0
  47. package/components/grid/cell/dataGridCellEditorComponent.js.map +1 -0
  48. package/components/grid/cell/dateCellEditor.d.ts +4 -25
  49. package/components/grid/cell/dateCellEditor.js +53 -72
  50. package/components/grid/cell/dateCellEditor.js.map +1 -1
  51. package/components/grid/cell/durationCellEditor.d.ts +4 -24
  52. package/components/grid/cell/durationCellEditor.js +74 -97
  53. package/components/grid/cell/durationCellEditor.js.map +1 -1
  54. package/components/grid/cell/hexaOctetStringCellEditor.d.ts +4 -24
  55. package/components/grid/cell/hexaOctetStringCellEditor.js +70 -94
  56. package/components/grid/cell/hexaOctetStringCellEditor.js.map +1 -1
  57. package/components/grid/cell/hexaValueCellEditor.d.ts +4 -24
  58. package/components/grid/cell/hexaValueCellEditor.js +65 -89
  59. package/components/grid/cell/hexaValueCellEditor.js.map +1 -1
  60. package/components/grid/cell/numberCellEditor.d.ts +4 -27
  61. package/components/grid/cell/numberCellEditor.js +73 -95
  62. package/components/grid/cell/numberCellEditor.js.map +1 -1
  63. package/components/grid/cell/rangeSelector.d.ts +78 -78
  64. package/components/grid/cell/rangeSelector.js +526 -518
  65. package/components/grid/cell/rangeSelector.js.map +1 -1
  66. package/components/grid/cell/simpleStatusTextCellEditor.d.ts +4 -32
  67. package/components/grid/cell/simpleStatusTextCellEditor.js +106 -116
  68. package/components/grid/cell/simpleStatusTextCellEditor.js.map +1 -1
  69. package/components/grid/cell/statusTextCellEditor.d.ts +4 -32
  70. package/components/grid/cell/statusTextCellEditor.js +136 -159
  71. package/components/grid/cell/statusTextCellEditor.js.map +1 -1
  72. package/components/grid/cell/tableDefaultRowStyleRules.d.ts +20 -20
  73. package/components/grid/cell/tableDefaultRowStyleRules.js +29 -18
  74. package/components/grid/cell/tableDefaultRowStyleRules.js.map +1 -1
  75. package/components/grid/cell/textCellEditor.d.ts +4 -21
  76. package/components/grid/cell/textCellEditor.js +63 -85
  77. package/components/grid/cell/textCellEditor.js.map +1 -1
  78. package/components/grid/cell/withAgGridHooks.d.ts +3 -0
  79. package/components/grid/cell/withAgGridHooks.js +15 -0
  80. package/components/grid/cell/withAgGridHooks.js.map +1 -0
  81. package/components/grid/columnUtils.d.ts +5 -5
  82. package/components/grid/columnUtils.js +26 -26
  83. package/components/grid/columnUtils.js.map +1 -1
  84. package/components/grid/config/columnTransfer.d.ts +21 -22
  85. package/components/grid/config/columnTransfer.js +205 -201
  86. package/components/grid/config/columnTransfer.js.map +1 -1
  87. package/components/grid/config/dataGridEditor.d.ts +41 -41
  88. package/components/grid/config/dataGridEditor.js +181 -160
  89. package/components/grid/config/dataGridEditor.js.map +1 -1
  90. package/components/grid/config/rowHeightCalculator.d.ts +8 -0
  91. package/components/grid/config/rowHeightCalculator.js +20 -0
  92. package/components/grid/config/rowHeightCalculator.js.map +1 -0
  93. package/components/grid/config/rowStylePicker.d.ts +27 -25
  94. package/components/grid/config/rowStylePicker.js +127 -109
  95. package/components/grid/config/rowStylePicker.js.map +1 -1
  96. package/components/grid/dataGrid.d.ts +218 -206
  97. package/components/grid/dataGrid.js +1629 -1538
  98. package/components/grid/dataGrid.js.map +1 -1
  99. package/components/grid/detail/detailHeaderPanel.d.ts +13 -13
  100. package/components/grid/detail/detailHeaderPanel.js +25 -25
  101. package/components/grid/detail/detailHeaderPanel.js.map +1 -1
  102. package/components/grid/export/contextMenu.d.ts +18 -24
  103. package/components/grid/export/contextMenu.js +116 -113
  104. package/components/grid/export/contextMenu.js.map +1 -1
  105. package/components/grid/export/progressPopup.d.ts +29 -29
  106. package/components/grid/export/progressPopup.js +93 -93
  107. package/components/grid/export/progressPopup.js.map +1 -1
  108. package/components/grid/export/worker/clipboardExport.d.ts +1 -1
  109. package/components/grid/export/worker/clipboardExport.js +8 -8
  110. package/components/grid/export/worker/csvExport.d.ts +1 -1
  111. package/components/grid/export/worker/csvExport.js +8 -8
  112. package/components/grid/export/worker/pdfExport.d.ts +1 -1
  113. package/components/grid/export/worker/pdfExport.js +81 -81
  114. package/components/grid/export/worker/pdfExport.js.map +1 -1
  115. package/components/grid/export/worker/txtExport.d.ts +1 -1
  116. package/components/grid/export/worker/txtExport.js +19 -19
  117. package/components/grid/extendedDataGrid.d.ts +140 -140
  118. package/components/grid/extendedDataGrid.js +704 -695
  119. package/components/grid/extendedDataGrid.js.map +1 -1
  120. package/components/grid/filter/customColumnFilter.d.ts +5 -21
  121. package/components/grid/filter/customColumnFilter.js +11 -82
  122. package/components/grid/filter/customColumnFilter.js.map +1 -1
  123. package/components/grid/filter/dataGridColumnFilter.d.ts +17 -0
  124. package/components/grid/filter/dataGridColumnFilter.js +49 -0
  125. package/components/grid/filter/dataGridColumnFilter.js.map +1 -0
  126. package/components/grid/filter/dateColumnFilter.d.ts +7 -11
  127. package/components/grid/filter/dateColumnFilter.js +22 -56
  128. package/components/grid/filter/dateColumnFilter.js.map +1 -1
  129. package/components/grid/filter/textColumnFilter.d.ts +8 -20
  130. package/components/grid/filter/textColumnFilter.js +24 -76
  131. package/components/grid/filter/textColumnFilter.js.map +1 -1
  132. package/components/grid/filter/wildcardQuickFilterEngine.d.ts +7 -0
  133. package/components/grid/filter/wildcardQuickFilterEngine.js +48 -0
  134. package/components/grid/filter/wildcardQuickFilterEngine.js.map +1 -0
  135. package/components/grid/header/simpleHeader.d.ts +17 -16
  136. package/components/grid/header/simpleHeader.js +230 -186
  137. package/components/grid/header/simpleHeader.js.map +1 -1
  138. package/components/grid/panel/dataGridPagination.d.ts +16 -16
  139. package/components/grid/panel/dataGridPagination.js +58 -58
  140. package/components/grid/panel/dataGridPagination.js.map +1 -1
  141. package/components/grid/panel/loadingOverlay.d.ts +6 -6
  142. package/components/grid/panel/loadingOverlay.js +10 -10
  143. package/components/grid/panel/loadingOverlay.js.map +1 -1
  144. package/components/grid/panel/noRecordsOverlay.d.ts +6 -6
  145. package/components/grid/panel/noRecordsOverlay.js +10 -10
  146. package/components/grid/panel/noRecordsOverlay.js.map +1 -1
  147. package/components/grid/panel/tablePagination.d.ts +10 -10
  148. package/components/grid/panel/tablePagination.js +45 -45
  149. package/components/grid/panel/tablePagination.js.map +1 -1
  150. package/components/icons/dropdownArrow.d.ts +8 -0
  151. package/components/icons/dropdownArrow.js +59 -0
  152. package/components/icons/dropdownArrow.js.map +1 -0
  153. package/components/icons/undoIcon.d.ts +8 -8
  154. package/components/icons/undoIcon.js +6 -6
  155. package/components/input/autoCompleteInput.d.ts +35 -35
  156. package/components/input/autoCompleteInput.js +122 -121
  157. package/components/input/autoCompleteInput.js.map +1 -1
  158. package/components/input/draftUtils.d.ts +4 -4
  159. package/components/input/draftUtils.js +48 -48
  160. package/components/input/draftUtils.js.map +1 -1
  161. package/components/input/draftail.d.ts +1 -1
  162. package/components/input/draftail.js +1 -1
  163. package/components/input/hexaFormattedInput.d.ts +16 -16
  164. package/components/input/hexaFormattedInput.js +54 -54
  165. package/components/input/hexaFormattedInput.js.map +1 -1
  166. package/components/input/mask/helpers.d.ts +28 -28
  167. package/components/input/mask/helpers.js +112 -112
  168. package/components/input/mask/helpers.js.map +1 -1
  169. package/components/input/mask/inputMaskCore.d.ts +46 -46
  170. package/components/input/mask/inputMaskCore.js +278 -278
  171. package/components/input/mask/inputMaskCore.js.map +1 -1
  172. package/components/input/mask/pattern.d.ts +20 -20
  173. package/components/input/mask/pattern.js +78 -78
  174. package/components/input/mask/pattern.js.map +1 -1
  175. package/components/input/maskedInput.d.ts +373 -351
  176. package/components/input/maskedInput.js +224 -224
  177. package/components/input/maskedInput.js.map +1 -1
  178. package/components/input/passwordInput.d.ts +9 -9
  179. package/components/input/passwordInput.js +55 -55
  180. package/components/input/passwordInput.js.map +1 -1
  181. package/components/input/simpleAutoComplete.d.ts +12 -12
  182. package/components/input/simpleAutoComplete.js +41 -43
  183. package/components/input/simpleAutoComplete.js.map +1 -1
  184. package/components/input/textarea/extractSpansOfClasses.d.ts +15 -15
  185. package/components/input/textarea/extractSpansOfClasses.js +96 -96
  186. package/components/input/textarea/extractSpansOfClasses.js.map +1 -1
  187. package/components/input/textarea/getRanges.d.ts +1 -1
  188. package/components/input/textarea/getRanges.js +73 -73
  189. package/components/input/textarea/getRanges.js.map +1 -1
  190. package/components/input/textarea/getType.d.ts +1 -1
  191. package/components/input/textarea/getType.js +26 -26
  192. package/components/input/textarea/getType.js.map +1 -1
  193. package/components/input/textarea/highlighedContents.d.ts +6 -6
  194. package/components/input/textarea/highlighedContents.js +10 -10
  195. package/components/input/textarea/mentionsWithHighlighting.d.ts +27 -27
  196. package/components/input/textarea/mentionsWithHighlighting.js +60 -60
  197. package/components/input/textarea/mentionsWithHighlighting.js.map +1 -1
  198. package/components/keyboard/keyboardUtils.d.ts +5 -5
  199. package/components/keyboard/keyboardUtils.js +32 -32
  200. package/components/modal/draggableModalProvider.d.ts +4 -4
  201. package/components/modal/draggableModalProvider.js +21 -21
  202. package/components/modal/draggableModalProvider.js.map +1 -1
  203. package/components/modal/impl/clamp.d.ts +1 -1
  204. package/components/modal/impl/clamp.js +1 -1
  205. package/components/modal/impl/clamp.js.map +1 -1
  206. package/components/modal/impl/draggableModal.d.ts +12 -12
  207. package/components/modal/impl/draggableModal.js +17 -17
  208. package/components/modal/impl/draggableModal.js.map +1 -1
  209. package/components/modal/impl/draggableModalContext.d.ts +9 -9
  210. package/components/modal/impl/draggableModalContext.js +2 -2
  211. package/components/modal/impl/draggableModalContext.js.map +1 -1
  212. package/components/modal/impl/draggableModalInner.d.ts +15 -13
  213. package/components/modal/impl/draggableModalInner.js +57 -55
  214. package/components/modal/impl/draggableModalInner.js.map +1 -1
  215. package/components/modal/impl/draggableModalReducer.d.ts +66 -62
  216. package/components/modal/impl/draggableModalReducer.js +77 -78
  217. package/components/modal/impl/draggableModalReducer.js.map +1 -1
  218. package/components/modal/impl/getWindowSize.d.ts +4 -4
  219. package/components/modal/impl/getWindowSize.js +4 -4
  220. package/components/modal/impl/getWindowSize.js.map +1 -1
  221. package/components/modal/impl/index.d.ts +3 -3
  222. package/components/modal/impl/index.js +3 -3
  223. package/components/modal/impl/index.js.map +1 -1
  224. package/components/modal/impl/resizeHandle.d.ts +3 -3
  225. package/components/modal/impl/resizeHandle.js +4 -4
  226. package/components/modal/impl/resizeHandle.js.map +1 -1
  227. package/components/modal/impl/useDrag.d.ts +5 -5
  228. package/components/modal/impl/useDrag.js +42 -42
  229. package/components/modal/impl/useDrag.js.map +1 -1
  230. package/components/modal/impl/usePrevious.d.ts +1 -1
  231. package/components/modal/impl/usePrevious.js +8 -8
  232. package/components/modal/impl/usePrevious.js.map +1 -1
  233. package/components/modal/impl/useResize.d.ts +7 -7
  234. package/components/modal/impl/useResize.js +46 -46
  235. package/components/modal/impl/useResize.js.map +1 -1
  236. package/components/modal/modalDialog.d.ts +49 -49
  237. package/components/modal/modalDialog.js +152 -152
  238. package/components/modal/modalDialog.js.map +1 -1
  239. package/components/picker/enumValuePicker.d.ts +16 -16
  240. package/components/picker/enumValuePicker.js +34 -34
  241. package/components/picker/enumValuePicker.js.map +1 -1
  242. package/components/platformSpecific.d.ts +10 -10
  243. package/components/platformSpecific.js +27 -27
  244. package/components/scrollTo/onlyText.d.ts +4 -4
  245. package/components/scrollTo/onlyText.js +30 -30
  246. package/components/scrollTo/onlyText.js.map +1 -1
  247. package/components/scrollTo/scrollTo.d.ts +41 -39
  248. package/components/scrollTo/scrollTo.js +264 -264
  249. package/components/scrollTo/scrollTo.js.map +1 -1
  250. package/components/style/withCss.d.ts +9 -0
  251. package/components/style/withCss.js +6 -0
  252. package/components/style/withCss.js.map +1 -0
  253. package/components/style/withInputNumberCss.d.ts +6 -0
  254. package/components/style/withInputNumberCss.js +13 -0
  255. package/components/style/withInputNumberCss.js.map +1 -0
  256. package/components/table/dragSortingTable.d.ts +13 -14
  257. package/components/table/dragSortingTable.js +96 -82
  258. package/components/table/dragSortingTable.js.map +1 -1
  259. package/components/text/impl/innerSize.d.ts +2 -2
  260. package/components/text/impl/innerSize.js +12 -12
  261. package/components/text/impl/series.d.ts +1 -1
  262. package/components/text/impl/series.js +28 -28
  263. package/components/text/impl/shallowEqual.d.ts +1 -1
  264. package/components/text/impl/shallowEqual.js +18 -18
  265. package/components/text/impl/shallowEqual.js.map +1 -1
  266. package/components/text/impl/uniqueId.d.ts +1 -1
  267. package/components/text/impl/uniqueId.js +4 -4
  268. package/components/text/impl/whilst.d.ts +1 -1
  269. package/components/text/impl/whilst.js +19 -19
  270. package/components/text/impl/whilst.js.map +1 -1
  271. package/components/text/textFit.d.ts +38 -38
  272. package/components/text/textFit.js +165 -168
  273. package/components/text/textFit.js.map +1 -1
  274. package/i18n/components.cs.json +101 -100
  275. package/i18n/components.sk.json +101 -100
  276. package/i18n/components.uk.json +101 -100
  277. package/i18n/componentsLocaleHolder.d.ts +3 -3
  278. package/i18n/componentsLocaleHolder.js +28 -28
  279. package/i18n/componentsLocaleHolder.js.map +1 -1
  280. package/package.json +71 -70
  281. package/style/index.less +274 -298
  282. package/style/modal/DraggableModal.css +43 -40
  283. package/style/modal/ResizeHandle.css +27 -19
  284. package/tsconfig.build.json +24 -24
  285. package/tsconfig.json +11 -11
  286. package/components/grid/cell/wildcardQuickFilter.d.ts +0 -11
  287. package/components/grid/cell/wildcardQuickFilter.js +0 -61
  288. package/components/grid/cell/wildcardQuickFilter.js.map +0 -1
  289. package/components/table/dataTable.d.ts +0 -17
  290. package/components/table/dataTable.js +0 -79
  291. package/components/table/dataTable.js.map +0 -1
  292. package/style/antd/antd-tree-showline.css +0 -25
  293. package/style/antd/full-height-tabs.scss +0 -63
  294. package/style/draftail/draftail-editor.css +0 -179
  295. package/style/table/dragSortingTable.css +0 -7
@@ -1,419 +1,447 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import React from "react";
13
- import MaskedInput from "../input/maskedInput";
14
- import padStart from 'lodash/padStart';
15
- import isEqual from 'lodash/isEqual';
16
- import debounce from 'lodash/debounce';
17
- import moment from "moment";
18
- import { CalendarOutlined } from "@ant-design/icons";
19
- import { Button, Calendar, Select, Tooltip } from "antd";
20
- import { Key } from "ts-key-enum";
21
- import { D2000UnixTimeNullValue } from "d2core/types/unixTimeUtils";
22
- const DATE_TIME_DATA_MAP = [
23
- { key: "SSS", min: 0, max: 999, unit: "ms" },
24
- { key: "ss", min: 0, max: 59, unit: "s" },
25
- { key: "mm", min: 0, max: 59, unit: "m" },
26
- { key: "HH", min: 0, max: 23, unit: "h" },
27
- { key: ["YYYY", "YY"], min: [1900, 0], max: [9999, 99], unit: "y" },
28
- { key: "MM", min: 1, max: 12, unit: "M" },
29
- { key: "DD", min: 1, max: 31, unit: "d" },
30
- ];
31
- const MIN_TIME = moment.unix(0);
32
- const MAX_TIME = moment().add(1000, "year");
33
- export function allowDatesBeforeEpoch() {
34
- DATE_TIME_DATA_MAP[4].min = 1902;
35
- }
36
- export default class DateTimeInput extends React.Component {
37
- constructor(props) {
38
- var _a, _b, _c, _d;
39
- super(props);
40
- this.inputRef = React.createRef();
41
- this.today = moment();
42
- this.state = {
43
- valid: (!!props.value && props.value.isValid()) || (!!props.allowClear && props.value === null),
44
- currentPos: null,
45
- currentInfo: {
46
- info: undefined,
47
- time: undefined,
48
- length: 0
49
- },
50
- popupCalendarVisible: false,
51
- calendarSelectedDate: (_d = (_b = (_a = props.defaultSelectedDate) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : (_c = props.value) === null || _c === void 0 ? void 0 : _c.clone()) !== null && _d !== void 0 ? _d : moment().startOf('day'),
52
- focused: false,
53
- };
54
- this.recalc = this.recalc.bind(this);
55
- this.increment = this.increment.bind(this);
56
- this.decrement = this.decrement.bind(this);
57
- this.onItemMouseOver = debounce(this.onItemMouseOver.bind(this), 100, { maxWait: 100 });
58
- }
59
- componentDidUpdate(prevProps, _prevState, _snapshot) {
60
- if (!isEqual(prevProps, this.props) && this.inputRef.current !== null) {
61
- this.inputRef.current.input.selectionStart = this.state.currentPos;
62
- this.inputRef.current.input.selectionEnd = this.state.currentPos;
63
- if (prevProps.value !== this.props.value) {
64
- this.setState({ valid: (!!this.props.value && this.props.value.isValid()) || (!!this.props.allowClear && this.props.value === null) });
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React from "react";
13
+ import MaskedInput from "../input/maskedInput";
14
+ import padStart from 'lodash/padStart';
15
+ import isEqual from 'lodash/isEqual';
16
+ import debounce from 'lodash/debounce';
17
+ import dayjs from "dayjs";
18
+ import { CalendarOutlined } from "@ant-design/icons";
19
+ import { Button, Calendar, Select, Tooltip } from "antd";
20
+ import { Key } from "ts-key-enum";
21
+ import { D2000UnixTimeNullValue } from "d2core/types/unixTimeUtils";
22
+ import { createStyles } from "antd-style";
23
+ import WithCss from "d2coreui/components/style/withCss";
24
+ const useStyles = createStyles(({ token, css, cx }) => {
25
+ return {
26
+ dateTimeInputCalendar: css `
27
+ // adaptations of date-picker calendar styles
28
+ .ant-picker-cell-in-view.ant-picker-cell-selected .ant-picker-cell-inner:not(.date-picker-item-marked) {
29
+ color: inherit;
30
+ background: inherit;
65
31
  }
66
- }
67
- }
68
- get input() {
69
- var _a;
70
- return (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.input;
71
- }
72
- focus() {
73
- var _a;
74
- (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
75
- }
76
- recalc() {
77
- if (this.inputRef.current !== null) {
78
- this.setState({
79
- currentInfo: DateTimeInput.parseDateTimeFormat(this.props.value, this.inputRef.current.input.value, this.props.mask, this.inputRef.current.input.selectionStart),
80
- currentPos: this.inputRef.current.input.selectionStart,
81
- });
82
- }
83
- }
84
- increment() {
85
- var _a;
86
- if (this.state.currentInfo.info !== undefined && !!this.props.value && DateTimeInput.isValid(this.state.currentInfo, this.props.value, 1)) {
87
- const unit = this.state.currentInfo.info.unit;
88
- this.incrementDate(unit);
89
- }
90
- (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
91
- }
92
- incrementDate(unit) {
93
- var _a, _b, _c, _d, _e;
94
- if (!!this.props.value) {
95
- this.props.value.add(1, unit);
96
- if (!!this.props.maxDateTime && this.props.value.isAfter(this.props.maxDateTime)) {
97
- (_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, (_c = this.props.maxDateTime) === null || _c === void 0 ? void 0 : _c.clone());
32
+
33
+ .ant-picker-panel:focus > .ant-picker-date-panel .ant-picker-cell-in-view.ant-picker-cell-selected .ant-picker-cell-inner:before {
34
+ position: absolute;
35
+ top: 0;
36
+ right: 0;
37
+ bottom: 0;
38
+ left: 0;
39
+ z-index: 1;
40
+ border: 1px solid #096dd9;
41
+ border-radius: 2px;
42
+ content: '';
98
43
  }
99
- else {
100
- (_e = (_d = this.props).onChange) === null || _e === void 0 ? void 0 : _e.call(_d, this.props.value.clone());
44
+
45
+ .ant-picker-content thead {
46
+ user-select: none;
101
47
  }
102
- }
103
- }
104
- decrement() {
105
- var _a;
106
- if (this.state.currentInfo.info !== undefined && !!this.props.value && DateTimeInput.isValid(this.state.currentInfo, this.props.value, -1)) {
107
- const unit = this.state.currentInfo.info.unit;
108
- this.decrementDate(unit);
109
- }
110
- (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
111
- }
112
- decrementDate(unit) {
113
- var _a, _b, _c, _d, _e;
114
- if (!!this.props.value) {
115
- this.props.value.subtract(1, unit);
116
- if (!!this.props.minDateTime && this.props.value.isBefore(this.props.minDateTime)) {
117
- (_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, (_c = this.props.minDateTime) === null || _c === void 0 ? void 0 : _c.clone());
48
+
49
+ .date-picker-item-marked {
50
+ color: #fff;
51
+ background: #1890ff;
118
52
  }
119
- else {
120
- (_e = (_d = this.props).onChange) === null || _e === void 0 ? void 0 : _e.call(_d, this.props.value.clone());
53
+
54
+ .ant-picker-cell-in-view.ant-picker-cell-today .ant-picker-cell-inner::before {
55
+ border: 1px solid #13c2c2;
121
56
  }
122
- }
123
- }
124
- onItemMouseOver(itemDate) {
125
- var _a, _b;
126
- (_b = (_a = this.props).onDateItemMouseOver) === null || _b === void 0 ? void 0 : _b.call(_a, itemDate);
127
- }
128
- renderCalendarNavigation(value) {
129
- const start = 0;
130
- const end = 12;
131
- const monthOptions = [];
132
- const current = value.clone();
133
- const localeData = value.localeData();
134
- const months = [];
135
- for (let i = 0; i < 12; i++) {
136
- current.month(i);
137
- months.push(localeData.months(current));
138
- }
139
- for (let index = start; index < end; index++) {
140
- monthOptions.push(React.createElement(Select.Option, { className: "month-item", key: `${index}`, value: `${index}` }, months[index]));
141
- }
142
- const month = value.month();
143
- const year = value.year();
144
- const options = [];
145
- for (let i = year - 4; i <= year + 2; i += 1) {
146
- options.push(React.createElement(Select.Option, { key: i, value: i, className: "year-item" }, i));
147
- }
148
- return (React.createElement("div", { style: { paddingBottom: 8 } },
149
- React.createElement("div", { style: { float: "left", paddingBottom: 8, width: 140, display: "flex" } },
150
- React.createElement(Button, { style: { width: 10, padding: 0 }, size: "small", type: "text", tabIndex: -1, disabled: !DateTimeInput.checkDateValueValidity(this.state.calendarSelectedDate, -1, "month"), onClick: () => {
151
- this.state.calendarSelectedDate.subtract(1, "month");
152
- this.setState({ calendarSelectedDate: this.state.calendarSelectedDate });
153
- }, className: "ant-picker-header-prev-btn" },
154
- React.createElement("span", { className: "ant-picker-prev-icon" })),
155
- React.createElement(Select, { style: { flex: "1 1 auto" }, size: "small", dropdownMatchSelectWidth: false, dropdownStyle: { zIndex: 2070 }, getPopupContainer: this.props.getPopupContainer, value: String(month), onChange: selectedMonth => {
156
- const newValue = this.state.calendarSelectedDate.clone();
157
- newValue.month(parseInt(selectedMonth, 10));
158
- this.setState({ calendarSelectedDate: newValue });
159
- } }, monthOptions),
160
- React.createElement(Button, { style: { width: 10, padding: 0 }, size: "small", type: "text", tabIndex: -1, className: "ant-picker-header-next-btn", onClick: () => {
161
- this.state.calendarSelectedDate.add(1, "month");
162
- this.setState({ calendarSelectedDate: this.state.calendarSelectedDate });
163
- } },
164
- React.createElement("span", { className: "ant-picker-next-icon" }))),
165
- React.createElement("div", { style: { float: "right", paddingBottom: 8, width: 110 } },
166
- React.createElement(Button, { style: { width: 12, padding: 0 }, size: "small", type: "text", tabIndex: -1, className: "ant-picker-header-prev-btn", onClick: () => {
167
- this.state.calendarSelectedDate.subtract(1, "year");
168
- this.setState({ calendarSelectedDate: this.state.calendarSelectedDate });
169
- } },
170
- React.createElement("span", { className: "ant-picker-prev-icon" })),
171
- React.createElement(Select, { size: "small", style: { width: 84 }, dropdownMatchSelectWidth: false, dropdownStyle: { zIndex: 2070 }, getPopupContainer: this.props.getPopupContainer, onChange: newYear => {
172
- const newValue = this.state.calendarSelectedDate.clone().year(parseInt(newYear, 10));
173
- this.setState({ calendarSelectedDate: newValue });
174
- }, value: String(year) }, options),
175
- React.createElement(Button, { style: { width: 12, padding: 0 }, size: "small", type: "text", tabIndex: -1, className: "ant-picker-header-next-btn", onClick: () => {
176
- this.state.calendarSelectedDate.add(1, "year");
177
- this.setState({ calendarSelectedDate: this.state.calendarSelectedDate });
178
- } },
179
- React.createElement("span", { className: "ant-picker-next-icon" })))));
180
- }
181
- renderCalendar() {
182
- var _a, _b;
183
- return (React.createElement("div", { onKeyDown: !this.props.ignoreKeyStrokes ? (e) => {
184
- var _a, _b, _c, _d;
185
- if (e.key === Key.Enter) {
186
- var tagName = (_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase();
187
- if (tagName !== "input") {
188
- (_d = (_c = this.props).onChange) === null || _d === void 0 ? void 0 : _d.call(_c, this.state.calendarSelectedDate);
189
- }
190
- }
191
- } : undefined, onMouseOver: (e) => {
192
- if (e.target instanceof HTMLTableCellElement) {
193
- const date = moment(e.target.title, "YYYY-MM-DD");
194
- this.onItemMouseOver(date);
195
- }
196
- } },
197
- React.createElement(Calendar, { fullscreen: false, style: this.props.renderAsCalendar ? this.props.style : undefined, dateFullCellRender: ((date) => {
198
- let className = date.isSame(this.today, "date") ? 'ant-picker-cell-inner ant-picker-calendar-date ant-picker-calendar-date-today' : 'ant-picker-cell-inner ant-picker-calendar-date';
199
- const markedDateInterval = this.props.markedDateInterval;
200
- if (markedDateInterval && (markedDateInterval[0].isBefore(date) || markedDateInterval[0].isSame(date, "millisecond")) &&
201
- (markedDateInterval[1].isAfter(date) || markedDateInterval[1].isSame(date, "millisecond"))) {
202
- className += " date-picker-item-marked";
203
- }
204
- else if (date.isSame(this.props.value, "date")) {
205
- className += " date-picker-item-marked";
206
- }
207
- return (React.createElement("div", { className: className, style: { userSelect: "none" }, onKeyDown: (e) => {
208
- var _a, _b, _c, _d;
209
- if (e.key === Key.Enter) {
210
- let newValue = (_b = (_a = this.props.value) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : moment().startOf("day");
211
- newValue = newValue.year(date.year()).month(date.month()).date(date.date());
212
- (_d = (_c = this.props).onChange) === null || _d === void 0 ? void 0 : _d.call(_c, date);
213
- }
214
- }, onMouseDown: () => {
215
- var _a, _b, _c, _d;
216
- let newValue = (_b = (_a = this.props.value) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : moment().startOf("day");
217
- newValue = newValue.year(date.year()).month(date.month()).date(date.date());
218
- (_d = (_c = this.props).onDateItemMouseDown) === null || _d === void 0 ? void 0 : _d.call(_c, newValue);
219
- }, onMouseUp: () => {
220
- var _a, _b, _c, _d;
221
- let newValue = (_b = (_a = this.props.value) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : moment().startOf("day");
222
- newValue = newValue.year(date.year()).month(date.month()).date(date.date());
223
- (_d = (_c = this.props).onDateItemMouseUp) === null || _d === void 0 ? void 0 : _d.call(_c, newValue);
224
- } },
225
- React.createElement("div", { className: `ant-picker-calendar-date-value` }, padStart("" + date.date(), 2, '0')),
226
- React.createElement("div", { className: `ant-picker-calendar-date-content` })));
227
- }), headerRender: ({ value }) => {
228
- return this.renderCalendarNavigation(value);
229
- }, value: this.state.calendarSelectedDate, validRange: [(_a = this.props.minDateTime) !== null && _a !== void 0 ? _a : MIN_TIME, (_b = this.props.maxDateTime) !== null && _b !== void 0 ? _b : MAX_TIME], onSelect: (value) => {
230
- var _a, _b, _c, _d;
231
- if (window.event instanceof MouseEvent) {
232
- let newValue = (_b = (_a = this.props.value) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : moment().startOf("day");
233
- newValue = newValue.year(value.year()).month(value.month()).date(value.date());
234
- (_d = (_c = this.props).onChange) === null || _d === void 0 ? void 0 : _d.call(_c, newValue);
235
- }
236
- this.setState({ calendarSelectedDate: value, popupCalendarVisible: false });
237
- } })));
238
- }
239
- renderInput() {
240
- var _a;
241
- const _b = this.props, { mask, value, onChange, onInvalidValue, style, disabled, inputDisabled, bordered, hidePopup, renderAsCalendar, allowClear, minDateTime, maxDateTime, onDateItemMouseDown, onDateItemMouseOver, onDateItemMouseUp, markedDateInterval, inputStyle, getPopupContainer, autoFocus, className } = _b, props = __rest(_b, ["mask", "value", "onChange", "onInvalidValue", "style", "disabled", "inputDisabled", "bordered", "hidePopup", "renderAsCalendar", "allowClear", "minDateTime", "maxDateTime", "onDateItemMouseDown", "onDateItemMouseOver", "onDateItemMouseUp", "markedDateInterval", "inputStyle", "getPopupContainer", "autoFocus", "className"]);
242
- const isUpDisabled = disabled || this.state.currentInfo.info === undefined || !DateTimeInput.isValid(this.state.currentInfo, this.props.value, 1);
243
- const isDownDisabled = disabled || this.state.currentInfo.info === undefined || !DateTimeInput.isValid(this.state.currentInfo, this.props.value, -1);
244
- const unix = value === null || value === void 0 ? void 0 : value.valueOf();
245
- let divClassName = "custom-date-time-picker";
246
- if (disabled || inputDisabled) {
247
- divClassName += " ant-input-number disabled ant-input-disabled readonly";
248
- }
249
- else {
250
- divClassName += " ant-input-number";
251
- }
252
- if (bordered === false) {
253
- divClassName += " ant-input-borderless";
254
- }
255
- const maskedInputStyle = { color: this.state.valid ? "inherit" : "red", border: "none" };
256
- if (inputStyle) {
257
- Object.assign(maskedInputStyle, inputStyle);
258
- }
259
- return (React.createElement("div", Object.assign({ style: bordered === false ? Object.assign(Object.assign({}, style), { border: 0 }) : style }, props, { className: (className ? className + " " : "") + divClassName }),
260
- React.createElement("div", { className: "ant-input-number-input-wrap", onKeyDown: (event) => {
261
- if (event.keyCode === 38) {
262
- this.increment();
263
- event.preventDefault();
264
- event.stopPropagation();
265
- }
266
- else if (event.keyCode === 40) {
267
- this.decrement();
268
- event.preventDefault();
269
- event.stopPropagation();
270
- }
271
- } },
272
- React.createElement(MaskedInput, { mask: this.props.mask.replace(/[a-zA-Z]/g, '1'), bordered: bordered, ref: this.inputRef, style: maskedInputStyle, value: (this.state.focused || unix !== D2000UnixTimeNullValue * 1000) ? ((_a = value === null || value === void 0 ? void 0 : value.locale("locale.d2000").format(this.props.mask)) !== null && _a !== void 0 ? _a : "") : "", placeholder: (!this.state.focused && unix === D2000UnixTimeNullValue * 1000) ? "Null Time" : undefined, onFocus: (event => {
273
- event.target.selectionStart = event.target.selectionEnd = this.state.currentPos;
274
- this.setState({ focused: true });
275
- }), onBlur: () => {
276
- this.setState({ focused: false });
277
- }, autoFocus: autoFocus, disabled: disabled || inputDisabled, onWheel: (event) => {
278
- if (event.deltaY > 0) {
279
- if (!isDownDisabled) {
280
- this.decrement();
281
- }
282
- }
283
- if (event.deltaY < 0) {
284
- if (!isUpDisabled) {
285
- this.increment();
286
- }
287
- }
288
- }, onMouseUp: this.recalc, onKeyUp: this.recalc, onChange: (event) => {
289
- const inputString = event.target.value;
290
- const value = DateTimeInput.parseDateTimeFormat(this.props.value, inputString, this.props.mask, event.target.selectionStart);
291
- if (value.time !== undefined) {
292
- if (this.props.minDateTime !== undefined && value.time.isBefore(this.props.minDateTime)) {
293
- value.time = this.props.minDateTime.clone();
294
- }
295
- if (this.props.maxDateTime !== undefined && value.time.isAfter(this.props.maxDateTime)) {
296
- value.time = this.props.maxDateTime.clone();
297
- }
298
- onChange === null || onChange === void 0 ? void 0 : onChange(value.time.clone());
299
- }
300
- else if (!!this.props.allowClear && !inputString) {
301
- onChange === null || onChange === void 0 ? void 0 : onChange(null);
302
- }
303
- else {
304
- onInvalidValue === null || onInvalidValue === void 0 ? void 0 : onInvalidValue(inputString);
305
- }
306
- this.setState({
307
- valid: (value.time !== undefined && value.time.isValid()) || (!!this.props.allowClear && !inputString),
308
- currentInfo: value
309
- });
310
- } })),
311
- !hidePopup && !renderAsCalendar && React.createElement("div", { className: "ant-input-number-handler-wrap", style: {
312
- width: 28,
313
- opacity: 1,
314
- height: "100%",
315
- textAlign: "center",
316
- cursor: "pointer",
317
- background: "transparent",
318
- border: bordered === false ? 0 : undefined
319
- }, onClick: (event) => {
320
- if (document.createEvent) {
321
- var ev = document.createEvent('HTMLEvents');
322
- ev.initEvent('contextmenu', true, false);
323
- event.target.dispatchEvent(ev);
324
- }
325
- } },
326
- React.createElement(CalendarOutlined, { style: { color: "rgba(0,0,0,0.65)", verticalAlign: "middle", marginTop: 2 } }))));
327
- }
328
- render() {
329
- if (this.props.renderAsCalendar) {
330
- return this.renderCalendar();
331
- }
332
- else if (this.props.hidePopup) {
333
- return this.renderInput();
334
- }
335
- else {
336
- return (React.createElement(Tooltip, { color: "white", trigger: this.props.disabled ? [] : ["contextMenu"], getPopupContainer: this.props.getPopupContainer, overlayInnerStyle: { maxHeight: "100vh", overflowY: "auto", overflowX: "hidden", width: 266 }, open: this.state.popupCalendarVisible, onOpenChange: (visible) => {
337
- var _a, _b, _c, _d;
338
- this.setState({ popupCalendarVisible: visible });
339
- if (visible) {
340
- this.setState({ calendarSelectedDate: (_d = (_b = (_a = this.props.defaultSelectedDate) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : (_c = this.props.value) === null || _c === void 0 ? void 0 : _c.clone()) !== null && _d !== void 0 ? _d : moment().startOf("day") });
341
- }
342
- }, title: this.renderCalendar(), placement: this.props.placement }, this.renderInput()));
343
- }
344
- }
345
- static isValid(info, value, offset) {
346
- var _a;
347
- const unit = (_a = info.info) === null || _a === void 0 ? void 0 : _a.unit;
348
- return this.checkDateValueValidity(value, offset, unit);
349
- }
350
- static checkDateValueValidity(value, offset, unit) {
351
- if (value === null) {
352
- return false;
353
- }
354
- let v = value.clone().add(offset, unit);
355
- return v.isValid() && v.isSameOrAfter(moment(0));
356
- }
357
- static parseDateTimeFormat(previousTime, value, mask, cursorPos) {
358
- var _a, _b, _c;
359
- let result = {
360
- time: moment(0).startOf("day"),
361
- info: undefined,
362
- length: 0,
363
- };
364
- for (let v of DATE_TIME_DATA_MAP) {
365
- let index = -1;
366
- let length = 0;
367
- let min = 0;
368
- let max = 0;
369
- if (Array.isArray(v.key) || Array.isArray(v.min) || Array.isArray(v.max)) {
370
- for (let i = 0; i < v.key.length; i++) {
371
- const x = v.key[i];
372
- index = mask.indexOf(x);
373
- if (index !== -1) {
374
- length = x.length;
375
- min = v.min[i];
376
- max = v.max[i];
377
- break;
378
- }
379
- }
57
+
58
+ .ant-picker-cell:hover:not(.ant-picker-cell-in-view) .ant-picker-cell-inner, .ant-picker-cell:hover:not(.ant-picker-cell-selected):not(.ant-picker-cell-range-start):not(.ant-picker-cell-range-end):not(.ant-picker-cell-range-hover-start):not(.ant-picker-cell-range-hover-end) .ant-picker-cell-inner {
59
+ background: #1890ff;
60
+ color: rgba(0, 0, 0, 0.85);
380
61
  }
381
- else {
382
- index = mask.indexOf(v.key);
383
- length = v.key.length;
384
- min = v.min;
385
- max = v.max;
386
- }
387
- if (index !== -1) {
388
- let val = Number(value.substring(index, index + length));
389
- if (!isNaN(val) && val >= min && val <= max) {
390
- if (v.unit === "M") {
391
- val--;
392
- }
393
- if (v.unit === "d") {
394
- (_a = result.time) === null || _a === void 0 ? void 0 : _a.set('D', val);
395
- }
396
- else if (v.unit === "y" && length === 2) {
397
- const century = (previousTime != null && previousTime.isValid()) ? Math.floor(previousTime.year() / 100) * 100 : (val > 70 ? 1900 : 2000);
398
- (_b = result.time) === null || _b === void 0 ? void 0 : _b.set(v.unit, century + val);
399
- }
400
- else {
401
- (_c = result.time) === null || _c === void 0 ? void 0 : _c.set(v.unit, val);
402
- }
403
- }
404
- else {
405
- result.time = undefined;
406
- result.info = undefined;
407
- result.length = 0;
408
- break;
409
- }
410
- if (cursorPos !== null && cursorPos >= index && cursorPos <= index + length) {
411
- result.info = v;
412
- result.length = length;
413
- }
414
- }
415
- }
416
- return result;
417
- }
418
- }
62
+ `,
63
+ };
64
+ });
65
+ const DATE_TIME_DATA_MAP = [
66
+ { key: "SSS", min: 0, max: 999, unit: "ms" },
67
+ { key: "ss", min: 0, max: 59, unit: "s" },
68
+ { key: "mm", min: 0, max: 59, unit: "m" },
69
+ { key: "HH", min: 0, max: 23, unit: "h" },
70
+ { key: ["YYYY", "YY"], min: [1900, 0], max: [9999, 99], unit: "y" },
71
+ { key: "MM", min: 1, max: 12, unit: "M" },
72
+ { key: "DD", min: 1, max: 31, unit: "d" },
73
+ ];
74
+ const MIN_TIME = dayjs.unix(0);
75
+ const MAX_TIME = dayjs().add(1000, "year");
76
+ export function allowDatesBeforeEpoch() {
77
+ DATE_TIME_DATA_MAP[4].min = 1902;
78
+ }
79
+ export default class DateTimeInput extends React.Component {
80
+ constructor(props) {
81
+ var _a, _b, _c, _d;
82
+ super(props);
83
+ this.inputRef = React.createRef();
84
+ this.today = dayjs();
85
+ this.state = {
86
+ valid: DateTimeInput.isValidValue(props.value, props.minDateTime, props.maxDateTime, props.allowClear),
87
+ currentPos: null,
88
+ currentInfo: {
89
+ info: undefined,
90
+ time: undefined,
91
+ length: 0
92
+ },
93
+ popupCalendarVisible: false,
94
+ calendarSelectedDate: (_d = (_b = (_a = props.defaultSelectedDate) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : (_c = props.value) === null || _c === void 0 ? void 0 : _c.clone()) !== null && _d !== void 0 ? _d : dayjs().startOf('day'),
95
+ focused: false,
96
+ };
97
+ this.recalc = this.recalc.bind(this);
98
+ this.increment = this.increment.bind(this);
99
+ this.decrement = this.decrement.bind(this);
100
+ this.onItemMouseOver = debounce(this.onItemMouseOver.bind(this), 100, { maxWait: 100 });
101
+ }
102
+ componentDidUpdate(prevProps, _prevState, _snapshot) {
103
+ if (!isEqual(prevProps, this.props) && this.inputRef.current !== null) {
104
+ this.inputRef.current.input.selectionStart = this.state.currentPos;
105
+ this.inputRef.current.input.selectionEnd = this.state.currentPos;
106
+ if (prevProps.value !== this.props.value) {
107
+ this.setState({ valid: DateTimeInput.isValidValue(this.props.value, this.props.minDateTime, this.props.maxDateTime, this.props.allowClear) });
108
+ }
109
+ }
110
+ }
111
+ get input() {
112
+ var _a;
113
+ return (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.input;
114
+ }
115
+ focus() {
116
+ var _a;
117
+ (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
118
+ }
119
+ recalc() {
120
+ if (this.inputRef.current !== null) {
121
+ this.setState({
122
+ currentInfo: DateTimeInput.parseDateTimeFormat(this.props.value, this.inputRef.current.input.value, this.props.mask, this.inputRef.current.input.selectionStart),
123
+ currentPos: this.inputRef.current.input.selectionStart,
124
+ });
125
+ }
126
+ }
127
+ increment() {
128
+ var _a;
129
+ if (this.state.currentInfo.info !== undefined && !!this.props.value && DateTimeInput.isValid(this.state.currentInfo, this.props.value, 1)) {
130
+ const unit = this.state.currentInfo.info.unit;
131
+ this.incrementDate(unit);
132
+ }
133
+ (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
134
+ }
135
+ incrementDate(unit) {
136
+ var _a, _b, _c, _d, _e;
137
+ if (!!this.props.value) {
138
+ const value = this.props.value.clone().add(1, unit);
139
+ if (!!this.props.maxDateTime && value.isAfter(this.props.maxDateTime)) {
140
+ (_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, (_c = this.props.maxDateTime) === null || _c === void 0 ? void 0 : _c.clone());
141
+ }
142
+ else {
143
+ (_e = (_d = this.props).onChange) === null || _e === void 0 ? void 0 : _e.call(_d, value);
144
+ }
145
+ }
146
+ }
147
+ decrement() {
148
+ var _a;
149
+ if (this.state.currentInfo.info !== undefined && !!this.props.value && DateTimeInput.isValid(this.state.currentInfo, this.props.value, -1)) {
150
+ const unit = this.state.currentInfo.info.unit;
151
+ this.decrementDate(unit);
152
+ }
153
+ (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
154
+ }
155
+ decrementDate(unit) {
156
+ var _a, _b, _c, _d, _e;
157
+ if (!!this.props.value) {
158
+ const value = this.props.value.clone().subtract(1, unit);
159
+ if (!!this.props.minDateTime && value.isBefore(this.props.minDateTime)) {
160
+ (_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, (_c = this.props.minDateTime) === null || _c === void 0 ? void 0 : _c.clone());
161
+ }
162
+ else {
163
+ (_e = (_d = this.props).onChange) === null || _e === void 0 ? void 0 : _e.call(_d, value);
164
+ }
165
+ }
166
+ }
167
+ onItemMouseOver(itemDate) {
168
+ var _a, _b;
169
+ (_b = (_a = this.props).onDateItemMouseOver) === null || _b === void 0 ? void 0 : _b.call(_a, itemDate);
170
+ }
171
+ renderCalendarNavigation(value) {
172
+ const start = 0;
173
+ const end = 12;
174
+ const monthOptions = [];
175
+ const current = value.clone();
176
+ const localeData = value.localeData();
177
+ const months = [];
178
+ for (let i = 0; i < 12; i++) {
179
+ months.push(localeData.months(current.month(i)));
180
+ }
181
+ for (let index = start; index < end; index++) {
182
+ monthOptions.push(React.createElement(Select.Option, { key: `${index}`, value: `${index}` }, months[index]));
183
+ }
184
+ const month = value.month();
185
+ const year = value.year();
186
+ const options = [];
187
+ for (let i = year - 4; i <= year + 2; i += 1) {
188
+ options.push(React.createElement(Select.Option, { key: `${i}`, value: `${i}` }, i));
189
+ }
190
+ const calendarSelectedDate = this.state.calendarSelectedDate;
191
+ return (React.createElement("div", { style: { display: "flex", marginBottom: 6 } },
192
+ React.createElement("div", { style: { display: "flex", width: 140 } },
193
+ React.createElement(Button, { style: { width: 10, padding: 0 }, size: "small", type: "text", tabIndex: -1, disabled: !DateTimeInput.checkDateValueValidity(calendarSelectedDate, -1, "month"), onClick: () => {
194
+ this.setState({ calendarSelectedDate: calendarSelectedDate.subtract(1, "month") });
195
+ }, className: "ant-picker-header-prev-btn" },
196
+ React.createElement("span", { className: "ant-picker-prev-icon" })),
197
+ React.createElement(Select, { style: { flex: "1 1 auto" }, size: "small", popupMatchSelectWidth: false, dropdownStyle: { zIndex: 2070 }, getPopupContainer: this.props.getPopupContainer, value: String(month), onChange: selectedMonth => {
198
+ this.setState({ calendarSelectedDate: calendarSelectedDate.month(parseInt(selectedMonth, 10)) });
199
+ } }, monthOptions),
200
+ React.createElement(Button, { style: { width: 10, padding: 0 }, size: "small", type: "text", tabIndex: -1, className: "ant-picker-header-next-btn", onClick: () => {
201
+ this.setState({ calendarSelectedDate: calendarSelectedDate.add(1, "month") });
202
+ } },
203
+ React.createElement("span", { className: "ant-picker-next-icon" }))),
204
+ React.createElement("div", { style: { display: "flex", width: 110 } },
205
+ React.createElement(Button, { style: { width: 12, padding: 0 }, size: "small", type: "text", tabIndex: -1, className: "ant-picker-header-prev-btn", onClick: () => {
206
+ this.setState({ calendarSelectedDate: calendarSelectedDate.subtract(1, "year") });
207
+ } },
208
+ React.createElement("span", { className: "ant-picker-prev-icon" })),
209
+ React.createElement(Select, { size: "small", style: { width: 84 }, popupMatchSelectWidth: false, dropdownStyle: { zIndex: 2070 }, getPopupContainer: this.props.getPopupContainer, onChange: newYear => {
210
+ this.setState({ calendarSelectedDate: calendarSelectedDate.year(parseInt(newYear, 10)) });
211
+ }, value: String(year) }, options),
212
+ React.createElement(Button, { style: { width: 12, padding: 0 }, size: "small", type: "text", tabIndex: -1, className: "ant-picker-header-next-btn", onClick: () => {
213
+ this.setState({ calendarSelectedDate: calendarSelectedDate.add(1, "year") });
214
+ } },
215
+ React.createElement("span", { className: "ant-picker-next-icon" })))));
216
+ }
217
+ renderCalendar() {
218
+ return (React.createElement("div", { onKeyDown: !this.props.ignoreKeyStrokes ? (e) => {
219
+ var _a, _b, _c, _d;
220
+ if (e.key === Key.Enter) {
221
+ var tagName = (_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase();
222
+ if (tagName !== "input") {
223
+ (_d = (_c = this.props).onChange) === null || _d === void 0 ? void 0 : _d.call(_c, this.state.calendarSelectedDate);
224
+ }
225
+ }
226
+ } : undefined, onMouseOver: (e) => {
227
+ if (e.target instanceof HTMLTableCellElement) {
228
+ const date = dayjs(e.target.title, "YYYY-MM-DD");
229
+ this.onItemMouseOver(date);
230
+ }
231
+ } },
232
+ React.createElement(WithCss, { useStyles: useStyles }, (css) => {
233
+ var _a, _b;
234
+ return React.createElement(Calendar, { className: css.styles.dateTimeInputCalendar, fullscreen: false, style: this.props.renderAsCalendar ? this.props.style : undefined, fullCellRender: ((date) => {
235
+ let className = date.isSame(this.today, "date") ? 'ant-picker-cell-inner ant-picker-calendar-date ant-picker-calendar-date-today' : 'ant-picker-cell-inner ant-picker-calendar-date';
236
+ const markedDateInterval = this.props.markedDateInterval;
237
+ if (markedDateInterval && (markedDateInterval[0].isBefore(date) || markedDateInterval[0].isSame(date, "millisecond")) &&
238
+ (markedDateInterval[1].isAfter(date) || markedDateInterval[1].isSame(date, "millisecond"))) {
239
+ className += " date-picker-item-marked";
240
+ }
241
+ else if (date.isSame(this.props.value, "date")) {
242
+ className += " date-picker-item-marked";
243
+ }
244
+ return (React.createElement("div", { className: className, style: { userSelect: "none" }, onKeyDown: (e) => {
245
+ var _a, _b, _c, _d;
246
+ if (e.key === Key.Enter) {
247
+ let newValue = (_b = (_a = this.props.value) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : dayjs().startOf("day");
248
+ newValue = newValue.year(date.year()).month(date.month()).date(date.date());
249
+ (_d = (_c = this.props).onChange) === null || _d === void 0 ? void 0 : _d.call(_c, newValue);
250
+ }
251
+ }, onMouseDown: () => {
252
+ var _a, _b, _c, _d;
253
+ let newValue = (_b = (_a = this.props.value) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : dayjs().startOf("day");
254
+ newValue = newValue.year(date.year()).month(date.month()).date(date.date());
255
+ (_d = (_c = this.props).onDateItemMouseDown) === null || _d === void 0 ? void 0 : _d.call(_c, newValue);
256
+ }, onMouseUp: () => {
257
+ var _a, _b, _c, _d;
258
+ let newValue = (_b = (_a = this.props.value) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : dayjs().startOf("day");
259
+ newValue = newValue.year(date.year()).month(date.month()).date(date.date());
260
+ (_d = (_c = this.props).onDateItemMouseUp) === null || _d === void 0 ? void 0 : _d.call(_c, newValue);
261
+ } },
262
+ React.createElement("div", { className: `ant-picker-calendar-date-value` }, padStart("" + date.date(), 2, '0')),
263
+ React.createElement("div", { className: `ant-picker-calendar-date-content` })));
264
+ }), headerRender: ({ value }) => {
265
+ return this.renderCalendarNavigation(value);
266
+ }, value: this.state.calendarSelectedDate, validRange: [(_a = this.props.minDateTime) !== null && _a !== void 0 ? _a : MIN_TIME, (_b = this.props.maxDateTime) !== null && _b !== void 0 ? _b : MAX_TIME], onSelect: (value) => {
267
+ var _a, _b, _c, _d;
268
+ if (window.event instanceof MouseEvent) {
269
+ let newValue = (_b = (_a = this.props.value) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : dayjs().startOf("day");
270
+ newValue = newValue.year(value.year()).month(value.month()).date(value.date());
271
+ (_d = (_c = this.props).onChange) === null || _d === void 0 ? void 0 : _d.call(_c, newValue);
272
+ }
273
+ this.setState({ calendarSelectedDate: value, popupCalendarVisible: false });
274
+ } });
275
+ })));
276
+ }
277
+ renderInput() {
278
+ var _a;
279
+ const _b = this.props, { mask, value, onChange, onInvalidValue, style, disabled, inputDisabled, bordered, hidePopup, renderAsCalendar, allowClear, minDateTime, maxDateTime, onDateItemMouseDown, onDateItemMouseOver, onDateItemMouseUp, markedDateInterval, inputStyle, getPopupContainer, autoFocus, className, size } = _b, props = __rest(_b, ["mask", "value", "onChange", "onInvalidValue", "style", "disabled", "inputDisabled", "bordered", "hidePopup", "renderAsCalendar", "allowClear", "minDateTime", "maxDateTime", "onDateItemMouseDown", "onDateItemMouseOver", "onDateItemMouseUp", "markedDateInterval", "inputStyle", "getPopupContainer", "autoFocus", "className", "size"]);
280
+ const isUpDisabled = disabled || this.state.currentInfo.info === undefined || !DateTimeInput.isValid(this.state.currentInfo, this.props.value, 1);
281
+ const isDownDisabled = disabled || this.state.currentInfo.info === undefined || !DateTimeInput.isValid(this.state.currentInfo, this.props.value, -1);
282
+ const unix = value === null || value === void 0 ? void 0 : value.valueOf();
283
+ const maskedInputStyle = { color: this.state.valid ? undefined : "#ff4d4f" };
284
+ if (inputStyle) {
285
+ Object.assign(maskedInputStyle, inputStyle);
286
+ }
287
+ return (React.createElement("div", Object.assign({ style: Object.assign(Object.assign({}, style), { position: "relative" }) }, props, { className: className }),
288
+ React.createElement("div", { onKeyDown: (event) => {
289
+ if (event.code === "ArrowUp") {
290
+ this.increment();
291
+ event.preventDefault();
292
+ event.stopPropagation();
293
+ }
294
+ else if (event.code === "ArrowDown") {
295
+ this.decrement();
296
+ event.preventDefault();
297
+ event.stopPropagation();
298
+ }
299
+ } },
300
+ React.createElement(MaskedInput, { mask: this.props.mask.replace(/[a-zA-Z]/g, '1'), bordered: bordered, ref: this.inputRef, style: maskedInputStyle, size: size, value: (this.state.focused || unix !== D2000UnixTimeNullValue * 1000) ? ((_a = value === null || value === void 0 ? void 0 : value.locale("locale.d2000").format(this.props.mask)) !== null && _a !== void 0 ? _a : "") : "", placeholder: (!this.state.focused && unix === D2000UnixTimeNullValue * 1000) ? "Null Time" : undefined, onFocus: (event => {
301
+ event.target.selectionStart = event.target.selectionEnd = this.state.currentPos;
302
+ this.setState({ focused: true });
303
+ }), onBlur: () => {
304
+ this.setState({ focused: false });
305
+ }, autoFocus: autoFocus, disabled: disabled || inputDisabled, onWheel: (event) => {
306
+ if (event.deltaY > 0) {
307
+ if (!isDownDisabled) {
308
+ this.decrement();
309
+ }
310
+ }
311
+ if (event.deltaY < 0) {
312
+ if (!isUpDisabled) {
313
+ this.increment();
314
+ }
315
+ }
316
+ }, onMouseUp: this.recalc, onKeyUp: this.recalc, onChange: (event) => {
317
+ const inputString = event.target.value;
318
+ const value = DateTimeInput.parseDateTimeFormat(this.props.value, inputString, this.props.mask, event.target.selectionStart);
319
+ const valid = DateTimeInput.isValidValue(value.time, this.props.minDateTime, this.props.maxDateTime, this.props.allowClear) || (!!this.props.allowClear && !inputString);
320
+ if (value.time !== undefined && valid) {
321
+ onChange === null || onChange === void 0 ? void 0 : onChange(value.time.clone());
322
+ }
323
+ else if (!!this.props.allowClear && !inputString) {
324
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
325
+ }
326
+ else {
327
+ onInvalidValue === null || onInvalidValue === void 0 ? void 0 : onInvalidValue(inputString);
328
+ }
329
+ this.setState({
330
+ valid: valid,
331
+ currentInfo: value
332
+ });
333
+ } })),
334
+ !hidePopup && !renderAsCalendar && React.createElement("div", { style: {
335
+ width: 28,
336
+ opacity: 1,
337
+ height: "100%",
338
+ textAlign: "center",
339
+ cursor: disabled ? "not-allowed" : "pointer",
340
+ background: "transparent",
341
+ position: "absolute",
342
+ top: 0,
343
+ right: 0,
344
+ }, onClick: (event) => {
345
+ if (document.createEvent) {
346
+ var ev = document.createEvent('HTMLEvents');
347
+ ev.initEvent('contextmenu', true, false);
348
+ event.target.dispatchEvent(ev);
349
+ }
350
+ } },
351
+ React.createElement(CalendarOutlined, { style: { color: "rgba(0,0,0,0.65)", verticalAlign: "middle", height: "100%" } }))));
352
+ }
353
+ render() {
354
+ if (this.props.renderAsCalendar) {
355
+ return this.renderCalendar();
356
+ }
357
+ else if (this.props.hidePopup) {
358
+ return this.renderInput();
359
+ }
360
+ else {
361
+ return (React.createElement(Tooltip, { color: "white", trigger: this.props.disabled ? [] : ["contextMenu"], getPopupContainer: this.props.getPopupContainer, overlayInnerStyle: { maxHeight: "100vh", overflowY: "auto", overflowX: "hidden", width: 266 }, open: this.state.popupCalendarVisible, onOpenChange: (visible) => {
362
+ var _a, _b, _c, _d;
363
+ this.setState({ popupCalendarVisible: visible });
364
+ if (visible) {
365
+ this.setState({ calendarSelectedDate: (_d = (_b = (_a = this.props.defaultSelectedDate) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : (_c = this.props.value) === null || _c === void 0 ? void 0 : _c.clone()) !== null && _d !== void 0 ? _d : dayjs().startOf("day") });
366
+ }
367
+ }, title: this.renderCalendar(), placement: this.props.placement }, this.renderInput()));
368
+ }
369
+ }
370
+ static isValid(info, value, offset) {
371
+ var _a;
372
+ const unit = (_a = info.info) === null || _a === void 0 ? void 0 : _a.unit;
373
+ return this.checkDateValueValidity(value, offset, unit);
374
+ }
375
+ static checkDateValueValidity(value, offset, unit) {
376
+ if (value === null) {
377
+ return false;
378
+ }
379
+ let v = value.clone().add(offset, unit);
380
+ return v.isValid() && v.isSameOrAfter(dayjs(0));
381
+ }
382
+ static parseDateTimeFormat(previousTime, value, mask, cursorPos) {
383
+ var _a, _b, _c;
384
+ let result = {
385
+ time: dayjs().startOf("day"),
386
+ info: undefined,
387
+ length: 0,
388
+ };
389
+ for (let v of DATE_TIME_DATA_MAP) {
390
+ let index = -1;
391
+ let length = 0;
392
+ let min = 0;
393
+ let max = 0;
394
+ if (Array.isArray(v.key) || Array.isArray(v.min) || Array.isArray(v.max)) {
395
+ for (let i = 0; i < v.key.length; i++) {
396
+ const x = v.key[i];
397
+ index = mask.indexOf(x);
398
+ if (index !== -1) {
399
+ length = x.length;
400
+ min = v.min[i];
401
+ max = v.max[i];
402
+ break;
403
+ }
404
+ }
405
+ }
406
+ else {
407
+ index = mask.indexOf(v.key);
408
+ length = v.key.length;
409
+ min = v.min;
410
+ max = v.max;
411
+ }
412
+ if (index !== -1) {
413
+ let val = Number(value.substring(index, index + length));
414
+ if (!isNaN(val) && val >= min && val <= max) {
415
+ if (v.unit === "M") {
416
+ val--;
417
+ }
418
+ if (v.unit === "d") {
419
+ result.time = (_a = result.time) === null || _a === void 0 ? void 0 : _a.set('D', val);
420
+ }
421
+ else if (v.unit === "y" && length === 2) {
422
+ const century = (previousTime != null && previousTime.isValid()) ? Math.floor(previousTime.year() / 100) * 100 : (val > 70 ? 1900 : 2000);
423
+ result.time = (_b = result.time) === null || _b === void 0 ? void 0 : _b.set(v.unit, century + val);
424
+ }
425
+ else if (v.unit !== "weeks" && v.unit !== "week" && v.unit !== "w") {
426
+ result.time = (_c = result.time) === null || _c === void 0 ? void 0 : _c.set(v.unit, val);
427
+ }
428
+ }
429
+ else {
430
+ result.time = undefined;
431
+ result.info = undefined;
432
+ result.length = 0;
433
+ break;
434
+ }
435
+ if (cursorPos !== null && cursorPos >= index && cursorPos <= index + length) {
436
+ result.info = v;
437
+ result.length = length;
438
+ }
439
+ }
440
+ }
441
+ return result;
442
+ }
443
+ static isValidValue(value, minDateTime, maxDateTime, allowClear) {
444
+ return (!!value && value.isValid() && (!minDateTime || value.isSameOrAfter(minDateTime)) && (!maxDateTime || value.isSameOrBefore(maxDateTime))) || (!!allowClear && value === null);
445
+ }
446
+ }
419
447
  //# sourceMappingURL=dateTimeInput.js.map