d2coreui 23.0.52 → 23.0.53
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.
- package/CHANGELOG.md +27 -0
- package/README.md +154 -0
- package/components/clipboard/clipboardUtils.d.ts +11 -0
- package/components/clipboard/clipboardUtils.js +16 -4
- package/components/clipboard/clipboardUtils.js.map +1 -1
- package/components/codemirror/SyntaxHighlighter.d.ts +13 -0
- package/components/codemirror/SyntaxHighlighter.js +6 -1
- package/components/codemirror/SyntaxHighlighter.js.map +1 -1
- package/components/collapse/expandable.d.ts +10 -0
- package/components/collapse/expandable.js +4 -0
- package/components/collapse/expandable.js.map +1 -1
- package/components/color/colorPicker.d.ts +16 -0
- package/components/color/colorPicker.js +4 -0
- package/components/color/colorPicker.js.map +1 -1
- package/components/color/colorSwatch.d.ts +16 -0
- package/components/color/colorSwatch.js +23 -2
- package/components/color/colorSwatch.js.map +1 -1
- package/components/color/colorUtils.d.ts +9 -0
- package/components/color/colorUtils.js +15 -0
- package/components/color/colorUtils.js.map +1 -1
- package/components/date/dateRangeInput.d.ts +76 -0
- package/components/date/dateRangeInput.js +63 -12
- package/components/date/dateRangeInput.js.map +1 -1
- package/components/date/dateRangeInputAdvancedPanel.d.ts +27 -0
- package/components/date/dateRangeInputAdvancedPanel.js +7 -0
- package/components/date/dateRangeInputAdvancedPanel.js.map +1 -1
- package/components/date/dateRangeInputConfirm.d.ts +18 -0
- package/components/date/dateRangeInputConfirm.js +12 -0
- package/components/date/dateRangeInputConfirm.js.map +1 -1
- package/components/date/dateTimeInput.d.ts +99 -0
- package/components/date/dateTimeInput.js +78 -6
- package/components/date/dateTimeInput.js.map +1 -1
- package/components/date/durationInput.d.ts +37 -0
- package/components/date/durationInput.js +26 -3
- package/components/date/durationInput.js.map +1 -1
- package/components/date/savedIntervals.d.ts +63 -0
- package/components/date/savedIntervals.js +37 -0
- package/components/date/savedIntervals.js.map +1 -1
- package/components/date/savedIntervalsDialog.d.ts +13 -0
- package/components/date/savedIntervalsDialog.js +7 -2
- package/components/date/savedIntervalsDialog.js.map +1 -1
- package/components/form/NiceFormItem.d.ts +9 -0
- package/components/form/NiceFormItem.js +4 -0
- package/components/form/NiceFormItem.js.map +1 -1
- package/components/grid/cell/beanAccessor.d.ts +12 -0
- package/components/grid/cell/beanAccessor.js +8 -0
- package/components/grid/cell/beanAccessor.js.map +1 -1
- package/components/grid/cell/bigNumberCellEditor.d.ts +9 -0
- package/components/grid/cell/bigNumberCellEditor.js +19 -0
- package/components/grid/cell/bigNumberCellEditor.js.map +1 -1
- package/components/grid/cell/cellControl.d.ts +4 -0
- package/components/grid/cell/cellControl.js +14 -0
- package/components/grid/cell/cellControl.js.map +1 -1
- package/components/grid/cell/cellEditorUtils.d.ts +6 -0
- package/components/grid/cell/cellEditorUtils.js +6 -0
- package/components/grid/cell/cellEditorUtils.js.map +1 -1
- package/components/grid/cell/customEnumCellEditor.d.ts +6 -0
- package/components/grid/cell/customEnumCellEditor.js +10 -0
- package/components/grid/cell/customEnumCellEditor.js.map +1 -1
- package/components/grid/cell/dataGridCellEditorComponent.d.ts +26 -0
- package/components/grid/cell/dataGridCellEditorComponent.js +21 -0
- package/components/grid/cell/dataGridCellEditorComponent.js.map +1 -1
- package/components/grid/cell/dateCellEditor.d.ts +6 -0
- package/components/grid/cell/dateCellEditor.js +10 -0
- package/components/grid/cell/dateCellEditor.js.map +1 -1
- package/components/grid/cell/dragListenerFeature.d.ts +6 -0
- package/components/grid/cell/dragListenerFeature.js +6 -0
- package/components/grid/cell/dragListenerFeature.js.map +1 -1
- package/components/grid/cell/durationCellEditor.d.ts +6 -0
- package/components/grid/cell/durationCellEditor.js +14 -0
- package/components/grid/cell/durationCellEditor.js.map +1 -1
- package/components/grid/cell/hexaOctetStringCellEditor.d.ts +6 -0
- package/components/grid/cell/hexaOctetStringCellEditor.js +14 -0
- package/components/grid/cell/hexaOctetStringCellEditor.js.map +1 -1
- package/components/grid/cell/hexaValueCellEditor.d.ts +6 -0
- package/components/grid/cell/hexaValueCellEditor.js +14 -0
- package/components/grid/cell/hexaValueCellEditor.js.map +1 -1
- package/components/grid/cell/numberCellEditor.d.ts +6 -0
- package/components/grid/cell/numberCellEditor.js +15 -0
- package/components/grid/cell/numberCellEditor.js.map +1 -1
- package/components/grid/cell/rangeSelector.d.ts +7 -0
- package/components/grid/cell/rangeSelector.js +59 -5
- package/components/grid/cell/rangeSelector.js.map +1 -1
- package/components/grid/cell/simpleStatusTextCellEditor.d.ts +7 -0
- package/components/grid/cell/simpleStatusTextCellEditor.js +11 -0
- package/components/grid/cell/simpleStatusTextCellEditor.js.map +1 -1
- package/components/grid/cell/statusTextCellEditor.d.ts +7 -0
- package/components/grid/cell/statusTextCellEditor.js +17 -0
- package/components/grid/cell/statusTextCellEditor.js.map +1 -1
- package/components/grid/cell/tableDefaultRowStyleRules.d.ts +31 -0
- package/components/grid/cell/tableDefaultRowStyleRules.js +5 -0
- package/components/grid/cell/tableDefaultRowStyleRules.js.map +1 -1
- package/components/grid/cell/textCellEditor.d.ts +6 -0
- package/components/grid/cell/textCellEditor.js +15 -0
- package/components/grid/cell/textCellEditor.js.map +1 -1
- package/components/grid/cell/withAgGridHooks.d.ts +8 -0
- package/components/grid/cell/withAgGridHooks.js +8 -0
- package/components/grid/cell/withAgGridHooks.js.map +1 -1
- package/components/grid/columnUtils.d.ts +7 -0
- package/components/grid/columnUtils.js +7 -0
- package/components/grid/columnUtils.js.map +1 -1
- package/components/grid/config/columnTransfer.d.ts +18 -0
- package/components/grid/config/columnTransfer.js +14 -3
- package/components/grid/config/columnTransfer.js.map +1 -1
- package/components/grid/config/dataGridEditor.d.ts +31 -0
- package/components/grid/config/dataGridEditor.js +14 -2
- package/components/grid/config/dataGridEditor.js.map +1 -1
- package/components/grid/config/rowHeightCalculator.d.ts +11 -0
- package/components/grid/config/rowHeightCalculator.js +11 -0
- package/components/grid/config/rowHeightCalculator.js.map +1 -1
- package/components/grid/config/rowStylePicker.d.ts +19 -0
- package/components/grid/config/rowStylePicker.js +12 -0
- package/components/grid/config/rowStylePicker.js.map +1 -1
- package/components/grid/dataGrid.d.ts +331 -0
- package/components/grid/dataGrid.js +168 -11
- package/components/grid/dataGrid.js.map +1 -1
- package/components/grid/detail/detailHeaderPanel.d.ts +11 -0
- package/components/grid/detail/detailHeaderPanel.js +5 -0
- package/components/grid/detail/detailHeaderPanel.js.map +1 -1
- package/components/grid/export/contextMenu.d.ts +31 -0
- package/components/grid/export/contextMenu.js +8 -0
- package/components/grid/export/contextMenu.js.map +1 -1
- package/components/grid/export/progressPopup.d.ts +21 -0
- package/components/grid/export/progressPopup.js +17 -0
- package/components/grid/export/progressPopup.js.map +1 -1
- package/components/grid/export/worker/pdfExport.js +5 -0
- package/components/grid/export/worker/pdfExport.js.map +1 -1
- package/components/grid/extendedDataGrid.d.ts +240 -0
- package/components/grid/extendedDataGrid.js +116 -2
- package/components/grid/extendedDataGrid.js.map +1 -1
- package/components/grid/filter/customColumnFilter.d.ts +5 -0
- package/components/grid/filter/customColumnFilter.js +5 -0
- package/components/grid/filter/customColumnFilter.js.map +1 -1
- package/components/grid/filter/dataGridColumnFilter.d.ts +19 -0
- package/components/grid/filter/dataGridColumnFilter.js +19 -0
- package/components/grid/filter/dataGridColumnFilter.js.map +1 -1
- package/components/grid/filter/dateColumnFilter.d.ts +6 -0
- package/components/grid/filter/dateColumnFilter.js +6 -0
- package/components/grid/filter/dateColumnFilter.js.map +1 -1
- package/components/grid/filter/textColumnFilter.d.ts +6 -0
- package/components/grid/filter/textColumnFilter.js +6 -0
- package/components/grid/filter/textColumnFilter.js.map +1 -1
- package/components/grid/filter/wildcardQuickFilterEngine.d.ts +21 -0
- package/components/grid/filter/wildcardQuickFilterEngine.js +21 -0
- package/components/grid/filter/wildcardQuickFilterEngine.js.map +1 -1
- package/components/grid/header/simpleHeader.d.ts +17 -0
- package/components/grid/header/simpleHeader.js +20 -0
- package/components/grid/header/simpleHeader.js.map +1 -1
- package/components/grid/panel/dataGridPagination.d.ts +10 -0
- package/components/grid/panel/dataGridPagination.js +5 -0
- package/components/grid/panel/dataGridPagination.js.map +1 -1
- package/components/grid/panel/loadingOverlay.d.ts +5 -0
- package/components/grid/panel/loadingOverlay.js +4 -0
- package/components/grid/panel/loadingOverlay.js.map +1 -1
- package/components/grid/panel/noRecordsOverlay.d.ts +6 -0
- package/components/grid/panel/noRecordsOverlay.js +5 -0
- package/components/grid/panel/noRecordsOverlay.js.map +1 -1
- package/components/grid/panel/tablePagination.d.ts +4 -0
- package/components/grid/panel/tablePagination.js +4 -0
- package/components/grid/panel/tablePagination.js.map +1 -1
- package/components/icons/dropdownArrow.d.ts +3 -0
- package/components/icons/dropdownArrow.js +2 -0
- package/components/icons/dropdownArrow.js.map +1 -1
- package/components/icons/undoIcon.d.ts +2 -0
- package/components/icons/undoIcon.js +2 -0
- package/components/icons/undoIcon.js.map +1 -1
- package/components/input/autoCompleteInput.d.ts +29 -0
- package/components/input/autoCompleteInput.js +7 -0
- package/components/input/autoCompleteInput.js.map +1 -1
- package/components/input/draftUtils.d.ts +7 -0
- package/components/input/draftUtils.js +9 -0
- package/components/input/draftUtils.js.map +1 -1
- package/components/input/hexaFormattedInput.d.ts +9 -0
- package/components/input/hexaFormattedInput.js +3 -0
- package/components/input/hexaFormattedInput.js.map +1 -1
- package/components/input/mask/helpers.d.ts +27 -0
- package/components/input/mask/helpers.js +27 -0
- package/components/input/mask/helpers.js.map +1 -1
- package/components/input/mask/inputMaskCore.d.ts +80 -0
- package/components/input/mask/inputMaskCore.js +90 -0
- package/components/input/mask/inputMaskCore.js.map +1 -1
- package/components/input/mask/pattern.d.ts +24 -0
- package/components/input/mask/pattern.js +26 -0
- package/components/input/mask/pattern.js.map +1 -1
- package/components/input/maskedInput.d.ts +53 -0
- package/components/input/maskedInput.js +44 -4
- package/components/input/maskedInput.js.map +1 -1
- package/components/input/passwordInput.d.ts +7 -0
- package/components/input/passwordInput.js +8 -0
- package/components/input/passwordInput.js.map +1 -1
- package/components/input/simpleAutoComplete.d.ts +6 -0
- package/components/input/simpleAutoComplete.js +6 -0
- package/components/input/simpleAutoComplete.js.map +1 -1
- package/components/input/textarea/extractSpansOfClasses.d.ts +17 -0
- package/components/input/textarea/extractSpansOfClasses.js +26 -1
- package/components/input/textarea/extractSpansOfClasses.js.map +1 -1
- package/components/input/textarea/getRanges.d.ts +7 -0
- package/components/input/textarea/getRanges.js +11 -0
- package/components/input/textarea/getRanges.js.map +1 -1
- package/components/input/textarea/getType.d.ts +5 -0
- package/components/input/textarea/getType.js +5 -0
- package/components/input/textarea/getType.js.map +1 -1
- package/components/input/textarea/highlighedContents.d.ts +4 -0
- package/components/input/textarea/highlighedContents.js +5 -0
- package/components/input/textarea/highlighedContents.js.map +1 -1
- package/components/input/textarea/mentionsWithHighlighting.d.ts +25 -0
- package/components/input/textarea/mentionsWithHighlighting.js +14 -0
- package/components/input/textarea/mentionsWithHighlighting.js.map +1 -1
- package/components/keyboard/keyboardUtils.d.ts +6 -0
- package/components/keyboard/keyboardUtils.js +6 -0
- package/components/keyboard/keyboardUtils.js.map +1 -1
- package/components/modal/draggableModalProvider.d.ts +6 -0
- package/components/modal/draggableModalProvider.js +7 -0
- package/components/modal/draggableModalProvider.js.map +1 -1
- package/components/modal/impl/clamp.js +1 -0
- package/components/modal/impl/clamp.js.map +1 -1
- package/components/modal/impl/draggableModal.d.ts +1 -0
- package/components/modal/impl/draggableModal.js +6 -0
- package/components/modal/impl/draggableModal.js.map +1 -1
- package/components/modal/impl/draggableModalContext.js +1 -0
- package/components/modal/impl/draggableModalContext.js.map +1 -1
- package/components/modal/impl/draggableModalInner.js +12 -1
- package/components/modal/impl/draggableModalInner.js.map +1 -1
- package/components/modal/impl/draggableModalReducer.d.ts +7 -1
- package/components/modal/impl/draggableModalReducer.js +6 -1
- package/components/modal/impl/draggableModalReducer.js.map +1 -1
- package/components/modal/impl/draggableModalStyles.d.ts +17 -0
- package/components/modal/impl/draggableModalStyles.js +31 -0
- package/components/modal/impl/draggableModalStyles.js.map +1 -1
- package/components/modal/impl/getWindowSize.js +1 -0
- package/components/modal/impl/getWindowSize.js.map +1 -1
- package/components/modal/impl/index.js +1 -0
- package/components/modal/impl/index.js.map +1 -1
- package/components/modal/impl/resizeHandle.d.ts +1 -0
- package/components/modal/impl/resizeHandle.js +4 -1
- package/components/modal/impl/resizeHandle.js.map +1 -1
- package/components/modal/impl/useDrag.js +1 -0
- package/components/modal/impl/useDrag.js.map +1 -1
- package/components/modal/impl/usePrevious.js +1 -0
- package/components/modal/impl/usePrevious.js.map +1 -1
- package/components/modal/impl/useResize.js +1 -0
- package/components/modal/impl/useResize.js.map +1 -1
- package/components/modal/modalDialog.d.ts +85 -0
- package/components/modal/modalDialog.js +80 -10
- package/components/modal/modalDialog.js.map +1 -1
- package/components/picker/enumValuePicker.d.ts +17 -0
- package/components/picker/enumValuePicker.js +4 -0
- package/components/picker/enumValuePicker.js.map +1 -1
- package/components/platformSpecific.d.ts +17 -0
- package/components/platformSpecific.js +16 -0
- package/components/platformSpecific.js.map +1 -1
- package/components/scrollTo/onlyText.d.ts +5 -0
- package/components/scrollTo/onlyText.js +5 -0
- package/components/scrollTo/onlyText.js.map +1 -1
- package/components/scrollTo/scrollTo.d.ts +56 -0
- package/components/scrollTo/scrollTo.js +40 -3
- package/components/scrollTo/scrollTo.js.map +1 -1
- package/components/style/withCss.d.ts +15 -0
- package/components/style/withCss.js +6 -0
- package/components/style/withCss.js.map +1 -1
- package/components/table/dragSortingTable.d.ts +15 -0
- package/components/table/dragSortingTable.js +12 -0
- package/components/table/dragSortingTable.js.map +1 -1
- package/components/text/impl/innerSize.js +2 -0
- package/components/text/impl/innerSize.js.map +1 -1
- package/components/text/impl/series.d.ts +10 -0
- package/components/text/impl/series.js +10 -0
- package/components/text/impl/series.js.map +1 -1
- package/components/text/impl/shallowEqual.js +1 -0
- package/components/text/impl/shallowEqual.js.map +1 -1
- package/components/text/impl/whilst.d.ts +7 -0
- package/components/text/impl/whilst.js +7 -0
- package/components/text/impl/whilst.js.map +1 -1
- package/components/text/textFit.d.ts +24 -0
- package/components/text/textFit.js +29 -1
- package/components/text/textFit.js.map +1 -1
- package/i18n/componentsLocaleHolder.d.ts +9 -0
- package/i18n/componentsLocaleHolder.js +9 -0
- package/i18n/componentsLocaleHolder.js.map +1 -1
- package/package.json +66 -65
|
@@ -21,15 +21,24 @@ import { createStyles } from "antd-style";
|
|
|
21
21
|
import WithCss from "../style/withCss";
|
|
22
22
|
const useStyles = createStyles(({ token, css }) => {
|
|
23
23
|
return {
|
|
24
|
+
// the confirm buttons float above the page on a transparent tooltip, so they need their own surface
|
|
24
25
|
buttonsSurface: css `
|
|
25
26
|
background: ${token.colorBgElevated};
|
|
26
27
|
`,
|
|
28
|
+
// ghost button is transparent by default - give it the same opaque surface
|
|
27
29
|
revertButton: css `
|
|
28
30
|
background: ${token.colorBgElevated};
|
|
29
31
|
border-right-width: 2px;
|
|
30
32
|
`,
|
|
31
33
|
};
|
|
32
34
|
});
|
|
35
|
+
/**
|
|
36
|
+
* {@link DateRangeInput} that buffers edits and reports them through `onChange` only when confirmed with the
|
|
37
|
+
* Apply button or Enter; the Revert button or Escape restores the last value from props. The Revert/Apply buttons
|
|
38
|
+
* float next to the input (and appear in the popup footer) while the range differs from the props, contains an
|
|
39
|
+
* invalid text or {@link DateRangeInputConfirmProps.requireConfirmationAtStart} is pending. A change of
|
|
40
|
+
* `fromValue`/`toValue` from props discards the buffered edit.
|
|
41
|
+
*/
|
|
33
42
|
export default class DateRangeInputConfirm extends React.Component {
|
|
34
43
|
constructor(props) {
|
|
35
44
|
var _a, _b, _c, _d, _e;
|
|
@@ -50,6 +59,7 @@ export default class DateRangeInputConfirm extends React.Component {
|
|
|
50
59
|
this.onConfirm = this.onConfirm.bind(this);
|
|
51
60
|
this.onRevert = this.onRevert.bind(this);
|
|
52
61
|
}
|
|
62
|
+
/** Confirms on Enter and reverts on Escape; attached to the wrapping element. */
|
|
53
63
|
onKeyDown(event) {
|
|
54
64
|
if (event.key === Key.Enter) {
|
|
55
65
|
this.onConfirm();
|
|
@@ -115,11 +125,13 @@ export default class DateRangeInputConfirm extends React.Component {
|
|
|
115
125
|
align = { points: ["br", "tr"], offset: [0, 8] };
|
|
116
126
|
}
|
|
117
127
|
else {
|
|
128
|
+
// default bottomRight
|
|
118
129
|
align = { points: ["tr", "br"], offset: [0, -6] };
|
|
119
130
|
}
|
|
120
131
|
return (React.createElement("span", { onKeyDown: this.onKeyDown, ref: this.parentRef },
|
|
121
132
|
React.createElement(Tooltip, { color: "transparent", styles: { body: { boxShadow: "none" } }, open: this.confirmButtonsVisible() && !this.state.popupVisible, align: align, title: this.renderConfirmButtons(rest.size, rest.size === "small" ? 48 : undefined), getPopupContainer: () => {
|
|
122
133
|
var _a, _b;
|
|
134
|
+
// very nasty trick how remove error of ResizeObservers infinite cycling - because popover (with dynamic size) is placed in resizable panel
|
|
123
135
|
const parentNode = ((_b = (_a = this.parentRef.current) === null || _a === void 0 ? void 0 : _a.parentNode) !== null && _b !== void 0 ? _b : document.body);
|
|
124
136
|
return parentNode;
|
|
125
137
|
} },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateRangeInputConfirm.js","sourceRoot":"","sources":["../../../../components/date/dateRangeInputConfirm.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAC,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,cAAc,EAAE,EAAC,kBAAkB,EAAsB,MAAM,kBAAkB,CAAC;AAGzF,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAE3C,OAAO,E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AAC,EAAE,CAAC,IAAI,CAAC,cAAc,GAAG,SAAS,EACjD,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,EACtC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,cAAc,EAClC,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE;wBAClB,IAAI,CAAC,QAAQ,CAAC,EAAC,mBAAmB,EAAE,IAAI,EAAC,CAAC,CAAC;oBAC/C,CAAC,EACD,QAAQ,EAAE,CAAC,SAAuB,EAAE,OAAqB,EAAE,EAAE;wBACzD,IAAI,CAAC,QAAQ,CAAC;4BACV,gBAAgB,EAAE,SAAS;4BAC3B,cAAc,EAAE,OAAO;4BACvB,mBAAmB,EAAE,KAAK;yBAC7B,CAAC,CAAA;oBACN,CAAC,EACD,sBAAsB,EAAE,GAAG,EAAE;wBACzB,IAAI,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC;4BAC/B,OAAO,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;wBAClD,CAAC;wBACD,OAAO,SAAS,CAAC;oBACrB,CAAC,EACD,oBAAoB,EAAE,OAAO,CAAC,EAAE;wBAC5B,IAAI,CAAC,QAAQ,CAAC,EAAC,YAAY,EAAE,OAAO,EAAC,CAAC,CAAC;oBAC3C,CAAC,EACD,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAC5B,YAAY,EAAE,IAAI,CAAC,EAAE;wBACjB,IAAI,CAAC,QAAQ,CAAC,EAAC,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;oBAChC,CAAC,IACG,IAAI,EACV,CACI,CACP,CACV,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, {createRef} from \"react\";\r\nimport {Dayjs} from \"dayjs\";\r\nimport {Button, Space, Tooltip} from \"antd\";\r\nimport {DateTimeUtils} from \"d2core/utils/dateTimeUtils\";\r\nimport {CheckOutlined} from \"@ant-design/icons\";\r\nimport i18n from \"d2core/i18n/i18n\";\r\nimport DateRangeInput, {DateRangeInputMode, DateRangeInputProps} from \"./dateRangeInput\";\r\nimport {TooltipPlacement} from \"antd/es/tooltip\";\r\nimport {AlignType} from \"@rc-component/trigger/lib/interface\";\r\nimport {UndoIcon} from \"../icons/undoIcon\";\r\nimport {SizeType} from \"antd/lib/config-provider/SizeContext\";\r\nimport {Key} from \"ts-key-enum\";\r\nimport {createStyles} from \"antd-style\";\r\nimport WithCss from \"../style/withCss\";\r\n\r\nconst useStyles = createStyles(({token, css}) => {\r\n return {\r\n // the confirm buttons float above the page on a transparent tooltip, so they need their own surface\r\n buttonsSurface: css`\r\n background: ${token.colorBgElevated};\r\n `,\r\n // ghost button is transparent by default - give it the same opaque surface\r\n revertButton: css`\r\n background: ${token.colorBgElevated};\r\n border-right-width: 2px;\r\n `,\r\n }\r\n});\r\n\r\ninterface DateRangeInputConfirmProps extends DateRangeInputProps {\r\n requireConfirmationAtStart?: boolean\r\n confirmPlacement?: TooltipPlacement\r\n}\r\n\r\ninterface DateRangeInputConfirmState {\r\n originalFromValue: Dayjs | null\r\n originalToValue: Dayjs | null\r\n currentFromValue: Dayjs | null\r\n currentToValue: Dayjs | null\r\n invalidDatesPresent: boolean\r\n requireConfirmation: boolean\r\n\r\n popupVisible: boolean\r\n mode: DateRangeInputMode\r\n}\r\n\r\nexport default class DateRangeInputConfirm extends React.Component<DateRangeInputConfirmProps, DateRangeInputConfirmState> {\r\n private dateRangeInput: DateRangeInput | null = null;\r\n private parentRef: React.RefObject<HTMLSpanElement> = createRef();\r\n\r\n constructor(props: Readonly<DateRangeInputConfirmProps>) {\r\n super(props);\r\n this.state = {\r\n originalFromValue: props.fromValue ?? null,\r\n originalToValue: props.toValue ?? null,\r\n currentFromValue: props.fromValue ?? null,\r\n currentToValue: props.toValue ?? null,\r\n invalidDatesPresent: false,\r\n requireConfirmation: !!props.requireConfirmationAtStart,\r\n\r\n popupVisible: false,\r\n mode: props.defaultMode ?? DateRangeInputMode.SIMPLE,\r\n };\r\n\r\n this.onKeyDown = this.onKeyDown.bind(this);\r\n this.onConfirm = this.onConfirm.bind(this);\r\n this.onRevert = this.onRevert.bind(this);\r\n }\r\n\r\n onKeyDown(event: React.KeyboardEvent) {\r\n if (event.key === Key.Enter) {\r\n this.onConfirm();\r\n } else if (event.key === Key.Escape) {\r\n this.onRevert();\r\n }\r\n }\r\n\r\n componentDidUpdate(prevProps: Readonly<DateRangeInputProps>) {\r\n const preFromValueUnixTime = DateTimeUtils.toUnixTime(prevProps.fromValue);\r\n const currentFromValueUnixTime = DateTimeUtils.toUnixTime(this.props.fromValue);\r\n const prevToValueUnixTime = DateTimeUtils.toUnixTime(prevProps.toValue);\r\n const currentToValueUnixTime = DateTimeUtils.toUnixTime(this.props.toValue);\r\n if (preFromValueUnixTime !== currentFromValueUnixTime ||\r\n prevToValueUnixTime !== currentToValueUnixTime) {\r\n this.setState({\r\n originalFromValue: this.props.fromValue ?? null,\r\n originalToValue: this.props.toValue ?? null,\r\n currentFromValue: this.props.fromValue ?? null,\r\n currentToValue: this.props.toValue ?? null\r\n })\r\n }\r\n }\r\n\r\n private onConfirm() {\r\n this.setState({requireConfirmation: false});\r\n this.props.onChange?.(this.state.currentFromValue, this.state.currentToValue);\r\n this.dateRangeInput?.closePopup();\r\n }\r\n\r\n private onRevert() {\r\n this.setState({\r\n currentFromValue: this.state.originalFromValue ?? null,\r\n currentToValue: this.state.originalToValue ?? null,\r\n invalidDatesPresent: false,\r\n });\r\n this.dateRangeInput?.closePopup();\r\n }\r\n\r\n private renderConfirmButtons(size?: SizeType, buttonWidth?: number) {\r\n const validInterval = this.props.allowClear ?\r\n (!this.state.currentFromValue || this.state.currentFromValue.isValid()) && (!this.state.currentToValue || this.state.currentToValue.isValid()) :\r\n this.state.currentFromValue && this.state.currentFromValue.isValid() && this.state.currentToValue && this.state.currentToValue.isValid();\r\n\r\n return (\r\n <WithCss useStyles={useStyles}>{({styles}) =>\r\n <Space.Compact className={styles.buttonsSurface}>\r\n <Button\r\n className={styles.revertButton}\r\n style={{width: buttonWidth}}\r\n size={size}\r\n title={i18n(\"Revert\")}\r\n key=\"revert\"\r\n danger\r\n ghost\r\n onClick={this.onRevert}\r\n >\r\n <UndoIcon/>\r\n </Button>\r\n <Button\r\n style={{width: buttonWidth}}\r\n title={i18n(\"Apply\")} key=\"apply-button\"\r\n size={size}\r\n type=\"primary\"\r\n disabled={!validInterval || this.state.invalidDatesPresent}\r\n onClick={this.onConfirm}\r\n >\r\n <CheckOutlined/>\r\n </Button>\r\n </Space.Compact>\r\n }</WithCss>\r\n );\r\n }\r\n\r\n private confirmButtonsVisible() {\r\n const {originalFromValue, originalToValue, currentFromValue, currentToValue} = this.state;\r\n const valueChanged = DateTimeUtils.toUnixTime(currentFromValue) !== DateTimeUtils.toUnixTime(originalFromValue) ||\r\n DateTimeUtils.toUnixTime(currentToValue) !== DateTimeUtils.toUnixTime(originalToValue);\r\n\r\n return valueChanged || this.state.invalidDatesPresent || this.state.requireConfirmation;\r\n }\r\n\r\n render(): any {\r\n const {\r\n fromValue,\r\n toValue,\r\n onChange,\r\n allowClear,\r\n requireConfirmationAtStart,\r\n confirmPlacement,\r\n compact,\r\n ...rest\r\n } = this.props;\r\n let align: AlignType;\r\n if (confirmPlacement === \"right\") {\r\n align = {points: [\"tl\", \"tr\"], offset: [-8, 0]};\r\n } else if (confirmPlacement === \"topRight\") {\r\n align = {points: [\"br\", \"tr\"], offset: [0, 8]};\r\n } else {\r\n // default bottomRight\r\n align = {points: [\"tr\", \"br\"], offset: [0, -6]};\r\n }\r\n return (\r\n <span onKeyDown={this.onKeyDown} ref={this.parentRef}>\r\n <Tooltip\r\n color={\"transparent\"}\r\n styles={{body: {boxShadow: \"none\"}}}\r\n open={this.confirmButtonsVisible() && !this.state.popupVisible}\r\n align={align}\r\n title={this.renderConfirmButtons(rest.size, rest.size === \"small\" ? 48 : undefined)}\r\n getPopupContainer={() => {\r\n // very nasty trick how remove error of ResizeObservers infinite cycling - because popover (with dynamic size) is placed in resizable panel\r\n const parentNode = (this.parentRef.current?.parentNode ?? document.body) as HTMLElement;\r\n return parentNode;\r\n }}\r\n >\r\n <DateRangeInput\r\n ref={component => this.dateRangeInput = component}\r\n fromValue={this.state.currentFromValue}\r\n toValue={this.state.currentToValue}\r\n allowClear={allowClear}\r\n compact={compact}\r\n onInvalidValue={(_) => {\r\n this.setState({invalidDatesPresent: true});\r\n }}\r\n onChange={(fromValue: Dayjs | null, toValue: Dayjs | null) => {\r\n this.setState({\r\n currentFromValue: fromValue,\r\n currentToValue: toValue,\r\n invalidDatesPresent: false,\r\n })\r\n }}\r\n confirmButtonsRenderer={() => {\r\n if (this.confirmButtonsVisible()) {\r\n return this.renderConfirmButtons(\"small\", 48);\r\n }\r\n return undefined;\r\n }}\r\n onPopupVisibleChange={visible => {\r\n this.setState({popupVisible: visible});\r\n }}\r\n defaultMode={this.state.mode}\r\n onModeChange={mode => {\r\n this.setState({mode: mode});\r\n }}\r\n {...rest}\r\n />\r\n </Tooltip>\r\n </span>\r\n );\r\n }\r\n}"]}
|
|
1
|
+
{"version":3,"file":"dateRangeInputConfirm.js","sourceRoot":"","sources":["../../../../components/date/dateRangeInputConfirm.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAC,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,cAAc,EAAE,EAAC,kBAAkB,EAAsB,MAAM,kBAAkB,CAAC;AAGzF,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,GAAG,EAAC,MAAM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"antd\";\r\nimport {DateTimeUtils} from \"d2core/utils/dateTimeUtils\";\r\nimport {CheckOutlined} from \"@ant-design/icons\";\r\nimport i18n from \"d2core/i18n/i18n\";\r\nimport DateRangeInput, {DateRangeInputMode, DateRangeInputProps} from \"./dateRangeInput\";\r\nimport {TooltipPlacement} from \"antd/es/tooltip\";\r\nimport {AlignType} from \"@rc-component/trigger/lib/interface\";\r\nimport {UndoIcon} from \"../icons/undoIcon\";\r\nimport {SizeType} from \"antd/lib/config-provider/SizeContext\";\r\nimport {Key} from \"ts-key-enum\";\r\nimport {createStyles} from \"antd-style\";\r\nimport WithCss from \"../style/withCss\";\r\n\r\nconst useStyles = createStyles(({token, css}) => {\r\n return {\r\n // the confirm buttons float above the page on a transparent tooltip, so they need their own surface\r\n buttonsSurface: css`\r\n background: ${token.colorBgElevated};\r\n `,\r\n // ghost button is transparent by default - give it the same opaque surface\r\n revertButton: css`\r\n background: ${token.colorBgElevated};\r\n border-right-width: 2px;\r\n `,\r\n }\r\n});\r\n\r\n/**\r\n * Props of {@link DateRangeInputConfirm} - those of {@link DateRangeInput}, except that `onChange` is called only\r\n * on confirmation. `onInvalidValue`, `onPopupVisibleChange`, `onModeChange`, `defaultMode` and\r\n * `confirmButtonsRenderer` are used internally and passing them overrides the confirm behaviour.\r\n */\r\ninterface DateRangeInputConfirmProps extends DateRangeInputProps {\r\n /** Shows the confirm buttons from the start, even before anything is changed, until the first confirmation. */\r\n requireConfirmationAtStart?: boolean\r\n /**\r\n * Where the floating confirm buttons are shown next to the input: `\"right\"`, `\"topRight\"`; any other value\r\n * (or none) means below the right edge.\r\n */\r\n confirmPlacement?: TooltipPlacement\r\n}\r\n\r\ninterface DateRangeInputConfirmState {\r\n originalFromValue: Dayjs | null\r\n originalToValue: Dayjs | null\r\n currentFromValue: Dayjs | null\r\n currentToValue: Dayjs | null\r\n invalidDatesPresent: boolean\r\n requireConfirmation: boolean\r\n\r\n popupVisible: boolean\r\n mode: DateRangeInputMode\r\n}\r\n\r\n/**\r\n * {@link DateRangeInput} that buffers edits and reports them through `onChange` only when confirmed with the\r\n * Apply button or Enter; the Revert button or Escape restores the last value from props. The Revert/Apply buttons\r\n * float next to the input (and appear in the popup footer) while the range differs from the props, contains an\r\n * invalid text or {@link DateRangeInputConfirmProps.requireConfirmationAtStart} is pending. A change of\r\n * `fromValue`/`toValue` from props discards the buffered edit.\r\n */\r\nexport default class DateRangeInputConfirm extends React.Component<DateRangeInputConfirmProps, DateRangeInputConfirmState> {\r\n private dateRangeInput: DateRangeInput | null = null;\r\n private parentRef: React.RefObject<HTMLSpanElement> = createRef();\r\n\r\n constructor(props: Readonly<DateRangeInputConfirmProps>) {\r\n super(props);\r\n this.state = {\r\n originalFromValue: props.fromValue ?? null,\r\n originalToValue: props.toValue ?? null,\r\n currentFromValue: props.fromValue ?? null,\r\n currentToValue: props.toValue ?? null,\r\n invalidDatesPresent: false,\r\n requireConfirmation: !!props.requireConfirmationAtStart,\r\n\r\n popupVisible: false,\r\n mode: props.defaultMode ?? DateRangeInputMode.SIMPLE,\r\n };\r\n\r\n this.onKeyDown = this.onKeyDown.bind(this);\r\n this.onConfirm = this.onConfirm.bind(this);\r\n this.onRevert = this.onRevert.bind(this);\r\n }\r\n\r\n /** Confirms on Enter and reverts on Escape; attached to the wrapping element. */\r\n onKeyDown(event: React.KeyboardEvent) {\r\n if (event.key === Key.Enter) {\r\n this.onConfirm();\r\n } else if (event.key === Key.Escape) {\r\n this.onRevert();\r\n }\r\n }\r\n\r\n componentDidUpdate(prevProps: Readonly<DateRangeInputProps>) {\r\n const preFromValueUnixTime = DateTimeUtils.toUnixTime(prevProps.fromValue);\r\n const currentFromValueUnixTime = DateTimeUtils.toUnixTime(this.props.fromValue);\r\n const prevToValueUnixTime = DateTimeUtils.toUnixTime(prevProps.toValue);\r\n const currentToValueUnixTime = DateTimeUtils.toUnixTime(this.props.toValue);\r\n if (preFromValueUnixTime !== currentFromValueUnixTime ||\r\n prevToValueUnixTime !== currentToValueUnixTime) {\r\n this.setState({\r\n originalFromValue: this.props.fromValue ?? null,\r\n originalToValue: this.props.toValue ?? null,\r\n currentFromValue: this.props.fromValue ?? null,\r\n currentToValue: this.props.toValue ?? null\r\n })\r\n }\r\n }\r\n\r\n private onConfirm() {\r\n this.setState({requireConfirmation: false});\r\n this.props.onChange?.(this.state.currentFromValue, this.state.currentToValue);\r\n this.dateRangeInput?.closePopup();\r\n }\r\n\r\n private onRevert() {\r\n this.setState({\r\n currentFromValue: this.state.originalFromValue ?? null,\r\n currentToValue: this.state.originalToValue ?? null,\r\n invalidDatesPresent: false,\r\n });\r\n this.dateRangeInput?.closePopup();\r\n }\r\n\r\n private renderConfirmButtons(size?: SizeType, buttonWidth?: number) {\r\n const validInterval = this.props.allowClear ?\r\n (!this.state.currentFromValue || this.state.currentFromValue.isValid()) && (!this.state.currentToValue || this.state.currentToValue.isValid()) :\r\n this.state.currentFromValue && this.state.currentFromValue.isValid() && this.state.currentToValue && this.state.currentToValue.isValid();\r\n\r\n return (\r\n <WithCss useStyles={useStyles}>{({styles}) =>\r\n <Space.Compact className={styles.buttonsSurface}>\r\n <Button\r\n className={styles.revertButton}\r\n style={{width: buttonWidth}}\r\n size={size}\r\n title={i18n(\"Revert\")}\r\n key=\"revert\"\r\n danger\r\n ghost\r\n onClick={this.onRevert}\r\n >\r\n <UndoIcon/>\r\n </Button>\r\n <Button\r\n style={{width: buttonWidth}}\r\n title={i18n(\"Apply\")} key=\"apply-button\"\r\n size={size}\r\n type=\"primary\"\r\n disabled={!validInterval || this.state.invalidDatesPresent}\r\n onClick={this.onConfirm}\r\n >\r\n <CheckOutlined/>\r\n </Button>\r\n </Space.Compact>\r\n }</WithCss>\r\n );\r\n }\r\n\r\n private confirmButtonsVisible() {\r\n const {originalFromValue, originalToValue, currentFromValue, currentToValue} = this.state;\r\n const valueChanged = DateTimeUtils.toUnixTime(currentFromValue) !== DateTimeUtils.toUnixTime(originalFromValue) ||\r\n DateTimeUtils.toUnixTime(currentToValue) !== DateTimeUtils.toUnixTime(originalToValue);\r\n\r\n return valueChanged || this.state.invalidDatesPresent || this.state.requireConfirmation;\r\n }\r\n\r\n render(): any {\r\n const {\r\n fromValue,\r\n toValue,\r\n onChange,\r\n allowClear,\r\n requireConfirmationAtStart,\r\n confirmPlacement,\r\n compact,\r\n ...rest\r\n } = this.props;\r\n let align: AlignType;\r\n if (confirmPlacement === \"right\") {\r\n align = {points: [\"tl\", \"tr\"], offset: [-8, 0]};\r\n } else if (confirmPlacement === \"topRight\") {\r\n align = {points: [\"br\", \"tr\"], offset: [0, 8]};\r\n } else {\r\n // default bottomRight\r\n align = {points: [\"tr\", \"br\"], offset: [0, -6]};\r\n }\r\n return (\r\n <span onKeyDown={this.onKeyDown} ref={this.parentRef}>\r\n <Tooltip\r\n color={\"transparent\"}\r\n styles={{body: {boxShadow: \"none\"}}}\r\n open={this.confirmButtonsVisible() && !this.state.popupVisible}\r\n align={align}\r\n title={this.renderConfirmButtons(rest.size, rest.size === \"small\" ? 48 : undefined)}\r\n getPopupContainer={() => {\r\n // very nasty trick how remove error of ResizeObservers infinite cycling - because popover (with dynamic size) is placed in resizable panel\r\n const parentNode = (this.parentRef.current?.parentNode ?? document.body) as HTMLElement;\r\n return parentNode;\r\n }}\r\n >\r\n <DateRangeInput\r\n ref={component => this.dateRangeInput = component}\r\n fromValue={this.state.currentFromValue}\r\n toValue={this.state.currentToValue}\r\n allowClear={allowClear}\r\n compact={compact}\r\n onInvalidValue={(_) => {\r\n this.setState({invalidDatesPresent: true});\r\n }}\r\n onChange={(fromValue: Dayjs | null, toValue: Dayjs | null) => {\r\n this.setState({\r\n currentFromValue: fromValue,\r\n currentToValue: toValue,\r\n invalidDatesPresent: false,\r\n })\r\n }}\r\n confirmButtonsRenderer={() => {\r\n if (this.confirmButtonsVisible()) {\r\n return this.renderConfirmButtons(\"small\", 48);\r\n }\r\n return undefined;\r\n }}\r\n onPopupVisibleChange={visible => {\r\n this.setState({popupVisible: visible});\r\n }}\r\n defaultMode={this.state.mode}\r\n onModeChange={mode => {\r\n this.setState({mode: mode});\r\n }}\r\n {...rest}\r\n />\r\n </Tooltip>\r\n </span>\r\n );\r\n }\r\n}"]}
|
|
@@ -4,30 +4,75 @@ import { TooltipPlacement } from "antd/lib/tooltip";
|
|
|
4
4
|
import { SizeType } from "antd/lib/config-provider/SizeContext";
|
|
5
5
|
import { InputProps } from "antd/es";
|
|
6
6
|
import { InputStatus } from "antd/es/_util/statusUtils";
|
|
7
|
+
/**
|
|
8
|
+
* Props of {@link DateTimeInput}. Remaining HTML attributes (`style`, `className`, `id`, ...) are
|
|
9
|
+
* applied to the root `div` of the input; with {@link DateTimeInputProps.renderAsCalendar} only
|
|
10
|
+
* `style` is used (on the calendar).
|
|
11
|
+
*/
|
|
7
12
|
interface DateTimeInputProps extends Omit<HTMLAttributes<HTMLDivElement>, "onChange"> {
|
|
13
|
+
/**
|
|
14
|
+
* dayjs format of the displayed and typed value, typically from `LocaleHolder.getDateTimeFormat()`.
|
|
15
|
+
* Editable tokens: `YYYY`, `YY`, `MM`, `DD`, `HH`, `mm`, `ss`, `SSS` and the UTC offset `Z` (`+02:00`) or
|
|
16
|
+
* `ZZ` (`+0200`); other characters are literals. Fields missing from the mask are taken from the start
|
|
17
|
+
* of the current day. A 2-digit year keeps the century of the previous value (without one, `> 70` means 19xx,
|
|
18
|
+
* otherwise 20xx). Including the UTC offset makes both instants of a DST fold enterable and rejects a
|
|
19
|
+
* wall clock inside a DST gap.
|
|
20
|
+
*/
|
|
8
21
|
mask: string;
|
|
22
|
+
/**
|
|
23
|
+
* Current value (controlled), in the browser's local time zone. `null` shows an empty input. The D2000
|
|
24
|
+
* "null time" instant is shown as an empty input with a "Null Time" placeholder while not focused.
|
|
25
|
+
*/
|
|
9
26
|
value: Dayjs | null;
|
|
27
|
+
/**
|
|
28
|
+
* Called with a new value whenever the typed text parses to a valid instant within
|
|
29
|
+
* {@link DateTimeInputProps.minDateTime}/{@link DateTimeInputProps.maxDateTime}, when a field is stepped
|
|
30
|
+
* (arrow keys, mouse wheel - clamped to min/max), when a day is picked in the calendar (the time of day
|
|
31
|
+
* of the current value is kept, 00:00 when there is none) and when "Today" is clicked (start of today).
|
|
32
|
+
* Called with `null` when the input is emptied and {@link DateTimeInputProps.allowClear} is set.
|
|
33
|
+
*/
|
|
10
34
|
onChange?: (time: Dayjs | null) => void;
|
|
35
|
+
/** Called with the raw input text when an edit results in text that is not a valid (or allowed) value. */
|
|
11
36
|
onInvalidValue?: (inputString: string) => void;
|
|
37
|
+
/** Allows the value to be cleared: an emptied input is reported as `null` and `null` counts as valid. */
|
|
12
38
|
allowClear?: boolean;
|
|
39
|
+
/** Disables the input and the calendar popup. */
|
|
13
40
|
disabled?: boolean;
|
|
41
|
+
/** Disables only the text input without the disabled look of the whole component - e.g. while a popup is open. */
|
|
14
42
|
inputDisabled?: boolean;
|
|
43
|
+
/** Earliest allowed value (inclusive); earlier typed values are invalid, steps are clamped, calendar days are disabled. */
|
|
15
44
|
minDateTime?: Dayjs;
|
|
45
|
+
/** Latest allowed value (inclusive); later typed values are invalid, steps are clamped, calendar days are disabled. */
|
|
16
46
|
maxDateTime?: Dayjs;
|
|
47
|
+
/** antd input variant. */
|
|
17
48
|
variant?: InputProps["variant"];
|
|
49
|
+
/** antd validation status; an unparseable or out-of-range value is always drawn as `"error"` regardless. */
|
|
18
50
|
status?: InputStatus;
|
|
51
|
+
/** Renders only the masked input - no calendar icon and no calendar popup. */
|
|
19
52
|
hidePopup?: boolean;
|
|
53
|
+
/** Renders only the calendar panel inline (no input, no "Today" button). */
|
|
20
54
|
renderAsCalendar?: boolean;
|
|
55
|
+
/** Focuses the input on mount. */
|
|
21
56
|
autoFocus?: boolean;
|
|
57
|
+
/** Placement of the calendar popup relative to the input. */
|
|
22
58
|
placement?: TooltipPlacement;
|
|
59
|
+
/** antd control size. */
|
|
23
60
|
size?: SizeType;
|
|
61
|
+
/** Day whose month the calendar shows initially and whenever the popup opens, instead of the value's month. */
|
|
24
62
|
defaultSelectedDate?: Dayjs;
|
|
63
|
+
/** Inclusive range of days highlighted in the calendar as selected. Intended for range pickers. */
|
|
25
64
|
markedDateInterval?: [Dayjs, Dayjs];
|
|
65
|
+
/** Called on mouse down over a calendar day, with that day combined with the time of day of the current value. */
|
|
26
66
|
onDateItemMouseDown?: (date: Dayjs) => void;
|
|
67
|
+
/** Called on mouse up over a calendar day, with that day combined with the time of day of the current value. */
|
|
27
68
|
onDateItemMouseUp?: (date: Dayjs) => void;
|
|
69
|
+
/** Called (debounced by 100 ms) when the mouse moves over a calendar day, with the start of that day. */
|
|
28
70
|
onDateItemMouseOver?: (date: Dayjs) => void;
|
|
71
|
+
/** Style of the inner text input element (the `style` prop styles the wrapper). */
|
|
29
72
|
inputStyle?: React.CSSProperties;
|
|
73
|
+
/** Container the calendar popup and its month/year dropdowns are rendered into. */
|
|
30
74
|
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
|
|
75
|
+
/** Disables the Enter key in the calendar, which otherwise commits the day currently shown as selected. */
|
|
31
76
|
ignoreKeyStrokes?: boolean;
|
|
32
77
|
}
|
|
33
78
|
interface DateTimeInputState {
|
|
@@ -43,6 +88,7 @@ interface MaskResult {
|
|
|
43
88
|
info: MaskSegment | undefined;
|
|
44
89
|
length: number;
|
|
45
90
|
}
|
|
91
|
+
/** the units the mask can address - a subset of ManipulateType, without the week units */
|
|
46
92
|
type DateTimeUnit = "ms" | "s" | "m" | "h" | "y" | "M" | "d";
|
|
47
93
|
interface InfoEntry {
|
|
48
94
|
key: string | string[];
|
|
@@ -51,8 +97,14 @@ interface InfoEntry {
|
|
|
51
97
|
unit: DateTimeUnit;
|
|
52
98
|
part: keyof WallClockParts;
|
|
53
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Calendar reading of a value, as typed. Kept apart from Dayjs on purpose - assembling a Dayjs
|
|
102
|
+
* normalises a wall clock that does not exist (during a DST gap 02:30 silently becomes 03:30),
|
|
103
|
+
* which would hide exactly the case the UTC offset is there to resolve.
|
|
104
|
+
*/
|
|
54
105
|
interface WallClockParts {
|
|
55
106
|
y: number;
|
|
107
|
+
/** 0-11, as in Dayjs */
|
|
56
108
|
M: number;
|
|
57
109
|
D: number;
|
|
58
110
|
h: number;
|
|
@@ -60,15 +112,43 @@ interface WallClockParts {
|
|
|
60
112
|
s: number;
|
|
61
113
|
ms: number;
|
|
62
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* One editable field of the mask, located in the *rendered* value rather than in the mask
|
|
117
|
+
* string. The two differ as soon as the mask contains a token whose rendered width is not
|
|
118
|
+
* its own length - dayjs prints `Z` as "+02:00" and `ZZ` as "+0200".
|
|
119
|
+
*/
|
|
63
120
|
interface MaskSegment {
|
|
121
|
+
/** the mask token this segment was built from, e.g. "YYYY" or "Z" */
|
|
64
122
|
token: string;
|
|
123
|
+
/** offset of the segment in the rendered value */
|
|
65
124
|
index: number;
|
|
125
|
+
/** length of the segment in the rendered value */
|
|
66
126
|
length: number;
|
|
127
|
+
/** numeric field description - undefined for the UTC-offset segment */
|
|
67
128
|
entry: InfoEntry | undefined;
|
|
68
129
|
min: number;
|
|
69
130
|
max: number;
|
|
70
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Globally changes the lowest year accepted in a `YYYY` field of every {@link DateTimeInput} from 1900 to 1902.
|
|
134
|
+
* Stepping and the calendar stay limited to dates from the Unix epoch on.
|
|
135
|
+
*/
|
|
71
136
|
export declare function allowDatesBeforeEpoch(): void;
|
|
137
|
+
/**
|
|
138
|
+
* Masked date-time input with a calendar popup - a controlled replacement for antd `DatePicker`.
|
|
139
|
+
* The value is typed field by field according to {@link DateTimeInputProps.mask}; ArrowUp/ArrowDown and the
|
|
140
|
+
* mouse wheel step the field under the cursor. The calendar opens on right-click or via the calendar icon.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* const [value, setValue] = useState<Dayjs | null>(dayjs().startOf("hour"));
|
|
144
|
+
*
|
|
145
|
+
* <DateTimeInput
|
|
146
|
+
* mask={LocaleHolder.getDateTimeFormat(true, true)}
|
|
147
|
+
* value={value}
|
|
148
|
+
* onChange={setValue}
|
|
149
|
+
* allowClear
|
|
150
|
+
* />
|
|
151
|
+
*/
|
|
72
152
|
export default class DateTimeInput extends React.Component<DateTimeInputProps, DateTimeInputState> {
|
|
73
153
|
private inputRef;
|
|
74
154
|
private today;
|
|
@@ -78,24 +158,43 @@ export default class DateTimeInput extends React.Component<DateTimeInputProps, D
|
|
|
78
158
|
componentDidMount(): void;
|
|
79
159
|
componentWillUnmount(): void;
|
|
80
160
|
componentDidUpdate(prevProps: Readonly<DateTimeInputProps>, _prevState: Readonly<DateTimeInputState>, _snapshot?: any): void;
|
|
161
|
+
/** The underlying `<input>` element, `undefined` before mount or with {@link DateTimeInputProps.renderAsCalendar}. */
|
|
81
162
|
get input(): HTMLInputElement | undefined;
|
|
82
163
|
private getLayout;
|
|
164
|
+
/** Moves the keyboard focus to the text input. */
|
|
83
165
|
focus(): void;
|
|
84
166
|
private canStep;
|
|
167
|
+
/**
|
|
168
|
+
* The value one step up/down from the current one, or undefined when the field under the
|
|
169
|
+
* cursor cannot be stepped. Over the UTC-offset field a step means "the other offset of the
|
|
170
|
+
* same wall clock", which only exists inside a DST fold - elsewhere the arrows stay inert.
|
|
171
|
+
*/
|
|
85
172
|
private nextValue;
|
|
86
173
|
private step;
|
|
174
|
+
/** the page must not scroll while the wheel is editing the value */
|
|
87
175
|
private onWheel;
|
|
176
|
+
/** Re-reads the cursor position and the mask field under it; called internally on key up and mouse up. */
|
|
88
177
|
recalc(): void;
|
|
89
178
|
private increment;
|
|
90
179
|
private decrement;
|
|
180
|
+
/** Forwards a hovered calendar day to {@link DateTimeInputProps.onDateItemMouseOver}; debounced by 100 ms. */
|
|
91
181
|
onItemMouseOver(itemDate: Dayjs): void;
|
|
92
182
|
private renderCalendarNavigation;
|
|
183
|
+
/** Renders the calendar panel - the popup content, or the whole component with {@link DateTimeInputProps.renderAsCalendar}. */
|
|
93
184
|
renderCalendar(): React.ReactElement;
|
|
185
|
+
/** Renders the masked input with its calendar icon, without the popup. */
|
|
94
186
|
renderInput(): React.JSX.Element;
|
|
95
187
|
render(): any;
|
|
96
188
|
private static toWallClock;
|
|
189
|
+
/** the two instants of a DST fold share the wall clock and differ only in the UTC offset */
|
|
97
190
|
private static isSameWallClock;
|
|
98
191
|
private static parseUtcOffset;
|
|
192
|
+
/**
|
|
193
|
+
* Picks the instant that shows the given wall clock at the given UTC offset. Inside a DST
|
|
194
|
+
* fold two instants share the wall clock and the offset is what tells them apart; inside a
|
|
195
|
+
* DST gap no instant matches, so the value is reported as invalid. A wall clock that does
|
|
196
|
+
* not exist at all (31.02.) is rejected by the same check rather than rolled over.
|
|
197
|
+
*/
|
|
99
198
|
private static resolveWallClock;
|
|
100
199
|
private static checkDateValueValidity;
|
|
101
200
|
private static parseDateTimeFormat;
|
|
@@ -24,6 +24,7 @@ import WithCss from "d2coreui/components/style/withCss";
|
|
|
24
24
|
import i18n from "d2core/i18n/i18n";
|
|
25
25
|
import { DEFAULT_FORMAT_CHARACTERS, ESCAPE_CHAR } from "d2coreui/components/input/mask/helpers";
|
|
26
26
|
const useStyles = createStyles(({ token, css }, props) => {
|
|
27
|
+
// antd colours prefix/suffix by status in every variant except borderless
|
|
27
28
|
const statusAffix = props.variant !== "borderless";
|
|
28
29
|
return {
|
|
29
30
|
dateTimeInputCalendar: css `
|
|
@@ -73,6 +74,7 @@ const useStyles = createStyles(({ token, css }, props) => {
|
|
|
73
74
|
vertical-align: middle;
|
|
74
75
|
height: 100%;
|
|
75
76
|
`,
|
|
77
|
+
// antd colours the affix by status - see `genOutlinedStatusStyle.affixColor`
|
|
76
78
|
suffixIconError: css `
|
|
77
79
|
${statusAffix ? `color: ${token.colorError};` : ""}
|
|
78
80
|
`,
|
|
@@ -82,6 +84,11 @@ const useStyles = createStyles(({ token, css }, props) => {
|
|
|
82
84
|
suffixIconDisabled: css `
|
|
83
85
|
color: ${token.colorTextDisabled};
|
|
84
86
|
`,
|
|
87
|
+
/**
|
|
88
|
+
* antd's borderless/filled status styles colour the value text and are not guarded
|
|
89
|
+
* against the disabled state - pickers keep colorTextDisabled, so match the picker.
|
|
90
|
+
* Applied only for a truly disabled component, never for `inputDisabled` (open popup).
|
|
91
|
+
*/
|
|
85
92
|
disabledText: css `
|
|
86
93
|
&& input[disabled] {
|
|
87
94
|
color: ${token.colorTextDisabled};
|
|
@@ -99,11 +106,17 @@ const DATE_TIME_DATA_MAP = [
|
|
|
99
106
|
{ key: "MM", min: 1, max: 12, unit: "M", part: "M" },
|
|
100
107
|
{ key: "DD", min: 1, max: 31, unit: "d", part: "D" },
|
|
101
108
|
];
|
|
109
|
+
/** numeric mask tokens, longest first so that YYYY is not read as YY */
|
|
102
110
|
const NUMBER_TOKENS = ["SSS", "YYYY", "YY", "DD", "MM", "HH", "mm", "ss"];
|
|
111
|
+
/** UTC-offset tokens mapped to the width dayjs renders them with */
|
|
103
112
|
const OFFSET_TOKENS = [
|
|
104
|
-
{ token: "ZZ", length: 5 },
|
|
105
|
-
{ token: "Z", length: 6 },
|
|
113
|
+
{ token: "ZZ", length: 5 }, // +0200
|
|
114
|
+
{ token: "Z", length: 6 }, // +02:00
|
|
106
115
|
];
|
|
116
|
+
/**
|
|
117
|
+
* MaskedInput format character for the sign of the UTC offset. A letter can never collide with
|
|
118
|
+
* a literal of the generated pattern - letters of the mask are always turned into field slots.
|
|
119
|
+
*/
|
|
107
120
|
const SIGN_FORMAT_CHAR = "S";
|
|
108
121
|
const SIGN_FORMAT_CHARACTERS = {
|
|
109
122
|
[SIGN_FORMAT_CHAR]: { validate: (char) => char === "+" || char === "-" },
|
|
@@ -111,9 +124,14 @@ const SIGN_FORMAT_CHARACTERS = {
|
|
|
111
124
|
const MAX_UTC_OFFSET_MINUTES = 14 * 60;
|
|
112
125
|
const MIN_TIME = dayjs.unix(0);
|
|
113
126
|
const MAX_TIME = dayjs().add(1000, "year");
|
|
127
|
+
/**
|
|
128
|
+
* Globally changes the lowest year accepted in a `YYYY` field of every {@link DateTimeInput} from 1900 to 1902.
|
|
129
|
+
* Stepping and the calendar stay limited to dates from the Unix epoch on.
|
|
130
|
+
*/
|
|
114
131
|
export function allowDatesBeforeEpoch() {
|
|
115
132
|
DATE_TIME_DATA_MAP[4].min = 1902;
|
|
116
133
|
}
|
|
134
|
+
/** the numeric field a mask token belongs to, with the min/max of that particular token */
|
|
117
135
|
function findInfoEntry(token) {
|
|
118
136
|
for (const entry of DATE_TIME_DATA_MAP) {
|
|
119
137
|
if (Array.isArray(entry.key)) {
|
|
@@ -137,9 +155,17 @@ function escapePatternChar(char) {
|
|
|
137
155
|
? ESCAPE_CHAR + char
|
|
138
156
|
: char;
|
|
139
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Walks the mask once and records, for every editable field, where it lands in the value as
|
|
160
|
+
* dayjs renders it. Both the MaskedInput pattern and the parser positions are derived from
|
|
161
|
+
* this, so tokens wider than their mask representation (`Z`, `ZZ`) no longer shift everything
|
|
162
|
+
* that follows them.
|
|
163
|
+
*/
|
|
140
164
|
function buildMaskLayout(mask) {
|
|
141
165
|
const segments = [];
|
|
142
166
|
let pattern = "";
|
|
167
|
+
// kept separately from pattern.length - an escaped literal takes two characters of the
|
|
168
|
+
// pattern source but still only one character of the rendered value
|
|
143
169
|
let renderIndex = 0;
|
|
144
170
|
let i = 0;
|
|
145
171
|
while (i < mask.length) {
|
|
@@ -160,18 +186,35 @@ function buildMaskLayout(mask) {
|
|
|
160
186
|
i += token.length;
|
|
161
187
|
continue;
|
|
162
188
|
}
|
|
189
|
+
// unknown token - keep the historical behaviour of one digit slot per letter
|
|
163
190
|
pattern += /[a-zA-Z]/.test(mask[i]) ? "1" : escapePatternChar(mask[i]);
|
|
164
191
|
renderIndex++;
|
|
165
192
|
i++;
|
|
166
193
|
}
|
|
167
194
|
return { pattern, segments };
|
|
168
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Masked date-time input with a calendar popup - a controlled replacement for antd `DatePicker`.
|
|
198
|
+
* The value is typed field by field according to {@link DateTimeInputProps.mask}; ArrowUp/ArrowDown and the
|
|
199
|
+
* mouse wheel step the field under the cursor. The calendar opens on right-click or via the calendar icon.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* const [value, setValue] = useState<Dayjs | null>(dayjs().startOf("hour"));
|
|
203
|
+
*
|
|
204
|
+
* <DateTimeInput
|
|
205
|
+
* mask={LocaleHolder.getDateTimeFormat(true, true)}
|
|
206
|
+
* value={value}
|
|
207
|
+
* onChange={setValue}
|
|
208
|
+
* allowClear
|
|
209
|
+
* />
|
|
210
|
+
*/
|
|
169
211
|
export default class DateTimeInput extends React.Component {
|
|
170
212
|
constructor(props) {
|
|
171
213
|
var _a, _b, _c, _d;
|
|
172
214
|
super(props);
|
|
173
215
|
this.inputRef = React.createRef();
|
|
174
216
|
this.today = dayjs();
|
|
217
|
+
/** the page must not scroll while the wheel is editing the value */
|
|
175
218
|
this.onWheel = (event) => {
|
|
176
219
|
if (this.props.disabled || this.props.inputDisabled) {
|
|
177
220
|
return;
|
|
@@ -206,6 +249,8 @@ export default class DateTimeInput extends React.Component {
|
|
|
206
249
|
}
|
|
207
250
|
componentDidMount() {
|
|
208
251
|
var _a;
|
|
252
|
+
// React registers `wheel` as a passive listener, so preventDefault() from an onWheel
|
|
253
|
+
// prop is ignored and the page scrolls along with the value - hence a native listener
|
|
209
254
|
(_a = this.input) === null || _a === void 0 ? void 0 : _a.addEventListener("wheel", this.onWheel, { passive: false });
|
|
210
255
|
}
|
|
211
256
|
componentWillUnmount() {
|
|
@@ -221,6 +266,7 @@ export default class DateTimeInput extends React.Component {
|
|
|
221
266
|
}
|
|
222
267
|
}
|
|
223
268
|
}
|
|
269
|
+
/** The underlying `<input>` element, `undefined` before mount or with {@link DateTimeInputProps.renderAsCalendar}. */
|
|
224
270
|
get input() {
|
|
225
271
|
var _a;
|
|
226
272
|
return (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.input;
|
|
@@ -232,6 +278,7 @@ export default class DateTimeInput extends React.Component {
|
|
|
232
278
|
}
|
|
233
279
|
return this.layout;
|
|
234
280
|
}
|
|
281
|
+
/** Moves the keyboard focus to the text input. */
|
|
235
282
|
focus() {
|
|
236
283
|
var _a;
|
|
237
284
|
(_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
@@ -239,6 +286,11 @@ export default class DateTimeInput extends React.Component {
|
|
|
239
286
|
canStep(direction) {
|
|
240
287
|
return this.nextValue(direction) !== undefined;
|
|
241
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* The value one step up/down from the current one, or undefined when the field under the
|
|
291
|
+
* cursor cannot be stepped. Over the UTC-offset field a step means "the other offset of the
|
|
292
|
+
* same wall clock", which only exists inside a DST fold - elsewhere the arrows stay inert.
|
|
293
|
+
*/
|
|
242
294
|
nextValue(direction) {
|
|
243
295
|
const segment = this.state.currentInfo.info;
|
|
244
296
|
const value = this.props.value;
|
|
@@ -272,6 +324,7 @@ export default class DateTimeInput extends React.Component {
|
|
|
272
324
|
}
|
|
273
325
|
(_g = this.inputRef.current) === null || _g === void 0 ? void 0 : _g.focus();
|
|
274
326
|
}
|
|
327
|
+
/** Re-reads the cursor position and the mask field under it; called internally on key up and mouse up. */
|
|
275
328
|
recalc() {
|
|
276
329
|
if (this.inputRef.current !== null) {
|
|
277
330
|
this.setState({
|
|
@@ -286,6 +339,7 @@ export default class DateTimeInput extends React.Component {
|
|
|
286
339
|
decrement() {
|
|
287
340
|
this.step(-1);
|
|
288
341
|
}
|
|
342
|
+
/** Forwards a hovered calendar day to {@link DateTimeInputProps.onDateItemMouseOver}; debounced by 100 ms. */
|
|
289
343
|
onItemMouseOver(itemDate) {
|
|
290
344
|
var _a, _b;
|
|
291
345
|
(_b = (_a = this.props).onDateItemMouseOver) === null || _b === void 0 ? void 0 : _b.call(_a, itemDate);
|
|
@@ -336,6 +390,7 @@ export default class DateTimeInput extends React.Component {
|
|
|
336
390
|
} },
|
|
337
391
|
React.createElement("span", { className: "ant-picker-next-icon" })))));
|
|
338
392
|
}
|
|
393
|
+
/** Renders the calendar panel - the popup content, or the whole component with {@link DateTimeInputProps.renderAsCalendar}. */
|
|
339
394
|
renderCalendar() {
|
|
340
395
|
return (React.createElement("div", { onKeyDown: !this.props.ignoreKeyStrokes ? (e) => {
|
|
341
396
|
var _a, _b, _c, _d;
|
|
@@ -404,10 +459,14 @@ export default class DateTimeInput extends React.Component {
|
|
|
404
459
|
this.setState({ popupCalendarVisible: false });
|
|
405
460
|
} }, i18n("Today")))));
|
|
406
461
|
}
|
|
462
|
+
/** Renders the masked input with its calendar icon, without the popup. */
|
|
407
463
|
renderInput() {
|
|
408
464
|
const _a = this.props, { mask, value, onChange, onInvalidValue, style, disabled, inputDisabled, variant, hidePopup, renderAsCalendar, allowClear, minDateTime, maxDateTime, onDateItemMouseDown, onDateItemMouseOver, onDateItemMouseUp, markedDateInterval, inputStyle, getPopupContainer, autoFocus, className, size, status } = _a, props = __rest(_a, ["mask", "value", "onChange", "onInvalidValue", "style", "disabled", "inputDisabled", "variant", "hidePopup", "renderAsCalendar", "allowClear", "minDateTime", "maxDateTime", "onDateItemMouseDown", "onDateItemMouseOver", "onDateItemMouseUp", "markedDateInterval", "inputStyle", "getPopupContainer", "autoFocus", "className", "size", "status"]);
|
|
409
465
|
const unix = value === null || value === void 0 ? void 0 : value.valueOf();
|
|
466
|
+
// an unparseable input is an error even when the caller reports no status
|
|
410
467
|
const mergedStatus = status || (!this.state.valid ? "error" : "");
|
|
468
|
+
// the root has to stay a plain DOM element - Tooltip in render() clones it to inject
|
|
469
|
+
// its trigger handlers, and a WithCss root would swallow them
|
|
411
470
|
return (React.createElement("div", Object.assign({ style: Object.assign(Object.assign({}, style), { position: "relative" }) }, props, { className: className }),
|
|
412
471
|
React.createElement(WithCss, { useStyles: useStyles, props: { variant } }, ({ styles, cx, theme }) => {
|
|
413
472
|
var _a;
|
|
@@ -417,12 +476,12 @@ export default class DateTimeInput extends React.Component {
|
|
|
417
476
|
}
|
|
418
477
|
return (React.createElement(React.Fragment, null,
|
|
419
478
|
React.createElement("div", { className: cx({ [styles.disabledText]: !!disabled }), onKeyDown: (event) => {
|
|
420
|
-
if (event.code === "ArrowUp") {
|
|
479
|
+
if (event.code === "ArrowUp") { // up
|
|
421
480
|
this.increment();
|
|
422
481
|
event.preventDefault();
|
|
423
482
|
event.stopPropagation();
|
|
424
483
|
}
|
|
425
|
-
else if (event.code === "ArrowDown") {
|
|
484
|
+
else if (event.code === "ArrowDown") { // down
|
|
426
485
|
this.decrement();
|
|
427
486
|
event.preventDefault();
|
|
428
487
|
event.stopPropagation();
|
|
@@ -498,6 +557,7 @@ export default class DateTimeInput extends React.Component {
|
|
|
498
557
|
h: value.hour(), m: value.minute(), s: value.second(), ms: value.millisecond(),
|
|
499
558
|
};
|
|
500
559
|
}
|
|
560
|
+
/** the two instants of a DST fold share the wall clock and differ only in the UTC offset */
|
|
501
561
|
static isSameWallClock(a, b) {
|
|
502
562
|
return a.y === b.y && a.M === b.M && a.D === b.D &&
|
|
503
563
|
a.h === b.h && a.m === b.m && a.s === b.s && a.ms === b.ms;
|
|
@@ -513,6 +573,12 @@ export default class DateTimeInput extends React.Component {
|
|
|
513
573
|
}
|
|
514
574
|
return match[1] === "-" ? -minutes : minutes;
|
|
515
575
|
}
|
|
576
|
+
/**
|
|
577
|
+
* Picks the instant that shows the given wall clock at the given UTC offset. Inside a DST
|
|
578
|
+
* fold two instants share the wall clock and the offset is what tells them apart; inside a
|
|
579
|
+
* DST gap no instant matches, so the value is reported as invalid. A wall clock that does
|
|
580
|
+
* not exist at all (31.02.) is rejected by the same check rather than rolled over.
|
|
581
|
+
*/
|
|
516
582
|
static resolveWallClock(nominal, offsetMinutes) {
|
|
517
583
|
const utcMs = Date.UTC(nominal.y, nominal.M, nominal.D, nominal.h, nominal.m, nominal.s, nominal.ms);
|
|
518
584
|
const candidate = dayjs(utcMs - offsetMinutes * 60000);
|
|
@@ -531,8 +597,11 @@ export default class DateTimeInput extends React.Component {
|
|
|
531
597
|
var _a;
|
|
532
598
|
const invalid = { time: undefined, info: undefined, length: 0 };
|
|
533
599
|
const base = dayjs().startOf("day");
|
|
600
|
+
// fields the mask does not carry keep the value they have in `base`
|
|
534
601
|
const nominal = DateTimeInput.toWallClock(base);
|
|
535
602
|
let time = base;
|
|
603
|
+
// iterated in DATE_TIME_DATA_MAP order, not in mask order - the day has to be set after
|
|
604
|
+
// the year and the month so that it is not clamped by the month it is temporarily in
|
|
536
605
|
for (const v of DATE_TIME_DATA_MAP) {
|
|
537
606
|
const segment = layout.segments.find((s) => s.entry === v);
|
|
538
607
|
if (segment === undefined) {
|
|
@@ -543,15 +612,18 @@ export default class DateTimeInput extends React.Component {
|
|
|
543
612
|
return invalid;
|
|
544
613
|
}
|
|
545
614
|
if (v.unit === "M") {
|
|
546
|
-
val--;
|
|
615
|
+
val--; // 0-11
|
|
547
616
|
}
|
|
548
617
|
if (v.unit === "y" && segment.length === 2) {
|
|
549
|
-
const century = (previousTime != null && previousTime.isValid()) ? Math.floor(previousTime.year() / 100) * 100 : (val > 70 ? 1900 : 2000);
|
|
618
|
+
const century = (previousTime != null && previousTime.isValid()) ? Math.floor(previousTime.year() / 100) * 100 : (val > 70 ? 1900 : 2000); // if short year
|
|
550
619
|
val += century;
|
|
551
620
|
}
|
|
552
621
|
nominal[v.part] = val;
|
|
553
622
|
time = time === null || time === void 0 ? void 0 : time.set(v.unit === "d" ? 'D' : v.unit, val);
|
|
554
623
|
}
|
|
624
|
+
// `time` has already normalised a wall clock that does not exist - when the mask carries
|
|
625
|
+
// the UTC offset, rebuild the instant from the typed reading instead, so that both sides
|
|
626
|
+
// of a DST fold are reachable and a DST gap comes out invalid
|
|
555
627
|
const offsetSegment = layout.segments.find((s) => s.entry === undefined);
|
|
556
628
|
if (offsetSegment !== undefined) {
|
|
557
629
|
const offset = DateTimeInput.parseUtcOffset(value.substring(offsetSegment.index, offsetSegment.index + offsetSegment.length));
|