d2coreui 23.0.44 → 23.0.46
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/components/date/dateRangeInput.d.ts +4 -0
- package/components/date/dateRangeInput.js +315 -46
- package/components/date/dateRangeInput.js.map +1 -1
- package/components/date/dateRangeInputAdvancedPanel.js +22 -7
- package/components/date/dateRangeInputAdvancedPanel.js.map +1 -1
- package/components/date/dateRangeInputConfirm.js +16 -3
- package/components/date/dateRangeInputConfirm.js.map +1 -1
- package/components/date/dateTimeInput.d.ts +37 -6
- package/components/date/dateTimeInput.js +295 -184
- package/components/date/dateTimeInput.js.map +1 -1
- package/components/grid/config/dataGridEditor.d.ts +2 -0
- package/components/grid/config/dataGridEditor.js +7 -0
- package/components/grid/config/dataGridEditor.js.map +1 -1
- package/components/grid/dataGrid.d.ts +4 -0
- package/components/grid/dataGrid.js +25 -11
- package/components/grid/dataGrid.js.map +1 -1
- package/components/grid/export/contextMenu.d.ts +1 -0
- package/components/grid/export/contextMenu.js.map +1 -1
- package/components/grid/extendedDataGrid.d.ts +2 -0
- package/components/grid/extendedDataGrid.js +4 -0
- package/components/grid/extendedDataGrid.js.map +1 -1
- package/components/input/maskedInput.d.ts +13 -13
- package/components/modal/impl/draggableModal.d.ts +1 -1
- package/components/modal/impl/draggableModal.js +0 -1
- package/components/modal/impl/draggableModal.js.map +1 -1
- package/components/modal/impl/draggableModalInner.d.ts +1 -1
- package/components/modal/impl/draggableModalInner.js +28 -5
- package/components/modal/impl/draggableModalInner.js.map +1 -1
- package/components/modal/impl/draggableModalReducer.d.ts +10 -0
- package/components/modal/impl/draggableModalReducer.js +18 -1
- package/components/modal/impl/draggableModalReducer.js.map +1 -1
- package/components/modal/impl/draggableModalStyles.d.ts +19 -0
- package/components/modal/impl/draggableModalStyles.js +140 -0
- package/components/modal/impl/draggableModalStyles.js.map +1 -0
- package/components/modal/impl/resizeHandle.d.ts +4 -2
- package/components/modal/impl/resizeHandle.js +16 -3
- package/components/modal/impl/resizeHandle.js.map +1 -1
- package/components/modal/modalDialog.d.ts +3 -8
- package/components/modal/modalDialog.js.map +1 -1
- package/components/style/withCss.d.ts +14 -4
- package/components/style/withCss.js +6 -2
- package/components/style/withCss.js.map +1 -1
- package/i18n/components.cs.json +3 -0
- package/i18n/components.sk.json +3 -0
- package/i18n/components.uk.json +3 -0
- package/package.json +1 -1
- package/style/modal/DraggableModal.css +0 -40
- package/style/modal/ResizeHandle.css +0 -27
|
@@ -22,7 +22,9 @@ import { D2000UnixTimeNullValue } from "d2core/types/unixTimeUtils";
|
|
|
22
22
|
import { createStyles } from "antd-style";
|
|
23
23
|
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
|
+
const useStyles = createStyles(({ token, css }, props) => {
|
|
27
|
+
const statusAffix = props.variant !== "borderless";
|
|
26
28
|
return {
|
|
27
29
|
dateTimeInputCalendar: css `
|
|
28
30
|
// adaptations of date-picker calendar styles
|
|
@@ -38,8 +40,8 @@ const useStyles = createStyles(({ token, css, cx }) => {
|
|
|
38
40
|
bottom: 0;
|
|
39
41
|
left: 0;
|
|
40
42
|
z-index: 1;
|
|
41
|
-
border:
|
|
42
|
-
border-radius:
|
|
43
|
+
border: ${token.lineWidth}px ${token.lineType} ${token.colorPrimary};
|
|
44
|
+
border-radius: ${token.borderRadiusSM}px;
|
|
43
45
|
content: '';
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -47,46 +49,144 @@ const useStyles = createStyles(({ token, css, cx }) => {
|
|
|
47
49
|
user-select: none;
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
// plays the role of antd's selected cell
|
|
50
53
|
.date-picker-item-marked {
|
|
51
|
-
color:
|
|
52
|
-
background:
|
|
54
|
+
color: ${token.colorTextLightSolid};
|
|
55
|
+
background: ${token.colorPrimary};
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
.ant-picker-cell-in-view.ant-picker-cell-today .ant-picker-cell-inner::before {
|
|
56
|
-
border:
|
|
59
|
+
border: ${token.lineWidth}px ${token.lineType} ${token.colorPrimary};
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
// antd's cellHoverBg, text colour is left untouched on hover
|
|
59
63
|
.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 {
|
|
60
|
-
background:
|
|
61
|
-
color: rgba(0, 0, 0, 0.85);
|
|
64
|
+
background: ${token.controlItemBgHover};
|
|
62
65
|
}
|
|
63
|
-
|
|
66
|
+
|
|
64
67
|
.ant-picker-body {
|
|
65
68
|
padding-bottom: 0 !important;
|
|
66
69
|
}
|
|
67
70
|
`,
|
|
71
|
+
suffixIcon: css `
|
|
72
|
+
color: ${token.colorTextQuaternary};
|
|
73
|
+
vertical-align: middle;
|
|
74
|
+
height: 100%;
|
|
75
|
+
`,
|
|
76
|
+
suffixIconError: css `
|
|
77
|
+
${statusAffix ? `color: ${token.colorError};` : ""}
|
|
78
|
+
`,
|
|
79
|
+
suffixIconWarning: css `
|
|
80
|
+
${statusAffix ? `color: ${token.colorWarning};` : ""}
|
|
81
|
+
`,
|
|
82
|
+
suffixIconDisabled: css `
|
|
83
|
+
color: ${token.colorTextDisabled};
|
|
84
|
+
`,
|
|
85
|
+
disabledText: css `
|
|
86
|
+
&& input[disabled] {
|
|
87
|
+
color: ${token.colorTextDisabled};
|
|
88
|
+
-webkit-text-fill-color: ${token.colorTextDisabled};
|
|
89
|
+
}
|
|
90
|
+
`,
|
|
68
91
|
};
|
|
69
92
|
});
|
|
70
93
|
const DATE_TIME_DATA_MAP = [
|
|
71
|
-
{ key: "SSS", min: 0, max: 999, unit: "ms" },
|
|
72
|
-
{ key: "ss", min: 0, max: 59, unit: "s" },
|
|
73
|
-
{ key: "mm", min: 0, max: 59, unit: "m" },
|
|
74
|
-
{ key: "HH", min: 0, max: 23, unit: "h" },
|
|
75
|
-
{ key: ["YYYY", "YY"], min: [1900, 0], max: [9999, 99], unit: "y" },
|
|
76
|
-
{ key: "MM", min: 1, max: 12, unit: "M" },
|
|
77
|
-
{ key: "DD", min: 1, max: 31, unit: "d" },
|
|
94
|
+
{ key: "SSS", min: 0, max: 999, unit: "ms", part: "ms" },
|
|
95
|
+
{ key: "ss", min: 0, max: 59, unit: "s", part: "s" },
|
|
96
|
+
{ key: "mm", min: 0, max: 59, unit: "m", part: "m" },
|
|
97
|
+
{ key: "HH", min: 0, max: 23, unit: "h", part: "h" },
|
|
98
|
+
{ key: ["YYYY", "YY"], min: [1900, 0], max: [9999, 99], unit: "y", part: "y" },
|
|
99
|
+
{ key: "MM", min: 1, max: 12, unit: "M", part: "M" },
|
|
100
|
+
{ key: "DD", min: 1, max: 31, unit: "d", part: "D" },
|
|
101
|
+
];
|
|
102
|
+
const NUMBER_TOKENS = ["SSS", "YYYY", "YY", "DD", "MM", "HH", "mm", "ss"];
|
|
103
|
+
const OFFSET_TOKENS = [
|
|
104
|
+
{ token: "ZZ", length: 5 },
|
|
105
|
+
{ token: "Z", length: 6 },
|
|
78
106
|
];
|
|
107
|
+
const SIGN_FORMAT_CHAR = "S";
|
|
108
|
+
const SIGN_FORMAT_CHARACTERS = {
|
|
109
|
+
[SIGN_FORMAT_CHAR]: { validate: (char) => char === "+" || char === "-" },
|
|
110
|
+
};
|
|
111
|
+
const MAX_UTC_OFFSET_MINUTES = 14 * 60;
|
|
79
112
|
const MIN_TIME = dayjs.unix(0);
|
|
80
113
|
const MAX_TIME = dayjs().add(1000, "year");
|
|
81
114
|
export function allowDatesBeforeEpoch() {
|
|
82
115
|
DATE_TIME_DATA_MAP[4].min = 1902;
|
|
83
116
|
}
|
|
117
|
+
function findInfoEntry(token) {
|
|
118
|
+
for (const entry of DATE_TIME_DATA_MAP) {
|
|
119
|
+
if (Array.isArray(entry.key)) {
|
|
120
|
+
const i = entry.key.indexOf(token);
|
|
121
|
+
if (i !== -1) {
|
|
122
|
+
return {
|
|
123
|
+
entry,
|
|
124
|
+
min: Array.isArray(entry.min) ? entry.min[i] : entry.min,
|
|
125
|
+
max: Array.isArray(entry.max) ? entry.max[i] : entry.max,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (entry.key === token) {
|
|
130
|
+
return { entry, min: entry.min, max: entry.max };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
function escapePatternChar(char) {
|
|
136
|
+
return char in DEFAULT_FORMAT_CHARACTERS || char === SIGN_FORMAT_CHAR || char === ESCAPE_CHAR
|
|
137
|
+
? ESCAPE_CHAR + char
|
|
138
|
+
: char;
|
|
139
|
+
}
|
|
140
|
+
function buildMaskLayout(mask) {
|
|
141
|
+
const segments = [];
|
|
142
|
+
let pattern = "";
|
|
143
|
+
let renderIndex = 0;
|
|
144
|
+
let i = 0;
|
|
145
|
+
while (i < mask.length) {
|
|
146
|
+
const offset = OFFSET_TOKENS.find((t) => mask.startsWith(t.token, i));
|
|
147
|
+
if (offset !== undefined) {
|
|
148
|
+
segments.push({ token: offset.token, index: renderIndex, length: offset.length, entry: undefined, min: 0, max: 0 });
|
|
149
|
+
pattern += SIGN_FORMAT_CHAR + (offset.length === 6 ? "11:11" : "1111");
|
|
150
|
+
renderIndex += offset.length;
|
|
151
|
+
i += offset.token.length;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const token = NUMBER_TOKENS.find((t) => mask.startsWith(t, i));
|
|
155
|
+
const found = token !== undefined ? findInfoEntry(token) : undefined;
|
|
156
|
+
if (token !== undefined && found !== undefined) {
|
|
157
|
+
segments.push({ token, index: renderIndex, length: token.length, entry: found.entry, min: found.min, max: found.max });
|
|
158
|
+
pattern += "1".repeat(token.length);
|
|
159
|
+
renderIndex += token.length;
|
|
160
|
+
i += token.length;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
pattern += /[a-zA-Z]/.test(mask[i]) ? "1" : escapePatternChar(mask[i]);
|
|
164
|
+
renderIndex++;
|
|
165
|
+
i++;
|
|
166
|
+
}
|
|
167
|
+
return { pattern, segments };
|
|
168
|
+
}
|
|
84
169
|
export default class DateTimeInput extends React.Component {
|
|
85
170
|
constructor(props) {
|
|
86
171
|
var _a, _b, _c, _d;
|
|
87
172
|
super(props);
|
|
88
173
|
this.inputRef = React.createRef();
|
|
89
174
|
this.today = dayjs();
|
|
175
|
+
this.onWheel = (event) => {
|
|
176
|
+
if (this.props.disabled || this.props.inputDisabled) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (event.deltaY > 0 && this.canStep(-1)) {
|
|
180
|
+
this.decrement();
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
}
|
|
183
|
+
else if (event.deltaY < 0 && this.canStep(1)) {
|
|
184
|
+
this.increment();
|
|
185
|
+
event.preventDefault();
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
this.layoutMask = props.mask;
|
|
189
|
+
this.layout = buildMaskLayout(props.mask);
|
|
90
190
|
this.state = {
|
|
91
191
|
valid: DateTimeInput.isValidValue(props.value, props.minDateTime, props.maxDateTime, props.allowClear),
|
|
92
192
|
currentPos: null,
|
|
@@ -104,6 +204,14 @@ export default class DateTimeInput extends React.Component {
|
|
|
104
204
|
this.decrement = this.decrement.bind(this);
|
|
105
205
|
this.onItemMouseOver = debounce(this.onItemMouseOver.bind(this), 100, { maxWait: 100 });
|
|
106
206
|
}
|
|
207
|
+
componentDidMount() {
|
|
208
|
+
var _a;
|
|
209
|
+
(_a = this.input) === null || _a === void 0 ? void 0 : _a.addEventListener("wheel", this.onWheel, { passive: false });
|
|
210
|
+
}
|
|
211
|
+
componentWillUnmount() {
|
|
212
|
+
var _a;
|
|
213
|
+
(_a = this.input) === null || _a === void 0 ? void 0 : _a.removeEventListener("wheel", this.onWheel);
|
|
214
|
+
}
|
|
107
215
|
componentDidUpdate(prevProps, _prevState, _snapshot) {
|
|
108
216
|
if (!isEqual(prevProps, this.props) && this.inputRef.current !== null) {
|
|
109
217
|
this.inputRef.current.input.selectionStart = this.state.currentPos;
|
|
@@ -117,57 +225,66 @@ export default class DateTimeInput extends React.Component {
|
|
|
117
225
|
var _a;
|
|
118
226
|
return (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.input;
|
|
119
227
|
}
|
|
228
|
+
getLayout() {
|
|
229
|
+
if (this.layoutMask !== this.props.mask) {
|
|
230
|
+
this.layoutMask = this.props.mask;
|
|
231
|
+
this.layout = buildMaskLayout(this.props.mask);
|
|
232
|
+
}
|
|
233
|
+
return this.layout;
|
|
234
|
+
}
|
|
120
235
|
focus() {
|
|
121
236
|
var _a;
|
|
122
237
|
(_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
123
238
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.setState({
|
|
127
|
-
currentInfo: DateTimeInput.parseDateTimeFormat(this.props.value, this.inputRef.current.input.value, this.props.mask, this.inputRef.current.input.selectionStart),
|
|
128
|
-
currentPos: this.inputRef.current.input.selectionStart,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
239
|
+
canStep(direction) {
|
|
240
|
+
return this.nextValue(direction) !== undefined;
|
|
131
241
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
242
|
+
nextValue(direction) {
|
|
243
|
+
const segment = this.state.currentInfo.info;
|
|
244
|
+
const value = this.props.value;
|
|
245
|
+
const step = direction > 0 ? 1 : -1;
|
|
246
|
+
if (segment === undefined || !value) {
|
|
247
|
+
return undefined;
|
|
137
248
|
}
|
|
138
|
-
(
|
|
249
|
+
if (segment.entry === undefined) {
|
|
250
|
+
const candidate = value.clone().add(step, "h");
|
|
251
|
+
return DateTimeInput.isSameWallClock(DateTimeInput.toWallClock(candidate), DateTimeInput.toWallClock(value))
|
|
252
|
+
? candidate
|
|
253
|
+
: undefined;
|
|
254
|
+
}
|
|
255
|
+
return DateTimeInput.checkDateValueValidity(value, step, segment.entry.unit)
|
|
256
|
+
? value.clone().add(step, segment.entry.unit)
|
|
257
|
+
: undefined;
|
|
139
258
|
}
|
|
140
|
-
|
|
141
|
-
var _a, _b, _c, _d, _e;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (!!this.props.maxDateTime &&
|
|
145
|
-
(_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a,
|
|
259
|
+
step(direction) {
|
|
260
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
261
|
+
const next = this.nextValue(direction);
|
|
262
|
+
if (next !== undefined) {
|
|
263
|
+
if (!!this.props.maxDateTime && next.isAfter(this.props.maxDateTime)) {
|
|
264
|
+
(_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.maxDateTime.clone());
|
|
265
|
+
}
|
|
266
|
+
else if (!!this.props.minDateTime && next.isBefore(this.props.minDateTime)) {
|
|
267
|
+
(_d = (_c = this.props).onChange) === null || _d === void 0 ? void 0 : _d.call(_c, this.props.minDateTime.clone());
|
|
146
268
|
}
|
|
147
269
|
else {
|
|
148
|
-
(
|
|
270
|
+
(_f = (_e = this.props).onChange) === null || _f === void 0 ? void 0 : _f.call(_e, next);
|
|
149
271
|
}
|
|
150
272
|
}
|
|
273
|
+
(_g = this.inputRef.current) === null || _g === void 0 ? void 0 : _g.focus();
|
|
151
274
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
275
|
+
recalc() {
|
|
276
|
+
if (this.inputRef.current !== null) {
|
|
277
|
+
this.setState({
|
|
278
|
+
currentInfo: DateTimeInput.parseDateTimeFormat(this.props.value, this.inputRef.current.input.value, this.getLayout(), this.inputRef.current.input.selectionStart),
|
|
279
|
+
currentPos: this.inputRef.current.input.selectionStart,
|
|
280
|
+
});
|
|
157
281
|
}
|
|
158
|
-
(_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
159
282
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
(_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());
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
(_e = (_d = this.props).onChange) === null || _e === void 0 ? void 0 : _e.call(_d, value);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
283
|
+
increment() {
|
|
284
|
+
this.step(1);
|
|
285
|
+
}
|
|
286
|
+
decrement() {
|
|
287
|
+
this.step(-1);
|
|
171
288
|
}
|
|
172
289
|
onItemMouseOver(itemDate) {
|
|
173
290
|
var _a, _b;
|
|
@@ -288,80 +405,75 @@ export default class DateTimeInput extends React.Component {
|
|
|
288
405
|
} }, i18n("Today")))));
|
|
289
406
|
}
|
|
290
407
|
renderInput() {
|
|
291
|
-
|
|
292
|
-
const _b = this.props, { mask, value, onChange, onInvalidValue, style, disabled, inputDisabled, variant, 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", "variant", "hidePopup", "renderAsCalendar", "allowClear", "minDateTime", "maxDateTime", "onDateItemMouseDown", "onDateItemMouseOver", "onDateItemMouseUp", "markedDateInterval", "inputStyle", "getPopupContainer", "autoFocus", "className", "size"]);
|
|
293
|
-
const isUpDisabled = disabled || this.state.currentInfo.info === undefined || !DateTimeInput.isValid(this.state.currentInfo, this.props.value, 1);
|
|
294
|
-
const isDownDisabled = disabled || this.state.currentInfo.info === undefined || !DateTimeInput.isValid(this.state.currentInfo, this.props.value, -1);
|
|
408
|
+
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"]);
|
|
295
409
|
const unix = value === null || value === void 0 ? void 0 : value.valueOf();
|
|
296
|
-
const
|
|
297
|
-
if (inputStyle) {
|
|
298
|
-
Object.assign(maskedInputStyle, inputStyle);
|
|
299
|
-
}
|
|
410
|
+
const mergedStatus = status || (!this.state.valid ? "error" : "");
|
|
300
411
|
return (React.createElement("div", Object.assign({ style: Object.assign(Object.assign({}, style), { position: "relative" }) }, props, { className: className }),
|
|
301
|
-
React.createElement(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
this.setState({ focused: true });
|
|
316
|
-
}), onBlur: () => {
|
|
317
|
-
this.setState({ focused: false });
|
|
318
|
-
}, autoFocus: autoFocus, disabled: disabled || inputDisabled, onWheel: (event) => {
|
|
319
|
-
if (event.deltaY > 0) {
|
|
320
|
-
if (!isDownDisabled) {
|
|
412
|
+
React.createElement(WithCss, { useStyles: useStyles, props: { variant } }, ({ styles, cx, theme }) => {
|
|
413
|
+
var _a;
|
|
414
|
+
const maskedInputStyle = !this.state.valid ? { color: theme.colorError } : {};
|
|
415
|
+
if (inputStyle) {
|
|
416
|
+
Object.assign(maskedInputStyle, inputStyle);
|
|
417
|
+
}
|
|
418
|
+
return (React.createElement(React.Fragment, null,
|
|
419
|
+
React.createElement("div", { className: cx({ [styles.disabledText]: !!disabled }), onKeyDown: (event) => {
|
|
420
|
+
if (event.code === "ArrowUp") {
|
|
421
|
+
this.increment();
|
|
422
|
+
event.preventDefault();
|
|
423
|
+
event.stopPropagation();
|
|
424
|
+
}
|
|
425
|
+
else if (event.code === "ArrowDown") {
|
|
321
426
|
this.decrement();
|
|
427
|
+
event.preventDefault();
|
|
428
|
+
event.stopPropagation();
|
|
322
429
|
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
this.
|
|
430
|
+
} },
|
|
431
|
+
React.createElement(MaskedInput, { mask: this.getLayout().pattern, formatCharacters: SIGN_FORMAT_CHARACTERS, variant: variant, status: mergedStatus, 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 => {
|
|
432
|
+
event.target.selectionStart = event.target.selectionEnd = this.state.currentPos;
|
|
433
|
+
this.setState({ focused: true });
|
|
434
|
+
}), onBlur: () => {
|
|
435
|
+
this.setState({ focused: false });
|
|
436
|
+
}, autoFocus: autoFocus, disabled: disabled || inputDisabled, onMouseUp: this.recalc, onKeyUp: this.recalc, onChange: (event) => {
|
|
437
|
+
const inputString = event.target.value;
|
|
438
|
+
const value = DateTimeInput.parseDateTimeFormat(this.props.value, inputString, this.getLayout(), event.target.selectionStart);
|
|
439
|
+
const valid = DateTimeInput.isValidValue(value.time, this.props.minDateTime, this.props.maxDateTime, this.props.allowClear) || (!!this.props.allowClear && !inputString);
|
|
440
|
+
if (value.time !== undefined && valid) {
|
|
441
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value.time.clone());
|
|
442
|
+
}
|
|
443
|
+
else if (!!this.props.allowClear && !inputString) {
|
|
444
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(null);
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
onInvalidValue === null || onInvalidValue === void 0 ? void 0 : onInvalidValue(inputString);
|
|
448
|
+
}
|
|
449
|
+
this.setState({
|
|
450
|
+
valid: valid,
|
|
451
|
+
currentInfo: value
|
|
452
|
+
});
|
|
453
|
+
} })),
|
|
454
|
+
!hidePopup && !renderAsCalendar && React.createElement("div", { style: {
|
|
455
|
+
width: 28,
|
|
456
|
+
opacity: 1,
|
|
457
|
+
height: "100%",
|
|
458
|
+
textAlign: "center",
|
|
459
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
460
|
+
background: "transparent",
|
|
461
|
+
position: "absolute",
|
|
462
|
+
top: 0,
|
|
463
|
+
right: 0,
|
|
464
|
+
}, onClick: (event) => {
|
|
465
|
+
if (document.createEvent) {
|
|
466
|
+
var ev = document.createEvent('HTMLEvents');
|
|
467
|
+
ev.initEvent('contextmenu', true, false);
|
|
468
|
+
event.target.dispatchEvent(ev);
|
|
327
469
|
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
else if (!!this.props.allowClear && !inputString) {
|
|
337
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(null);
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
onInvalidValue === null || onInvalidValue === void 0 ? void 0 : onInvalidValue(inputString);
|
|
341
|
-
}
|
|
342
|
-
this.setState({
|
|
343
|
-
valid: valid,
|
|
344
|
-
currentInfo: value
|
|
345
|
-
});
|
|
346
|
-
} })),
|
|
347
|
-
!hidePopup && !renderAsCalendar && React.createElement("div", { style: {
|
|
348
|
-
width: 28,
|
|
349
|
-
opacity: 1,
|
|
350
|
-
height: "100%",
|
|
351
|
-
textAlign: "center",
|
|
352
|
-
cursor: disabled ? "not-allowed" : "pointer",
|
|
353
|
-
background: "transparent",
|
|
354
|
-
position: "absolute",
|
|
355
|
-
top: 0,
|
|
356
|
-
right: 0,
|
|
357
|
-
}, onClick: (event) => {
|
|
358
|
-
if (document.createEvent) {
|
|
359
|
-
var ev = document.createEvent('HTMLEvents');
|
|
360
|
-
ev.initEvent('contextmenu', true, false);
|
|
361
|
-
event.target.dispatchEvent(ev);
|
|
362
|
-
}
|
|
363
|
-
} },
|
|
364
|
-
React.createElement(CalendarOutlined, { style: { color: "rgba(0,0,0,0.65)", verticalAlign: "middle", height: "100%" } }))));
|
|
470
|
+
} },
|
|
471
|
+
React.createElement(CalendarOutlined, { className: cx(styles.suffixIcon, {
|
|
472
|
+
[styles.suffixIconError]: !disabled && mergedStatus === "error",
|
|
473
|
+
[styles.suffixIconWarning]: !disabled && mergedStatus === "warning",
|
|
474
|
+
[styles.suffixIconDisabled]: !!disabled,
|
|
475
|
+
}) }))));
|
|
476
|
+
})));
|
|
365
477
|
}
|
|
366
478
|
render() {
|
|
367
479
|
if (this.props.renderAsCalendar) {
|
|
@@ -371,19 +483,42 @@ export default class DateTimeInput extends React.Component {
|
|
|
371
483
|
return this.renderInput();
|
|
372
484
|
}
|
|
373
485
|
else {
|
|
374
|
-
return (React.createElement(Tooltip, { color:
|
|
486
|
+
return (React.createElement(WithCss, { useStyles: useStyles }, ({ theme }) => React.createElement(Tooltip, { color: theme.colorBgElevated, trigger: this.props.disabled ? [] : ["contextMenu"], getPopupContainer: this.props.getPopupContainer, styles: { body: { maxHeight: "100vh", overflowY: "auto", overflowX: "hidden", width: 266 } }, open: this.state.popupCalendarVisible, onOpenChange: (visible) => {
|
|
375
487
|
var _a, _b, _c, _d;
|
|
376
488
|
this.setState({ popupCalendarVisible: visible });
|
|
377
489
|
if (visible) {
|
|
378
490
|
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") });
|
|
379
491
|
}
|
|
380
|
-
}, title: this.renderCalendar(), placement: this.props.placement }, this.renderInput()));
|
|
492
|
+
}, title: this.renderCalendar(), placement: this.props.placement }, this.renderInput())));
|
|
381
493
|
}
|
|
382
494
|
}
|
|
383
|
-
static
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
495
|
+
static toWallClock(value) {
|
|
496
|
+
return {
|
|
497
|
+
y: value.year(), M: value.month(), D: value.date(),
|
|
498
|
+
h: value.hour(), m: value.minute(), s: value.second(), ms: value.millisecond(),
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
static isSameWallClock(a, b) {
|
|
502
|
+
return a.y === b.y && a.M === b.M && a.D === b.D &&
|
|
503
|
+
a.h === b.h && a.m === b.m && a.s === b.s && a.ms === b.ms;
|
|
504
|
+
}
|
|
505
|
+
static parseUtcOffset(text) {
|
|
506
|
+
const match = /^([+-])(\d{2}):?(\d{2})$/.exec(text);
|
|
507
|
+
if (match === null) {
|
|
508
|
+
return undefined;
|
|
509
|
+
}
|
|
510
|
+
const minutes = Number(match[2]) * 60 + Number(match[3]);
|
|
511
|
+
if (Number(match[3]) > 59 || minutes > MAX_UTC_OFFSET_MINUTES) {
|
|
512
|
+
return undefined;
|
|
513
|
+
}
|
|
514
|
+
return match[1] === "-" ? -minutes : minutes;
|
|
515
|
+
}
|
|
516
|
+
static resolveWallClock(nominal, offsetMinutes) {
|
|
517
|
+
const utcMs = Date.UTC(nominal.y, nominal.M, nominal.D, nominal.h, nominal.m, nominal.s, nominal.ms);
|
|
518
|
+
const candidate = dayjs(utcMs - offsetMinutes * 60000);
|
|
519
|
+
return candidate.utcOffset() === offsetMinutes && DateTimeInput.isSameWallClock(DateTimeInput.toWallClock(candidate), nominal)
|
|
520
|
+
? candidate
|
|
521
|
+
: undefined;
|
|
387
522
|
}
|
|
388
523
|
static checkDateValueValidity(value, offset, unit) {
|
|
389
524
|
if (value === null) {
|
|
@@ -392,66 +527,42 @@ export default class DateTimeInput extends React.Component {
|
|
|
392
527
|
let v = value.clone().add(offset, unit);
|
|
393
528
|
return v.isValid() && v.isSameOrAfter(dayjs(0));
|
|
394
529
|
}
|
|
395
|
-
static parseDateTimeFormat(previousTime, value,
|
|
396
|
-
var _a
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
let min = 0;
|
|
406
|
-
let max = 0;
|
|
407
|
-
if (Array.isArray(v.key) || Array.isArray(v.min) || Array.isArray(v.max)) {
|
|
408
|
-
for (let i = 0; i < v.key.length; i++) {
|
|
409
|
-
const x = v.key[i];
|
|
410
|
-
index = mask.indexOf(x);
|
|
411
|
-
if (index !== -1) {
|
|
412
|
-
length = x.length;
|
|
413
|
-
min = v.min[i];
|
|
414
|
-
max = v.max[i];
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
530
|
+
static parseDateTimeFormat(previousTime, value, layout, cursorPos) {
|
|
531
|
+
var _a;
|
|
532
|
+
const invalid = { time: undefined, info: undefined, length: 0 };
|
|
533
|
+
const base = dayjs().startOf("day");
|
|
534
|
+
const nominal = DateTimeInput.toWallClock(base);
|
|
535
|
+
let time = base;
|
|
536
|
+
for (const v of DATE_TIME_DATA_MAP) {
|
|
537
|
+
const segment = layout.segments.find((s) => s.entry === v);
|
|
538
|
+
if (segment === undefined) {
|
|
539
|
+
continue;
|
|
418
540
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
min = v.min;
|
|
423
|
-
max = v.max;
|
|
541
|
+
let val = Number(value.substring(segment.index, segment.index + segment.length));
|
|
542
|
+
if (isNaN(val) || val < segment.min || val > segment.max) {
|
|
543
|
+
return invalid;
|
|
424
544
|
}
|
|
425
|
-
if (
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
if (v.unit === "d") {
|
|
432
|
-
result.time = (_a = result.time) === null || _a === void 0 ? void 0 : _a.set('D', val);
|
|
433
|
-
}
|
|
434
|
-
else if (v.unit === "y" && length === 2) {
|
|
435
|
-
const century = (previousTime != null && previousTime.isValid()) ? Math.floor(previousTime.year() / 100) * 100 : (val > 70 ? 1900 : 2000);
|
|
436
|
-
result.time = (_b = result.time) === null || _b === void 0 ? void 0 : _b.set(v.unit, century + val);
|
|
437
|
-
}
|
|
438
|
-
else if (v.unit !== "weeks" && v.unit !== "week" && v.unit !== "w") {
|
|
439
|
-
result.time = (_c = result.time) === null || _c === void 0 ? void 0 : _c.set(v.unit, val);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
else {
|
|
443
|
-
result.time = undefined;
|
|
444
|
-
result.info = undefined;
|
|
445
|
-
result.length = 0;
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
if (cursorPos !== null && cursorPos >= index && cursorPos <= index + length) {
|
|
449
|
-
result.info = v;
|
|
450
|
-
result.length = length;
|
|
451
|
-
}
|
|
545
|
+
if (v.unit === "M") {
|
|
546
|
+
val--;
|
|
547
|
+
}
|
|
548
|
+
if (v.unit === "y" && segment.length === 2) {
|
|
549
|
+
const century = (previousTime != null && previousTime.isValid()) ? Math.floor(previousTime.year() / 100) * 100 : (val > 70 ? 1900 : 2000);
|
|
550
|
+
val += century;
|
|
452
551
|
}
|
|
552
|
+
nominal[v.part] = val;
|
|
553
|
+
time = time === null || time === void 0 ? void 0 : time.set(v.unit === "d" ? 'D' : v.unit, val);
|
|
554
|
+
}
|
|
555
|
+
const offsetSegment = layout.segments.find((s) => s.entry === undefined);
|
|
556
|
+
if (offsetSegment !== undefined) {
|
|
557
|
+
const offset = DateTimeInput.parseUtcOffset(value.substring(offsetSegment.index, offsetSegment.index + offsetSegment.length));
|
|
558
|
+
time = offset === undefined ? undefined : DateTimeInput.resolveWallClock(nominal, offset);
|
|
559
|
+
}
|
|
560
|
+
if (time === undefined) {
|
|
561
|
+
return invalid;
|
|
453
562
|
}
|
|
454
|
-
|
|
563
|
+
const current = cursorPos === null ? undefined
|
|
564
|
+
: layout.segments.find((s) => cursorPos >= s.index && cursorPos <= s.index + s.length);
|
|
565
|
+
return { time, info: current, length: (_a = current === null || current === void 0 ? void 0 : current.length) !== null && _a !== void 0 ? _a : 0 };
|
|
455
566
|
}
|
|
456
567
|
static isValidValue(value, minDateTime, maxDateTime, allowClear) {
|
|
457
568
|
return (!!value && value.isValid() && (!minDateTime || value.isSameOrAfter(minDateTime)) && (!maxDateTime || value.isSameOrBefore(maxDateTime))) || (!!allowClear && value === null);
|