pixelize-design-library 2.2.43 → 2.2.45
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/dist/Components/DatePicker/CalendarPanel.d.ts +22 -0
- package/dist/Components/DatePicker/CalendarPanel.js +104 -0
- package/dist/Components/DatePicker/DatePicker.js +9 -120
- package/dist/Components/DatePicker/RangeDatePicker.d.ts +4 -0
- package/dist/Components/DatePicker/RangeDatePicker.js +205 -0
- package/dist/Components/DatePicker/SingleDatePicker.d.ts +4 -0
- package/dist/Components/DatePicker/SingleDatePicker.js +988 -0
- package/dist/Components/DatePicker/ThemeDatePicker.d.ts +4 -0
- package/dist/Components/DatePicker/ThemeDatePicker.js +43 -0
- package/dist/Components/DatePicker/TimeOnlyPicker.d.ts +4 -0
- package/dist/Components/DatePicker/TimeOnlyPicker.js +119 -0
- package/dist/Components/DatePicker/TimePickerInput.d.ts +12 -0
- package/dist/Components/DatePicker/TimePickerInput.js +362 -0
- package/dist/Components/NoteTextArea/NoteTextArea.d.ts +1 -1
- package/dist/Components/NoteTextArea/NoteTextArea.js +9 -9
- package/dist/Components/NoteTextArea/NoteTextAreaProps.d.ts +1 -0
- package/dist/Components/Table/Components/HeaderActions.js +41 -9
- package/dist/Theme/Meadow/palette.js +17 -17
- package/dist/Theme/Radiant/palette.js +34 -34
- package/dist/Theme/Skyline/palette.js +17 -17
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,988 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.SingleDatePicker = void 0;
|
|
30
|
+
var react_1 = __importStar(require("react"));
|
|
31
|
+
var react_2 = require("@chakra-ui/react");
|
|
32
|
+
var date_fns_1 = require("date-fns");
|
|
33
|
+
var lucide_react_1 = require("lucide-react");
|
|
34
|
+
var Button_1 = __importDefault(require("../Button/Button"));
|
|
35
|
+
var useCustomTheme_1 = require("../../Theme/useCustomTheme");
|
|
36
|
+
var FormLabel_1 = require("../Common/FormLabel");
|
|
37
|
+
var HelperText_1 = __importDefault(require("../Common/HelperText"));
|
|
38
|
+
var ErrorMessage_1 = __importDefault(require("../Common/ErrorMessage"));
|
|
39
|
+
var TimePicker_1 = __importDefault(require("./TimePicker"));
|
|
40
|
+
var TimePickerInput_1 = require("./TimePickerInput");
|
|
41
|
+
var CalendarPanel_1 = __importDefault(require("./CalendarPanel"));
|
|
42
|
+
var TOKEN_CHARS = /[dMyHhmsaAm]/;
|
|
43
|
+
var getPlaceholderForToken = function (token, length) {
|
|
44
|
+
var lower = token.toLowerCase();
|
|
45
|
+
switch (lower) {
|
|
46
|
+
case "d":
|
|
47
|
+
return token.toLowerCase() === token ? "d".repeat(Math.min(Math.max(length, 2), 4)) : "D".repeat(Math.min(Math.max(length, 2), 4));
|
|
48
|
+
case "m":
|
|
49
|
+
if (token === "M") {
|
|
50
|
+
return "M".repeat(Math.max(length, 2));
|
|
51
|
+
}
|
|
52
|
+
return "m".repeat(Math.max(length, 2));
|
|
53
|
+
case "y":
|
|
54
|
+
return token === token.toUpperCase() ? "Y".repeat(length >= 4 ? 4 : 2) : "y".repeat(length >= 4 ? 4 : 2);
|
|
55
|
+
case "h":
|
|
56
|
+
return token === token.toUpperCase() ? "H".repeat(Math.max(length, 2)) : "h".repeat(Math.max(length, 2));
|
|
57
|
+
case "s":
|
|
58
|
+
return token === token.toUpperCase() ? "S".repeat(Math.max(length, 2)) : "s".repeat(Math.max(length, 2));
|
|
59
|
+
case "a":
|
|
60
|
+
return token.repeat(Math.max(length, 2));
|
|
61
|
+
default:
|
|
62
|
+
return token.repeat(length);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var buildFormatSegments = function (format) {
|
|
66
|
+
var segments = [];
|
|
67
|
+
var cursor = 0;
|
|
68
|
+
var i = 0;
|
|
69
|
+
while (i < format.length) {
|
|
70
|
+
var char = format[i];
|
|
71
|
+
if (TOKEN_CHARS.test(char)) {
|
|
72
|
+
var j = i + 1;
|
|
73
|
+
while (j < format.length && format[j] === char) {
|
|
74
|
+
j++;
|
|
75
|
+
}
|
|
76
|
+
var length_1 = j - i;
|
|
77
|
+
var placeholder = getPlaceholderForToken(char, length_1);
|
|
78
|
+
var segment = {
|
|
79
|
+
type: "token",
|
|
80
|
+
token: char,
|
|
81
|
+
length: length_1,
|
|
82
|
+
placeholder: placeholder,
|
|
83
|
+
placeholderChar: placeholder.charAt(0) || char,
|
|
84
|
+
start: cursor,
|
|
85
|
+
end: cursor + placeholder.length,
|
|
86
|
+
};
|
|
87
|
+
segments.push(segment);
|
|
88
|
+
cursor += placeholder.length;
|
|
89
|
+
i = j;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
var literalSegment = {
|
|
93
|
+
type: "literal",
|
|
94
|
+
length: 1,
|
|
95
|
+
placeholder: char,
|
|
96
|
+
placeholderChar: char,
|
|
97
|
+
literal: char,
|
|
98
|
+
start: cursor,
|
|
99
|
+
end: cursor + 1,
|
|
100
|
+
};
|
|
101
|
+
segments.push(literalSegment);
|
|
102
|
+
cursor += 1;
|
|
103
|
+
i += 1;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return segments;
|
|
107
|
+
};
|
|
108
|
+
var buildTimeSegments = function (format) {
|
|
109
|
+
var _a;
|
|
110
|
+
var m = format.match(/^(h{1,2}|H{1,2}):m{1,2}(?:\s*a{1,2})?$/i);
|
|
111
|
+
if (!m)
|
|
112
|
+
return null;
|
|
113
|
+
var segments = [];
|
|
114
|
+
var cursor = 0;
|
|
115
|
+
var hourToken = m[1];
|
|
116
|
+
var hourPlaceholder = getPlaceholderForToken(hourToken[0], hourToken.length);
|
|
117
|
+
segments.push({ type: "token", token: hourToken[0], length: hourToken.length, placeholder: hourPlaceholder, placeholderChar: hourPlaceholder.charAt(0), start: cursor, end: cursor + hourPlaceholder.length });
|
|
118
|
+
cursor += hourPlaceholder.length;
|
|
119
|
+
segments.push({ type: "literal", length: 1, placeholder: ":", placeholderChar: ":", literal: ":", start: cursor, end: cursor + 1 });
|
|
120
|
+
cursor += 1;
|
|
121
|
+
var minuteLength = (((_a = format.match(/:m{1,2}/)) === null || _a === void 0 ? void 0 : _a[0].length) || 2) - 1;
|
|
122
|
+
var minutePlaceholder = getPlaceholderForToken("m", minuteLength);
|
|
123
|
+
segments.push({ type: "token", token: "m", length: minuteLength, placeholder: minutePlaceholder, placeholderChar: minutePlaceholder.charAt(0), start: cursor, end: cursor + minutePlaceholder.length });
|
|
124
|
+
cursor += minutePlaceholder.length;
|
|
125
|
+
var ampmMatch = format.match(/\s*a{1,2}$/);
|
|
126
|
+
if (ampmMatch) {
|
|
127
|
+
segments.push({ type: "literal", length: 1, placeholder: " ", placeholderChar: " ", literal: " ", start: cursor, end: cursor + 1 });
|
|
128
|
+
cursor += 1;
|
|
129
|
+
var aLen = ampmMatch[0].trim().length;
|
|
130
|
+
var aPlaceholder = getPlaceholderForToken("a", aLen);
|
|
131
|
+
segments.push({ type: "token", token: "a", length: aLen, placeholder: aPlaceholder, placeholderChar: aPlaceholder.charAt(0), start: cursor, end: cursor + aPlaceholder.length });
|
|
132
|
+
}
|
|
133
|
+
return segments;
|
|
134
|
+
};
|
|
135
|
+
var inferPickerTypeFromFormat = function (formatStr) {
|
|
136
|
+
var lower = formatStr.toLowerCase();
|
|
137
|
+
var hasTime = lower.includes("hh") || lower.includes("mm") || lower.includes("ss");
|
|
138
|
+
var hasDate = lower.includes("d") && lower.includes("m") && lower.includes("y");
|
|
139
|
+
if (hasTime && hasDate)
|
|
140
|
+
return "datetime";
|
|
141
|
+
if (hasTime)
|
|
142
|
+
return "time";
|
|
143
|
+
return "date";
|
|
144
|
+
};
|
|
145
|
+
var formatToPlaceholder = function (format) { return format; };
|
|
146
|
+
var filterNumericInput = function (value, format) {
|
|
147
|
+
var separators = format.match(/[^dDmMyYhHsSaA]/g) || [];
|
|
148
|
+
var uniqueSeparators = Array.from(new Set(separators));
|
|
149
|
+
return value
|
|
150
|
+
.split("")
|
|
151
|
+
.filter(function (char) {
|
|
152
|
+
if (/[0-9]/.test(char))
|
|
153
|
+
return true;
|
|
154
|
+
if (uniqueSeparators.includes(char))
|
|
155
|
+
return true;
|
|
156
|
+
if (char === " ")
|
|
157
|
+
return true;
|
|
158
|
+
return false;
|
|
159
|
+
})
|
|
160
|
+
.join("");
|
|
161
|
+
};
|
|
162
|
+
var getFormatForPickerType = function (pickerType, dateFormat) {
|
|
163
|
+
if (!pickerType) {
|
|
164
|
+
return dateFormat;
|
|
165
|
+
}
|
|
166
|
+
if (pickerType === "date") {
|
|
167
|
+
var hasTime = /[hHmsSaA]/.test(dateFormat);
|
|
168
|
+
if (hasTime) {
|
|
169
|
+
var dateMatch = dateFormat.match(/^([^hHmsSaA]+?)(?:\s*[hHmsSaA])/);
|
|
170
|
+
if (dateMatch && dateMatch[1]) {
|
|
171
|
+
return dateMatch[1].trim();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return dateFormat;
|
|
175
|
+
}
|
|
176
|
+
if (pickerType === "time") {
|
|
177
|
+
var hasDate = /[dDmMyY]/.test(dateFormat);
|
|
178
|
+
if (hasDate) {
|
|
179
|
+
var timeMatch = dateFormat.match(/[dDmMyY\/\-\s\.]+\s*([hHmsSaA\/\-\s:]+)$/);
|
|
180
|
+
if (timeMatch && timeMatch[1]) {
|
|
181
|
+
return timeMatch[1].trim();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return dateFormat;
|
|
185
|
+
}
|
|
186
|
+
return dateFormat;
|
|
187
|
+
};
|
|
188
|
+
var usesAmPm = function (format) { return /(^|[^a-zA-Z])a([^a-zA-Z]|$)/i.test(format); };
|
|
189
|
+
var sanitizeTimeInput = function (raw, format) {
|
|
190
|
+
var _a;
|
|
191
|
+
var ampm = usesAmPm(format);
|
|
192
|
+
var only = raw.replace(/[^0-9aApPmM:\s]/g, "");
|
|
193
|
+
if (/H{1,2}:m{1,2}/.test(format) || /h{1,2}:m{1,2}/i.test(format)) {
|
|
194
|
+
var digits = only.replace(/[^0-9]/g, "");
|
|
195
|
+
var hh = digits.slice(0, 2);
|
|
196
|
+
var mm = digits.slice(2, 4);
|
|
197
|
+
var out = hh;
|
|
198
|
+
if (mm.length)
|
|
199
|
+
out += ":" + mm;
|
|
200
|
+
if (ampm) {
|
|
201
|
+
var suffix = (((_a = only.match(/(am|pm)/i)) === null || _a === void 0 ? void 0 : _a[0]) || "").toUpperCase();
|
|
202
|
+
if (suffix)
|
|
203
|
+
out += " " + suffix;
|
|
204
|
+
}
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
return only;
|
|
208
|
+
};
|
|
209
|
+
var normalizeTimeBuffer = function (tokenChar, rawBuffer, segmentLength, is12Hour) {
|
|
210
|
+
if (!tokenChar)
|
|
211
|
+
return { value: rawBuffer, completed: rawBuffer.length >= segmentLength };
|
|
212
|
+
var t = tokenChar.toLowerCase();
|
|
213
|
+
var buf = rawBuffer.replace(/\D/g, "").slice(0, segmentLength);
|
|
214
|
+
if (segmentLength !== 2) {
|
|
215
|
+
return { value: buf, completed: buf.length >= segmentLength };
|
|
216
|
+
}
|
|
217
|
+
if (t === "h") {
|
|
218
|
+
var maxHour = is12Hour ? 12 : 24;
|
|
219
|
+
if (buf.length === 1) {
|
|
220
|
+
var d = parseInt(buf[0], 10);
|
|
221
|
+
var firstMax = is12Hour ? 1 : 2;
|
|
222
|
+
if (d > firstMax) {
|
|
223
|
+
return { value: "0".concat(d), completed: true };
|
|
224
|
+
}
|
|
225
|
+
return { value: buf, completed: false };
|
|
226
|
+
}
|
|
227
|
+
if (buf.length === 2) {
|
|
228
|
+
var h = parseInt(buf, 10);
|
|
229
|
+
if (is12Hour) {
|
|
230
|
+
if (h < 1)
|
|
231
|
+
h = 1;
|
|
232
|
+
if (h > 12)
|
|
233
|
+
h = 12;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
if (h < 1)
|
|
237
|
+
h = 1;
|
|
238
|
+
if (h > 24)
|
|
239
|
+
h = 24;
|
|
240
|
+
}
|
|
241
|
+
var out = h.toString().padStart(2, "0");
|
|
242
|
+
return { value: out, completed: true };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (t === "m") {
|
|
246
|
+
if (buf.length === 1) {
|
|
247
|
+
var d = parseInt(buf[0], 10);
|
|
248
|
+
if (d > 5) {
|
|
249
|
+
return { value: "0".concat(d), completed: true };
|
|
250
|
+
}
|
|
251
|
+
if (d === 0) {
|
|
252
|
+
return { value: "01", completed: true };
|
|
253
|
+
}
|
|
254
|
+
return { value: buf, completed: false };
|
|
255
|
+
}
|
|
256
|
+
if (buf.length === 2) {
|
|
257
|
+
var m = parseInt(buf, 10);
|
|
258
|
+
if (m < 1)
|
|
259
|
+
m = 1;
|
|
260
|
+
if (m > 60)
|
|
261
|
+
m = 60;
|
|
262
|
+
var out = m.toString().padStart(2, "0");
|
|
263
|
+
return { value: out, completed: true };
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return { value: buf, completed: buf.length >= segmentLength };
|
|
267
|
+
};
|
|
268
|
+
var SingleDatePicker = function (props) {
|
|
269
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
270
|
+
var id = props.id, name = props.name, label = props.label, isRequired = props.isRequired, isInformation = props.isInformation, informationMessage = props.informationMessage, error = props.error, errorMessage = props.errorMessage, helperText = props.helperText, placeholderText = props.placeholderText, _k = props.dateFormat, dateFormat = _k === void 0 ? "dd/MM/yyyy" : _k, pickerType = props.pickerType, minDate = props.minDate, maxDate = props.maxDate, disableFutureDates = props.disableFutureDates, disablePastDates = props.disablePastDates, _l = props.autoComplete, autoComplete = _l === void 0 ? "off" : _l, disabled = props.disabled, _m = props.width, width = _m === void 0 ? "100%" : _m, _o = props.disableToday, disableToday = _o === void 0 ? false : _o;
|
|
271
|
+
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
272
|
+
var _p = (0, react_2.useDisclosure)(), isOpen = _p.isOpen, onOpen = _p.onOpen, onClose = _p.onClose;
|
|
273
|
+
var inputRef = (0, react_1.useRef)(null);
|
|
274
|
+
var popoverRef = (0, react_1.useRef)(null);
|
|
275
|
+
var triggerRef = (0, react_1.useRef)(null);
|
|
276
|
+
var resolvedPickerType = pickerType !== null && pickerType !== void 0 ? pickerType : inferPickerTypeFromFormat(dateFormat);
|
|
277
|
+
var resolvedDateFormat = getFormatForPickerType(pickerType, dateFormat);
|
|
278
|
+
var enableMask = resolvedPickerType !== "time";
|
|
279
|
+
var basePlaceholder = (0, react_1.useMemo)(function () { return formatToPlaceholder(dateFormat); }, [dateFormat]);
|
|
280
|
+
var timeEffectiveFormat = (0, react_1.useMemo)(function () {
|
|
281
|
+
if ((pickerType !== null && pickerType !== void 0 ? pickerType : resolvedPickerType) === "time") {
|
|
282
|
+
var hasLowerH = /h{1,2}/.test(resolvedDateFormat);
|
|
283
|
+
var hasAmPm = /(^|[^a-zA-Z])a([^a-zA-Z]|$)/i.test(resolvedDateFormat);
|
|
284
|
+
if (hasLowerH && !hasAmPm)
|
|
285
|
+
return "".concat(resolvedDateFormat, " a");
|
|
286
|
+
}
|
|
287
|
+
return resolvedDateFormat;
|
|
288
|
+
}, [pickerType, resolvedPickerType, resolvedDateFormat]);
|
|
289
|
+
var activeFormat = timeEffectiveFormat;
|
|
290
|
+
var formatSegments = (0, react_1.useMemo)(function () {
|
|
291
|
+
if (!enableMask)
|
|
292
|
+
return [];
|
|
293
|
+
var expectHourFirst = /^(h{1,2}|H{1,2}):m{1,2}(?:\s*a{1,2})?$/i.test(activeFormat);
|
|
294
|
+
if (expectHourFirst) {
|
|
295
|
+
var ts = buildTimeSegments(activeFormat);
|
|
296
|
+
if (ts)
|
|
297
|
+
return ts;
|
|
298
|
+
}
|
|
299
|
+
return buildFormatSegments(activeFormat);
|
|
300
|
+
}, [enableMask, activeFormat]);
|
|
301
|
+
var tokenSegments = (0, react_1.useMemo)(function () { return (enableMask ? formatSegments.filter(function (segment) { return segment.type === "token"; }) : []); }, [enableMask, formatSegments]);
|
|
302
|
+
var maskPlaceholder = (0, react_1.useMemo)(function () {
|
|
303
|
+
if (!enableMask) {
|
|
304
|
+
return basePlaceholder;
|
|
305
|
+
}
|
|
306
|
+
var built = formatSegments.map(function (segment) { return segment.placeholder; }).join("");
|
|
307
|
+
if (built.length < basePlaceholder.length - 1)
|
|
308
|
+
return basePlaceholder;
|
|
309
|
+
if (/H|h/.test(activeFormat) && !/(H|h)/.test(built))
|
|
310
|
+
return basePlaceholder;
|
|
311
|
+
if (/:/.test(activeFormat) && !/:/.test(built))
|
|
312
|
+
return basePlaceholder;
|
|
313
|
+
return built;
|
|
314
|
+
}, [basePlaceholder, enableMask, formatSegments, activeFormat]);
|
|
315
|
+
var displayPlaceholder = placeholderText || (enableMask ? maskPlaceholder : basePlaceholder);
|
|
316
|
+
var didCommitRef = (0, react_1.useRef)(false);
|
|
317
|
+
var suppressOnCloseFinalizeRef = (0, react_1.useRef)(false);
|
|
318
|
+
var pendingSegmentNavigationRef = (0, react_1.useRef)(null);
|
|
319
|
+
var restoreSelectionRef = (0, react_1.useRef)(null);
|
|
320
|
+
var segmentInputBufferRef = (0, react_1.useRef)("");
|
|
321
|
+
var maskInsertedRef = (0, react_1.useRef)(false);
|
|
322
|
+
var today = new Date();
|
|
323
|
+
var tomorrow = (0, date_fns_1.addDays)(today, 1);
|
|
324
|
+
var showDate = resolvedPickerType === "date" || resolvedPickerType === "datetime";
|
|
325
|
+
var showTime = resolvedPickerType === "time" || resolvedPickerType === "datetime";
|
|
326
|
+
var formatHasTime = resolvedDateFormat.toLowerCase().includes("hh") ||
|
|
327
|
+
resolvedDateFormat.toLowerCase().includes("mm") ||
|
|
328
|
+
resolvedDateFormat.toLowerCase().includes("ss");
|
|
329
|
+
var selectedDate = ((_a = props.value) !== null && _a !== void 0 ? _a : props.selectedDate);
|
|
330
|
+
var _q = (0, react_1.useState)(selectedDate
|
|
331
|
+
? disableToday && (0, date_fns_1.isSameDay)(selectedDate, today)
|
|
332
|
+
? tomorrow
|
|
333
|
+
: selectedDate
|
|
334
|
+
: disableToday
|
|
335
|
+
? tomorrow
|
|
336
|
+
: today), currentMonth = _q[0], setCurrentMonth = _q[1];
|
|
337
|
+
var _r = (0, react_1.useState)(selectedDate !== null && selectedDate !== void 0 ? selectedDate : null), tempDate = _r[0], setTempDate = _r[1];
|
|
338
|
+
var _s = (0, react_1.useState)(""), inputValue = _s[0], setInputValue = _s[1];
|
|
339
|
+
var _t = (0, react_1.useState)(false), isTyping = _t[0], setIsTyping = _t[1];
|
|
340
|
+
var _u = (0, react_1.useState)(false), isMaskActive = _u[0], setIsMaskActive = _u[1];
|
|
341
|
+
var _v = (0, react_1.useState)(0), currentSegmentIndex = _v[0], setCurrentSegmentIndex = _v[1];
|
|
342
|
+
var lastSegmentIndexRef = (0, react_1.useRef)(0);
|
|
343
|
+
var resetCommitGuardAndOpen = function () {
|
|
344
|
+
didCommitRef.current = false;
|
|
345
|
+
suppressOnCloseFinalizeRef.current = false;
|
|
346
|
+
onOpen();
|
|
347
|
+
};
|
|
348
|
+
var commitOnce = function (value) {
|
|
349
|
+
if (didCommitRef.current)
|
|
350
|
+
return;
|
|
351
|
+
didCommitRef.current = true;
|
|
352
|
+
props.onChange(value);
|
|
353
|
+
};
|
|
354
|
+
var finalize = function (overrideValue) {
|
|
355
|
+
if (enableMask) {
|
|
356
|
+
maskInsertedRef.current = false;
|
|
357
|
+
segmentInputBufferRef.current = "";
|
|
358
|
+
setIsMaskActive(false);
|
|
359
|
+
}
|
|
360
|
+
var value = overrideValue !== undefined ? overrideValue : tempDate;
|
|
361
|
+
if (value) {
|
|
362
|
+
setInputValue((0, date_fns_1.format)(value, activeFormat));
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
setInputValue("");
|
|
366
|
+
}
|
|
367
|
+
commitOnce(value !== null && value !== void 0 ? value : null);
|
|
368
|
+
setIsTyping(false);
|
|
369
|
+
};
|
|
370
|
+
var requestClose = function (overrideValue) {
|
|
371
|
+
suppressOnCloseFinalizeRef.current = true;
|
|
372
|
+
finalize(overrideValue);
|
|
373
|
+
onClose();
|
|
374
|
+
};
|
|
375
|
+
(0, react_1.useEffect)(function () {
|
|
376
|
+
if (selectedDate instanceof Date) {
|
|
377
|
+
setTempDate(new Date(selectedDate));
|
|
378
|
+
setInputValue((0, date_fns_1.format)(selectedDate, activeFormat));
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
setTempDate(null);
|
|
382
|
+
setInputValue("");
|
|
383
|
+
}
|
|
384
|
+
}, [selectedDate, activeFormat]);
|
|
385
|
+
(0, react_1.useEffect)(function () {
|
|
386
|
+
if (!enableMask || !isMaskActive) {
|
|
387
|
+
restoreSelectionRef.current = null;
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (restoreSelectionRef.current && inputRef.current) {
|
|
391
|
+
var _a = restoreSelectionRef.current, start_1 = _a.start, end_1 = _a.end;
|
|
392
|
+
var inputEl = inputRef.current;
|
|
393
|
+
if (document.activeElement === inputEl) {
|
|
394
|
+
try {
|
|
395
|
+
inputEl.setSelectionRange(start_1, end_1);
|
|
396
|
+
}
|
|
397
|
+
catch (e) { }
|
|
398
|
+
}
|
|
399
|
+
var restore_1 = function () {
|
|
400
|
+
if (inputRef.current && document.activeElement === inputRef.current) {
|
|
401
|
+
try {
|
|
402
|
+
inputRef.current.setSelectionRange(start_1, end_1);
|
|
403
|
+
}
|
|
404
|
+
catch (e) { }
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
Promise.resolve().then(restore_1);
|
|
408
|
+
requestAnimationFrame(restore_1);
|
|
409
|
+
requestAnimationFrame(function () { return requestAnimationFrame(restore_1); });
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
(0, react_1.useLayoutEffect)(function () {
|
|
413
|
+
if (!enableMask || !isMaskActive || !inputRef.current)
|
|
414
|
+
return;
|
|
415
|
+
if (pendingSegmentNavigationRef.current !== null) {
|
|
416
|
+
var targetIdx = pendingSegmentNavigationRef.current;
|
|
417
|
+
pendingSegmentNavigationRef.current = null;
|
|
418
|
+
if (targetIdx >= 0 && targetIdx < tokenSegments.length) {
|
|
419
|
+
var segment = tokenSegments[targetIdx];
|
|
420
|
+
restoreSelectionRef.current = { start: segment.start, end: segment.end };
|
|
421
|
+
setCurrentSegmentIndex(targetIdx);
|
|
422
|
+
lastSegmentIndexRef.current = targetIdx;
|
|
423
|
+
segmentInputBufferRef.current = "";
|
|
424
|
+
inputRef.current.focus();
|
|
425
|
+
inputRef.current.setSelectionRange(segment.start, segment.end);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}, [inputValue, tokenSegments, enableMask, isMaskActive]);
|
|
429
|
+
var handleOpen = function () {
|
|
430
|
+
if (!selectedDate && showDate) {
|
|
431
|
+
setTempDate(disableToday ? tomorrow : new Date());
|
|
432
|
+
}
|
|
433
|
+
if (showTime && !tempDate) {
|
|
434
|
+
setTempDate(disableToday ? tomorrow : new Date());
|
|
435
|
+
}
|
|
436
|
+
resetCommitGuardAndOpen();
|
|
437
|
+
};
|
|
438
|
+
var handleInputChange = function (e) {
|
|
439
|
+
if (enableMask && isMaskActive) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
var value = e.target.value;
|
|
443
|
+
value = filterNumericInput(value, resolvedDateFormat);
|
|
444
|
+
setInputValue(value);
|
|
445
|
+
setIsTyping(true);
|
|
446
|
+
if (!value.trim()) {
|
|
447
|
+
setTempDate(null);
|
|
448
|
+
setIsTyping(false);
|
|
449
|
+
requestClose(null);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
try {
|
|
453
|
+
var parsed = (0, date_fns_1.parse)(value, resolvedDateFormat, new Date());
|
|
454
|
+
if ((0, date_fns_1.isValid)(parsed)) {
|
|
455
|
+
var finalDate = parsed;
|
|
456
|
+
if (showTime && tempDate && !formatHasTime) {
|
|
457
|
+
finalDate = new Date(parsed.getFullYear(), parsed.getMonth(), parsed.getDate(), tempDate.getHours(), tempDate.getMinutes(), tempDate.getSeconds());
|
|
458
|
+
}
|
|
459
|
+
setTempDate(finalDate);
|
|
460
|
+
setCurrentMonth(finalDate);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
catch (_a) { }
|
|
464
|
+
};
|
|
465
|
+
var handleInputBlur = function () {
|
|
466
|
+
var value = inputValue;
|
|
467
|
+
if (enableMask && isMaskActive) {
|
|
468
|
+
setIsMaskActive(false);
|
|
469
|
+
segmentInputBufferRef.current = "";
|
|
470
|
+
if (!value || !value.trim() || !isMaskComplete(value)) {
|
|
471
|
+
setInputValue("");
|
|
472
|
+
setTempDate(null);
|
|
473
|
+
setIsTyping(false);
|
|
474
|
+
maskInsertedRef.current = false;
|
|
475
|
+
requestClose(null);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
setIsTyping(false);
|
|
480
|
+
if (!value || !value.trim()) {
|
|
481
|
+
setTempDate(null);
|
|
482
|
+
requestClose(null);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
try {
|
|
486
|
+
var parsed = (0, date_fns_1.parse)(value, resolvedDateFormat, new Date());
|
|
487
|
+
if ((0, date_fns_1.isValid)(parsed)) {
|
|
488
|
+
var validated = computeFinalDate(parsed);
|
|
489
|
+
if (validated) {
|
|
490
|
+
setTempDate(validated);
|
|
491
|
+
setCurrentMonth(validated);
|
|
492
|
+
setInputValue((0, date_fns_1.format)(validated, resolvedDateFormat));
|
|
493
|
+
requestClose(validated);
|
|
494
|
+
maskInsertedRef.current = false;
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
catch (_a) { }
|
|
500
|
+
if (tempDate) {
|
|
501
|
+
setInputValue((0, date_fns_1.format)(tempDate, resolvedDateFormat));
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
setInputValue("");
|
|
505
|
+
setTempDate(null);
|
|
506
|
+
requestClose(null);
|
|
507
|
+
}
|
|
508
|
+
maskInsertedRef.current = false;
|
|
509
|
+
};
|
|
510
|
+
var handleDaySelect = function (day) {
|
|
511
|
+
var updated = new Date(day);
|
|
512
|
+
if (disableToday && (0, date_fns_1.isSameDay)(updated, today)) {
|
|
513
|
+
updated = tomorrow;
|
|
514
|
+
}
|
|
515
|
+
var updatedDate = tempDate
|
|
516
|
+
? new Date(updated.getFullYear(), updated.getMonth(), updated.getDate(), tempDate.getHours(), tempDate.getMinutes(), tempDate.getSeconds())
|
|
517
|
+
: updated;
|
|
518
|
+
setTempDate(updatedDate);
|
|
519
|
+
setInputValue((0, date_fns_1.format)(updatedDate, resolvedDateFormat));
|
|
520
|
+
setIsTyping(false);
|
|
521
|
+
if (!showTime) {
|
|
522
|
+
requestClose(updatedDate);
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
(0, react_1.useEffect)(function () {
|
|
526
|
+
if (!isOpen)
|
|
527
|
+
return;
|
|
528
|
+
var handleClickOutside = function (event) {
|
|
529
|
+
var _a, _b, _c;
|
|
530
|
+
var target = event.target;
|
|
531
|
+
var isInsidePopover = (_a = popoverRef.current) === null || _a === void 0 ? void 0 : _a.contains(target);
|
|
532
|
+
var isInsideInput = (_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.contains(target);
|
|
533
|
+
var isInsideTrigger = (_c = triggerRef.current) === null || _c === void 0 ? void 0 : _c.contains(target);
|
|
534
|
+
if (!isInsidePopover && !isInsideInput && !isInsideTrigger) {
|
|
535
|
+
finalize();
|
|
536
|
+
onClose();
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
document.addEventListener("mousedown", handleClickOutside, true);
|
|
540
|
+
document.addEventListener("click", handleClickOutside, true);
|
|
541
|
+
return function () {
|
|
542
|
+
document.removeEventListener("mousedown", handleClickOutside, true);
|
|
543
|
+
document.removeEventListener("click", handleClickOutside, true);
|
|
544
|
+
};
|
|
545
|
+
}, [isOpen]);
|
|
546
|
+
var ensureMaskValue = (0, react_1.useCallback)(function () {
|
|
547
|
+
var _a, _b, _c, _d;
|
|
548
|
+
if (!enableMask) {
|
|
549
|
+
return (_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : inputValue;
|
|
550
|
+
}
|
|
551
|
+
var currentValue = (_d = (_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : inputValue;
|
|
552
|
+
if (!currentValue || currentValue.length !== maskPlaceholder.length) {
|
|
553
|
+
currentValue = maskPlaceholder;
|
|
554
|
+
setInputValue(currentValue);
|
|
555
|
+
maskInsertedRef.current = true;
|
|
556
|
+
}
|
|
557
|
+
return currentValue;
|
|
558
|
+
}, [enableMask, inputRef, inputValue, maskPlaceholder]);
|
|
559
|
+
var selectSegment = (0, react_1.useCallback)(function (index) {
|
|
560
|
+
if (!enableMask || tokenSegments.length === 0)
|
|
561
|
+
return;
|
|
562
|
+
var clamped = Math.max(0, Math.min(tokenSegments.length - 1, index));
|
|
563
|
+
var segment = tokenSegments[clamped];
|
|
564
|
+
setCurrentSegmentIndex(clamped);
|
|
565
|
+
lastSegmentIndexRef.current = clamped;
|
|
566
|
+
segmentInputBufferRef.current = "";
|
|
567
|
+
var inputEl = inputRef.current;
|
|
568
|
+
if (!inputEl)
|
|
569
|
+
return;
|
|
570
|
+
var currentValue = inputEl.value;
|
|
571
|
+
if (!currentValue || currentValue.length === 0) {
|
|
572
|
+
currentValue = inputValue || maskPlaceholder;
|
|
573
|
+
if (inputEl.value !== currentValue) {
|
|
574
|
+
inputEl.value = currentValue;
|
|
575
|
+
setInputValue(currentValue);
|
|
576
|
+
}
|
|
577
|
+
maskInsertedRef.current = !inputValue;
|
|
578
|
+
}
|
|
579
|
+
else if (currentValue.length !== maskPlaceholder.length) {
|
|
580
|
+
var preservedSegments_1 = [];
|
|
581
|
+
formatSegments.forEach(function (seg) {
|
|
582
|
+
if (seg.start < currentValue.length) {
|
|
583
|
+
var segValue = currentValue.slice(seg.start, Math.min(seg.end, currentValue.length));
|
|
584
|
+
if (seg.type === "token" && /^\d+$/.test(segValue.replace(/\D/g, ""))) {
|
|
585
|
+
preservedSegments_1.push(segValue.padEnd(seg.placeholder.length, seg.placeholderChar));
|
|
586
|
+
}
|
|
587
|
+
else if (seg.type === "literal") {
|
|
588
|
+
preservedSegments_1.push(seg.placeholder);
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
preservedSegments_1.push(seg.placeholder);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
preservedSegments_1.push(seg.placeholder);
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
currentValue = preservedSegments_1.join("");
|
|
599
|
+
inputEl.value = currentValue;
|
|
600
|
+
setInputValue(currentValue);
|
|
601
|
+
}
|
|
602
|
+
inputEl.focus({ preventScroll: true });
|
|
603
|
+
inputEl.setSelectionRange(segment.start, segment.end);
|
|
604
|
+
requestAnimationFrame(function () {
|
|
605
|
+
if (inputRef.current) {
|
|
606
|
+
inputRef.current.setSelectionRange(segment.start, segment.end);
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
}, [enableMask, maskPlaceholder, tokenSegments, formatSegments, inputValue]);
|
|
610
|
+
var moveToSegment = (0, react_1.useCallback)(function (nextIndex) {
|
|
611
|
+
if (!enableMask || !tokenSegments.length)
|
|
612
|
+
return;
|
|
613
|
+
var clamped = Math.max(0, Math.min(tokenSegments.length - 1, nextIndex));
|
|
614
|
+
selectSegment(clamped);
|
|
615
|
+
}, [enableMask, selectSegment, tokenSegments.length]);
|
|
616
|
+
var getTokenIndexForCaret = function (caret, tokens) {
|
|
617
|
+
if (tokens.length === 0)
|
|
618
|
+
return 0;
|
|
619
|
+
var insideIdx = tokens.findIndex(function (t) { return caret >= t.start && caret <= t.end; });
|
|
620
|
+
if (insideIdx >= 0)
|
|
621
|
+
return insideIdx;
|
|
622
|
+
var toRight = tokens.findIndex(function (t) { return caret < t.end; });
|
|
623
|
+
if (toRight >= 0)
|
|
624
|
+
return toRight;
|
|
625
|
+
return tokens.length - 1;
|
|
626
|
+
};
|
|
627
|
+
var isSegmentComplete = function (segment, value) {
|
|
628
|
+
var _a;
|
|
629
|
+
if (segment.type === "literal")
|
|
630
|
+
return true;
|
|
631
|
+
var token = (_a = segment.token) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
632
|
+
if (!token)
|
|
633
|
+
return true;
|
|
634
|
+
if (token === "a") {
|
|
635
|
+
var normalized = value.trim().toLowerCase();
|
|
636
|
+
if (segment.placeholder.length <= 1) {
|
|
637
|
+
return normalized === "a" || normalized === "p";
|
|
638
|
+
}
|
|
639
|
+
return normalized === "am" || normalized === "pm";
|
|
640
|
+
}
|
|
641
|
+
return /^\d+$/.test(value) && value.length === segment.placeholder.length;
|
|
642
|
+
};
|
|
643
|
+
var isMaskComplete = function (value) {
|
|
644
|
+
if (!value || value.length !== maskPlaceholder.length)
|
|
645
|
+
return false;
|
|
646
|
+
return tokenSegments.every(function (segment) {
|
|
647
|
+
var segmentValue = value.slice(segment.start, segment.end);
|
|
648
|
+
return isSegmentComplete(segment, segmentValue);
|
|
649
|
+
});
|
|
650
|
+
};
|
|
651
|
+
var computeFinalDate = function (parsed) {
|
|
652
|
+
if (minDate && (0, date_fns_1.isBefore)(parsed, minDate))
|
|
653
|
+
return null;
|
|
654
|
+
if (maxDate && (0, date_fns_1.isAfter)(parsed, maxDate))
|
|
655
|
+
return null;
|
|
656
|
+
if (disablePastDates && (0, date_fns_1.isBefore)(parsed, today) && !(0, date_fns_1.isSameDay)(parsed, today))
|
|
657
|
+
return null;
|
|
658
|
+
if (disableFutureDates && (0, date_fns_1.isAfter)(parsed, today) && !(0, date_fns_1.isSameDay)(parsed, today))
|
|
659
|
+
return null;
|
|
660
|
+
if (disableToday && (0, date_fns_1.isSameDay)(parsed, today))
|
|
661
|
+
return null;
|
|
662
|
+
var finalDate = parsed;
|
|
663
|
+
if (showTime && tempDate && !formatHasTime) {
|
|
664
|
+
finalDate = new Date(parsed.getFullYear(), parsed.getMonth(), parsed.getDate(), tempDate.getHours(), tempDate.getMinutes(), tempDate.getSeconds());
|
|
665
|
+
}
|
|
666
|
+
return finalDate;
|
|
667
|
+
};
|
|
668
|
+
var updateTempDateFromMask = function (value) {
|
|
669
|
+
if (!isMaskComplete(value)) {
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
try {
|
|
673
|
+
var parsed = (0, date_fns_1.parse)(value, resolvedDateFormat, new Date());
|
|
674
|
+
if ((0, date_fns_1.isValid)(parsed)) {
|
|
675
|
+
var validated = computeFinalDate(parsed);
|
|
676
|
+
if (validated) {
|
|
677
|
+
setTempDate(validated);
|
|
678
|
+
setCurrentMonth(validated);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
catch (_a) { }
|
|
683
|
+
};
|
|
684
|
+
var handleInputFocus = function (e) {
|
|
685
|
+
if (!enableMask) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
e.stopPropagation();
|
|
689
|
+
if (!tokenSegments.length)
|
|
690
|
+
return;
|
|
691
|
+
setIsMaskActive(true);
|
|
692
|
+
setIsTyping(true);
|
|
693
|
+
if (!inputValue || inputValue.length !== maskPlaceholder.length) {
|
|
694
|
+
setInputValue(maskPlaceholder);
|
|
695
|
+
maskInsertedRef.current = true;
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
maskInsertedRef.current = false;
|
|
699
|
+
}
|
|
700
|
+
segmentInputBufferRef.current = "";
|
|
701
|
+
requestAnimationFrame(function () { return selectSegment(0); });
|
|
702
|
+
};
|
|
703
|
+
var handleInputClick = function (e) {
|
|
704
|
+
var _a;
|
|
705
|
+
if (!enableMask) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
e.stopPropagation();
|
|
709
|
+
if (!tokenSegments.length)
|
|
710
|
+
return;
|
|
711
|
+
setIsMaskActive(true);
|
|
712
|
+
if (!inputRef.current)
|
|
713
|
+
return;
|
|
714
|
+
var caret = (_a = inputRef.current.selectionStart) !== null && _a !== void 0 ? _a : 0;
|
|
715
|
+
var index = tokenSegments.findIndex(function (segment) { return caret >= segment.start && caret <= segment.end; });
|
|
716
|
+
if (index >= 0) {
|
|
717
|
+
requestAnimationFrame(function () { return selectSegment(index); });
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
var handleKeyDown = function (e) {
|
|
721
|
+
var _a, _b, _c, _d, _e;
|
|
722
|
+
if (!enableMask) {
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
var inputEl = inputRef.current;
|
|
726
|
+
var selStart = (_a = inputEl === null || inputEl === void 0 ? void 0 : inputEl.selectionStart) !== null && _a !== void 0 ? _a : 0;
|
|
727
|
+
var selEnd = (_b = inputEl === null || inputEl === void 0 ? void 0 : inputEl.selectionEnd) !== null && _b !== void 0 ? _b : selStart;
|
|
728
|
+
var caretForForward = selStart === selEnd ? selStart : selEnd;
|
|
729
|
+
var caretForBackward = selStart === selEnd ? selStart : selStart;
|
|
730
|
+
if (!tokenSegments.length)
|
|
731
|
+
return;
|
|
732
|
+
setIsMaskActive(true);
|
|
733
|
+
var key = e.key;
|
|
734
|
+
var is12Hour = /h{1,2}/.test(activeFormat) && !/H{1,2}/.test(activeFormat);
|
|
735
|
+
var caret = key === "ArrowLeft" ? caretForBackward : caretForForward;
|
|
736
|
+
var activeIdx = getTokenIndexForCaret(caret, tokenSegments);
|
|
737
|
+
var segment = (_c = tokenSegments[activeIdx]) !== null && _c !== void 0 ? _c : tokenSegments[0];
|
|
738
|
+
if (key === "Tab") {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
if (key === "ArrowLeft" || key === "ArrowRight") {
|
|
742
|
+
e.preventDefault();
|
|
743
|
+
var delta = key === "ArrowRight" ? 1 : -1;
|
|
744
|
+
var nextIdx = activeIdx + delta;
|
|
745
|
+
if (nextIdx >= 0 && nextIdx < tokenSegments.length) {
|
|
746
|
+
pendingSegmentNavigationRef.current = null;
|
|
747
|
+
var targetSegment_1 = tokenSegments[nextIdx];
|
|
748
|
+
if (inputRef.current && targetSegment_1) {
|
|
749
|
+
restoreSelectionRef.current = { start: targetSegment_1.start, end: targetSegment_1.end };
|
|
750
|
+
setCurrentSegmentIndex(nextIdx);
|
|
751
|
+
lastSegmentIndexRef.current = nextIdx;
|
|
752
|
+
segmentInputBufferRef.current = "";
|
|
753
|
+
inputRef.current.focus();
|
|
754
|
+
try {
|
|
755
|
+
inputRef.current.setSelectionRange(targetSegment_1.start, targetSegment_1.end);
|
|
756
|
+
}
|
|
757
|
+
catch (error) { }
|
|
758
|
+
requestAnimationFrame(function () {
|
|
759
|
+
if (inputRef.current) {
|
|
760
|
+
try {
|
|
761
|
+
inputRef.current.setSelectionRange(targetSegment_1.start, targetSegment_1.end);
|
|
762
|
+
}
|
|
763
|
+
catch (error) { }
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (key === "Home") {
|
|
771
|
+
e.preventDefault();
|
|
772
|
+
moveToSegment(0);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (key === "End") {
|
|
776
|
+
e.preventDefault();
|
|
777
|
+
moveToSegment(tokenSegments.length - 1);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
if (key === "Escape") {
|
|
781
|
+
e.preventDefault();
|
|
782
|
+
(_d = inputRef.current) === null || _d === void 0 ? void 0 : _d.blur();
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
if (key === "Enter") {
|
|
786
|
+
e.preventDefault();
|
|
787
|
+
handleInputBlur();
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
if (key === "Backspace" || key === "Delete") {
|
|
791
|
+
e.preventDefault();
|
|
792
|
+
var baseValue = ensureMaskValue();
|
|
793
|
+
var newValue = baseValue.slice(0, segment.start) + segment.placeholder + baseValue.slice(segment.end);
|
|
794
|
+
setInputValue(newValue);
|
|
795
|
+
setIsTyping(true);
|
|
796
|
+
maskInsertedRef.current = false;
|
|
797
|
+
segmentInputBufferRef.current = "";
|
|
798
|
+
updateTempDateFromMask(newValue);
|
|
799
|
+
requestAnimationFrame(function () { return selectSegment(activeIdx); });
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
if (e.ctrlKey || e.metaKey) {
|
|
803
|
+
var lowerKey = key.toLowerCase();
|
|
804
|
+
if (["a", "c", "v", "x"].includes(lowerKey)) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (((_e = segment.token) === null || _e === void 0 ? void 0 : _e.toLowerCase()) === "a") {
|
|
809
|
+
var lower = key.toLowerCase();
|
|
810
|
+
if (lower === "a" || lower === "p") {
|
|
811
|
+
e.preventDefault();
|
|
812
|
+
var value = lower === "a" ? (segment.placeholder.length <= 1 ? "A" : "AM") : (segment.placeholder.length <= 1 ? "P" : "PM");
|
|
813
|
+
var baseValue = ensureMaskValue();
|
|
814
|
+
var newValue = baseValue.slice(0, segment.start) + value + baseValue.slice(segment.end);
|
|
815
|
+
setInputValue(newValue);
|
|
816
|
+
setIsTyping(true);
|
|
817
|
+
maskInsertedRef.current = false;
|
|
818
|
+
segmentInputBufferRef.current = "";
|
|
819
|
+
updateTempDateFromMask(newValue);
|
|
820
|
+
requestAnimationFrame(function () { return moveToSegment(activeIdx + 1); });
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
if (key === "ArrowUp" || key === "ArrowDown") {
|
|
824
|
+
e.preventDefault();
|
|
825
|
+
var currentValue = ensureMaskValue().slice(segment.start, segment.end).toLowerCase();
|
|
826
|
+
var next = currentValue === "pm" ? (segment.placeholder.length <= 1 ? "A" : "AM") : (segment.placeholder.length <= 1 ? "P" : "PM");
|
|
827
|
+
var baseValue = ensureMaskValue();
|
|
828
|
+
var newValue = baseValue.slice(0, segment.start) + next + baseValue.slice(segment.end);
|
|
829
|
+
setInputValue(newValue);
|
|
830
|
+
setIsTyping(true);
|
|
831
|
+
maskInsertedRef.current = false;
|
|
832
|
+
segmentInputBufferRef.current = "";
|
|
833
|
+
updateTempDateFromMask(newValue);
|
|
834
|
+
requestAnimationFrame(function () { return moveToSegment(activeIdx + 1); });
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
e.preventDefault();
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
if (/^[0-9]$/.test(key)) {
|
|
841
|
+
e.preventDefault();
|
|
842
|
+
var baseValue = ensureMaskValue();
|
|
843
|
+
var placeholderChars_1 = segment.placeholder.split("");
|
|
844
|
+
var buffer = segmentInputBufferRef.current + key;
|
|
845
|
+
var normalized = normalizeTimeBuffer(segment.token, buffer, segment.placeholder.length, is12Hour);
|
|
846
|
+
var activeValue_1 = normalized.value;
|
|
847
|
+
var completed = normalized.completed;
|
|
848
|
+
placeholderChars_1.forEach(function (_char, idx) {
|
|
849
|
+
if (idx < activeValue_1.length) {
|
|
850
|
+
placeholderChars_1[idx] = activeValue_1[idx];
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
var newSegmentValue = placeholderChars_1.join("");
|
|
854
|
+
var newValue = baseValue.slice(0, segment.start) + newSegmentValue + baseValue.slice(segment.end);
|
|
855
|
+
setInputValue(newValue);
|
|
856
|
+
setIsTyping(true);
|
|
857
|
+
maskInsertedRef.current = false;
|
|
858
|
+
updateTempDateFromMask(newValue);
|
|
859
|
+
if (completed) {
|
|
860
|
+
segmentInputBufferRef.current = "";
|
|
861
|
+
var nextIdx = activeIdx + 1;
|
|
862
|
+
if (nextIdx < tokenSegments.length && inputRef.current) {
|
|
863
|
+
var nextSegment = tokenSegments[nextIdx];
|
|
864
|
+
pendingSegmentNavigationRef.current = nextIdx;
|
|
865
|
+
restoreSelectionRef.current = { start: nextSegment.start, end: nextSegment.end };
|
|
866
|
+
inputRef.current.value = newValue;
|
|
867
|
+
inputRef.current.focus();
|
|
868
|
+
inputRef.current.setSelectionRange(nextSegment.start, nextSegment.end);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
else {
|
|
872
|
+
segmentInputBufferRef.current = activeValue_1;
|
|
873
|
+
var caretStart_1 = segment.start + activeValue_1.length;
|
|
874
|
+
requestAnimationFrame(function () {
|
|
875
|
+
if (inputRef.current) {
|
|
876
|
+
inputRef.current.setSelectionRange(caretStart_1, segment.end);
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
if (key === "ArrowUp" || key === "ArrowDown") {
|
|
883
|
+
e.preventDefault();
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
if (key === " ") {
|
|
887
|
+
e.preventDefault();
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
e.preventDefault();
|
|
891
|
+
};
|
|
892
|
+
var handlePaste = function (e) {
|
|
893
|
+
if (!enableMask) {
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
e.preventDefault();
|
|
897
|
+
var pastedText = e.clipboardData.getData("text").trim();
|
|
898
|
+
if (!pastedText)
|
|
899
|
+
return;
|
|
900
|
+
try {
|
|
901
|
+
var parsed = (0, date_fns_1.parse)(pastedText, activeFormat, new Date());
|
|
902
|
+
if ((0, date_fns_1.isValid)(parsed)) {
|
|
903
|
+
var validated = computeFinalDate(parsed);
|
|
904
|
+
if (validated) {
|
|
905
|
+
var formattedValue_1 = (0, date_fns_1.format)(validated, activeFormat);
|
|
906
|
+
setTempDate(validated);
|
|
907
|
+
setCurrentMonth(validated);
|
|
908
|
+
setInputValue(formattedValue_1);
|
|
909
|
+
setIsTyping(true);
|
|
910
|
+
setIsMaskActive(true);
|
|
911
|
+
maskInsertedRef.current = false;
|
|
912
|
+
segmentInputBufferRef.current = "";
|
|
913
|
+
updateTempDateFromMask(formattedValue_1);
|
|
914
|
+
requestAnimationFrame(function () {
|
|
915
|
+
moveToSegment(tokenSegments.length - 1);
|
|
916
|
+
if (inputRef.current) {
|
|
917
|
+
var length_2 = formattedValue_1.length;
|
|
918
|
+
inputRef.current.setSelectionRange(length_2, length_2);
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
catch (_a) { }
|
|
926
|
+
};
|
|
927
|
+
var handleInputFocusMask = enableMask ? handleInputFocus : undefined;
|
|
928
|
+
var handleInputClickMask = enableMask ? handleInputClick : undefined;
|
|
929
|
+
var handleKeyDownMask = enableMask ? handleKeyDown : undefined;
|
|
930
|
+
var handlePasteMask = enableMask ? handlePaste : undefined;
|
|
931
|
+
var displayValue = isTyping
|
|
932
|
+
? inputValue
|
|
933
|
+
: tempDate
|
|
934
|
+
? (0, date_fns_1.format)(tempDate, resolvedDateFormat)
|
|
935
|
+
: "";
|
|
936
|
+
return (react_1.default.createElement(react_2.FormControl, { id: id, isInvalid: error, isRequired: isRequired, isDisabled: disabled, width: width },
|
|
937
|
+
label && (react_1.default.createElement(FormLabel_1.TextLabel, { label: label, isRequired: isRequired, isInformation: isInformation, informationMessage: informationMessage })),
|
|
938
|
+
react_1.default.createElement(react_2.Popover, { isLazy: true, isOpen: isOpen, onClose: function () {
|
|
939
|
+
if (suppressOnCloseFinalizeRef.current) {
|
|
940
|
+
suppressOnCloseFinalizeRef.current = false;
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
finalize();
|
|
944
|
+
}, placement: "bottom-start", closeOnBlur: false, returnFocusOnClose: false },
|
|
945
|
+
react_1.default.createElement(react_2.PopoverTrigger, null,
|
|
946
|
+
react_1.default.createElement(react_2.Box, { ref: triggerRef, as: "div" },
|
|
947
|
+
react_1.default.createElement(react_2.InputGroup, null,
|
|
948
|
+
react_1.default.createElement(react_2.Input, { ref: inputRef, id: id, name: name, placeholder: displayPlaceholder, value: displayValue, onChange: handleInputChange, onKeyDown: handleKeyDownMask, onPaste: handlePasteMask, onBlur: handleInputBlur, onClick: handleInputClickMask, onFocus: handleInputFocusMask, isDisabled: disabled, autoComplete: autoComplete, borderColor: error ? (_c = (_b = theme.colors.semantic) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c[500] : undefined, _focus: {
|
|
949
|
+
borderColor: error ? (_e = (_d = theme.colors.semantic) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e[500] : theme.colors.primary[500],
|
|
950
|
+
boxShadow: error
|
|
951
|
+
? "0 0 0 1px ".concat((_g = (_f = theme.colors.semantic) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g[500])
|
|
952
|
+
: "0 0 0 1px ".concat(theme.colors.primary[500]),
|
|
953
|
+
}, _hover: {
|
|
954
|
+
borderColor: error ? (_j = (_h = theme.colors.semantic) === null || _h === void 0 ? void 0 : _h.error) === null || _j === void 0 ? void 0 : _j[500] : undefined,
|
|
955
|
+
}, cursor: "text" }),
|
|
956
|
+
react_1.default.createElement(react_2.InputRightElement, { pr: 3, pointerEvents: "auto", onClick: function (e) {
|
|
957
|
+
e.stopPropagation();
|
|
958
|
+
if (!isOpen) {
|
|
959
|
+
handleOpen();
|
|
960
|
+
}
|
|
961
|
+
else {
|
|
962
|
+
onClose();
|
|
963
|
+
}
|
|
964
|
+
}, style: { cursor: "pointer" } },
|
|
965
|
+
react_1.default.createElement(lucide_react_1.CalendarIcon, { size: 18, color: theme.colors.gray[500] }))))),
|
|
966
|
+
react_1.default.createElement(react_2.PopoverContent, { width: "auto", p: 4, ref: popoverRef, boxShadow: "lg" },
|
|
967
|
+
react_1.default.createElement(react_2.PopoverBody, null,
|
|
968
|
+
showDate && (react_1.default.createElement(CalendarPanel_1.default, { currentMonth: currentMonth, setCurrentMonth: function (updater) { return setCurrentMonth(function (prev) { return updater(prev); }); }, today: today, isRange: false, tempDate: tempDate, tempRangeStart: null, tempRangeEnd: null, isSameDay: date_fns_1.isSameDay, isBefore: date_fns_1.isBefore, isAfter: date_fns_1.isAfter, minDate: minDate, maxDate: maxDate, disablePastDates: disablePastDates, disableFutureDates: disableFutureDates, disableToday: disableToday, onDaySelect: handleDaySelect })),
|
|
969
|
+
showTime && (react_1.default.createElement(react_2.Box, { mt: showDate ? 4 : 0 }, resolvedPickerType === "time" ? (react_1.default.createElement(TimePickerInput_1.TimePickerInput, { value: tempDate, onChange: function (updatedDate) {
|
|
970
|
+
setTempDate(updatedDate);
|
|
971
|
+
setInputValue(updatedDate ? (0, date_fns_1.format)(updatedDate, resolvedDateFormat) : "");
|
|
972
|
+
setIsTyping(false);
|
|
973
|
+
}, dateFormat: resolvedDateFormat, disabled: disabled, placeholder: placeholderText })) : (react_1.default.createElement(TimePicker_1.default, { date: tempDate !== null && tempDate !== void 0 ? tempDate : new Date((disableToday ? tomorrow : today).getFullYear(), (disableToday ? tomorrow : today).getMonth(), (disableToday ? tomorrow : today).getDate(), 0, 0, 0, 0), dateFormat: resolvedDateFormat, onChange: function (updatedDate) {
|
|
974
|
+
setTempDate(updatedDate);
|
|
975
|
+
setInputValue((0, date_fns_1.format)(updatedDate, resolvedDateFormat));
|
|
976
|
+
setIsTyping(false);
|
|
977
|
+
} })))),
|
|
978
|
+
react_1.default.createElement(react_2.Box, { display: "flex", justifyContent: "space-between", mt: 4, pt: 4, borderTop: "1px solid", borderColor: "gray.200" },
|
|
979
|
+
react_1.default.createElement(Button_1.default, { size: "sm", variant: "ghost", onClick: function () {
|
|
980
|
+
setTempDate(null);
|
|
981
|
+
requestClose(null);
|
|
982
|
+
} }, "Clear"),
|
|
983
|
+
react_1.default.createElement(Button_1.default, { size: "sm", colorScheme: "primary", onClick: function () { return requestClose(); } }, "OK"))))),
|
|
984
|
+
error && errorMessage && react_1.default.createElement(ErrorMessage_1.default, { errorMessage: errorMessage }),
|
|
985
|
+
helperText && !error && react_1.default.createElement(HelperText_1.default, { helperText: helperText })));
|
|
986
|
+
};
|
|
987
|
+
exports.SingleDatePicker = SingleDatePicker;
|
|
988
|
+
exports.default = exports.SingleDatePicker;
|