@dmsi/wedgekit-react 0.0.28 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/{chunk-57WRM337.js → chunk-5POWRPIO.js} +3 -2
  2. package/dist/{chunk-S5KPS4IQ.js → chunk-HXEPUO5W.js} +189 -95
  3. package/dist/chunk-KHQX42T7.js +127 -0
  4. package/dist/{chunk-OUSNH76S.js → chunk-PCCJ7L3N.js} +29 -6
  5. package/dist/{chunk-PDDZ5PMY.js → chunk-S46RZBT4.js} +3 -2
  6. package/dist/components/CalendarRange.cjs +28 -5
  7. package/dist/components/CalendarRange.js +1 -1
  8. package/dist/components/DataGrid.cjs +490 -217
  9. package/dist/components/DataGrid.js +303 -122
  10. package/dist/components/DataGridCell.cjs +192 -96
  11. package/dist/components/DataGridCell.js +4 -2
  12. package/dist/components/DateInput.cjs +231 -30
  13. package/dist/components/DateInput.js +101 -27
  14. package/dist/components/DateRangeInput.cjs +550 -37
  15. package/dist/components/DateRangeInput.js +413 -34
  16. package/dist/components/MenuOption.cjs +3 -2
  17. package/dist/components/MenuOption.js +1 -1
  18. package/dist/components/MobileDataGrid.cjs +3 -2
  19. package/dist/components/MobileDataGrid.js +1 -1
  20. package/dist/components/NestedMenu.cjs +3 -2
  21. package/dist/components/NestedMenu.js +1 -1
  22. package/dist/components/Notification.cjs +3 -2
  23. package/dist/components/Notification.js +1 -1
  24. package/dist/components/SideMenuGroup.cjs +3 -2
  25. package/dist/components/SideMenuGroup.js +1 -1
  26. package/dist/components/SideMenuItem.cjs +3 -2
  27. package/dist/components/SideMenuItem.js +1 -1
  28. package/dist/components/Stack.cjs +3 -2
  29. package/dist/components/Stack.js +1 -1
  30. package/dist/components/Swatch.cjs +3 -2
  31. package/dist/components/Swatch.js +1 -1
  32. package/dist/components/Time.cjs +3 -2
  33. package/dist/components/Time.js +1 -1
  34. package/dist/index.css +9 -0
  35. package/package.json +1 -1
  36. package/src/components/CalendarRange.tsx +37 -6
  37. package/src/components/DataGrid.tsx +284 -48
  38. package/src/components/DataGridCell.tsx +122 -35
  39. package/src/components/DateInput.tsx +118 -25
  40. package/src/components/DateRangeInput.tsx +544 -30
  41. package/src/components/MenuOption.tsx +18 -14
  42. package/src/components/Stack.tsx +4 -2
  43. package/src/utils/date.ts +206 -0
@@ -774,11 +774,20 @@ function CalendarRange({
774
774
  }) {
775
775
  const weekDays = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
776
776
  const parseDate = (d) => {
777
- if (!d) return void 0;
778
- if (typeof d === "number")
779
- return import_polyfill.Temporal.PlainDate.from(new Date(d).toISOString().slice(0, 10));
780
- if (typeof d === "string") return import_polyfill.Temporal.PlainDate.from(d);
781
- return void 0;
777
+ if (!d) {
778
+ return void 0;
779
+ }
780
+ try {
781
+ if (typeof d === "number") {
782
+ return import_polyfill.Temporal.PlainDate.from(new Date(d).toISOString().slice(0, 10));
783
+ }
784
+ if (typeof d === "string") {
785
+ return import_polyfill.Temporal.PlainDate.from(d);
786
+ }
787
+ return void 0;
788
+ } catch (error) {
789
+ return import_polyfill.Temporal.Now.plainDateISO();
790
+ }
782
791
  };
783
792
  const fromDate = parseDate(from);
784
793
  const toDate = parseDate(to);
@@ -789,6 +798,20 @@ function CalendarRange({
789
798
  const [selecting, setSelecting] = (0, import_react2.useState)("from");
790
799
  const [pendingFrom, setPendingFrom] = (0, import_react2.useState)(void 0);
791
800
  const [hoveredDate, setHoveredDate] = (0, import_react2.useState)(void 0);
801
+ (0, import_react2.useEffect)(() => {
802
+ if (fromDate) {
803
+ setBaseMonth(fromDate.with({ day: 1 }));
804
+ } else if (toDate) {
805
+ setBaseMonth(toDate.with({ day: 1 }));
806
+ }
807
+ }, [from, to]);
808
+ (0, import_react2.useEffect)(() => {
809
+ if (fromDate && toDate) {
810
+ setSelecting("from");
811
+ setPendingFrom(void 0);
812
+ setHoveredDate(void 0);
813
+ }
814
+ }, [from, to]);
792
815
  function getMonthData(monthOffset) {
793
816
  const monthDate = baseMonth.add({ months: monthOffset }).with({ day: 1 });
794
817
  const days = monthDate.daysInMonth;
@@ -1002,6 +1025,125 @@ function findDocumentRoot(element) {
1002
1025
  return window.document.body;
1003
1026
  }
1004
1027
 
1028
+ // src/utils/date.ts
1029
+ function parseInputDate(input) {
1030
+ const match = input.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
1031
+ if (!match) {
1032
+ return null;
1033
+ }
1034
+ const [, month, day, year] = match;
1035
+ const paddedMonth = month.padStart(2, "0");
1036
+ const paddedDay = day.padStart(2, "0");
1037
+ return `${year}-${paddedMonth}-${paddedDay}`;
1038
+ }
1039
+ function isValidDate(dateString) {
1040
+ const date = new Date(dateString);
1041
+ return date instanceof Date && !isNaN(date.getTime()) && dateString === date.toISOString().split("T")[0];
1042
+ }
1043
+ function formatInputValue(value) {
1044
+ const digits = value.replace(/\D/g, "");
1045
+ if (digits.length < 2) {
1046
+ return digits;
1047
+ }
1048
+ if (digits.length >= 4) {
1049
+ return `${digits.slice(0, 2)}/${digits.slice(2, 4)}/${digits.slice(4, 8)}`;
1050
+ }
1051
+ return `${digits.slice(0, 2)}/${digits.slice(2)}`;
1052
+ }
1053
+ function isDigit(character) {
1054
+ return /\d/.test(character);
1055
+ }
1056
+ function isSlash(character) {
1057
+ return character === "/";
1058
+ }
1059
+ function countDigitsUpToCursor(value, cursorPosition) {
1060
+ let digitCount = 0;
1061
+ for (let i = 0; i < cursorPosition && i < value.length; i++) {
1062
+ if (!isDigit(value[i])) {
1063
+ continue;
1064
+ }
1065
+ digitCount++;
1066
+ }
1067
+ return digitCount;
1068
+ }
1069
+ function findPositionAfterDigitCount(formattedValue, targetDigitCount) {
1070
+ let currentDigitCount = 0;
1071
+ for (let i = 0; i < formattedValue.length; i++) {
1072
+ if (!isDigit(formattedValue[i])) {
1073
+ continue;
1074
+ }
1075
+ currentDigitCount++;
1076
+ if (currentDigitCount !== targetDigitCount) {
1077
+ continue;
1078
+ }
1079
+ const positionAfterDigit = i + 1;
1080
+ const nextCharacter = formattedValue[positionAfterDigit];
1081
+ if (nextCharacter && isSlash(nextCharacter)) {
1082
+ return positionAfterDigit + 1;
1083
+ }
1084
+ return positionAfterDigit;
1085
+ }
1086
+ return formattedValue.length;
1087
+ }
1088
+ function calculateCursorPosition(originalValue, formattedValue, originalPosition) {
1089
+ const targetDigitCount = countDigitsUpToCursor(originalValue, originalPosition);
1090
+ const newPosition = findPositionAfterDigitCount(formattedValue, targetDigitCount);
1091
+ return Math.min(newPosition, formattedValue.length);
1092
+ }
1093
+ function parseDateParts(dateString) {
1094
+ const [yearStr, monthStr, dayStr] = dateString.split("-");
1095
+ if (!yearStr || !monthStr || !dayStr) {
1096
+ return null;
1097
+ }
1098
+ const year = parseInt(yearStr, 10);
1099
+ const month = parseInt(monthStr, 10);
1100
+ const day = parseInt(dayStr, 10);
1101
+ if (isNaN(year) || isNaN(month) || isNaN(day)) {
1102
+ return null;
1103
+ }
1104
+ return { year, month, day };
1105
+ }
1106
+ function isValidDateRange(month, day) {
1107
+ if (month < 1 || month > 12) {
1108
+ return false;
1109
+ }
1110
+ if (day < 1 || day > 31) {
1111
+ return false;
1112
+ }
1113
+ return true;
1114
+ }
1115
+ function formatDatePartsToDisplay(year, month, day) {
1116
+ const paddedMonth = month.toString().padStart(2, "0");
1117
+ const paddedDay = day.toString().padStart(2, "0");
1118
+ return `${paddedMonth}/${paddedDay}/${year}`;
1119
+ }
1120
+ function formatDate(date) {
1121
+ if (!date) {
1122
+ return "";
1123
+ }
1124
+ try {
1125
+ const dateParts = parseDateParts(date);
1126
+ if (!dateParts) {
1127
+ return "";
1128
+ }
1129
+ const { year, month, day } = dateParts;
1130
+ if (!isValidDateRange(month, day)) {
1131
+ return "";
1132
+ }
1133
+ return formatDatePartsToDisplay(year, month, day);
1134
+ } catch (error) {
1135
+ return "";
1136
+ }
1137
+ }
1138
+ function isValidDateRangeOrder(fromDate, toDate) {
1139
+ if (!fromDate || !toDate || !isValidDate(fromDate) || !isValidDate(toDate)) {
1140
+ return false;
1141
+ }
1142
+ const from = new Date(fromDate);
1143
+ const to = new Date(toDate);
1144
+ return to >= from;
1145
+ }
1146
+
1005
1147
  // src/components/DateRangeInput.tsx
1006
1148
  var import_jsx_runtime5 = require("react/jsx-runtime");
1007
1149
  var DateRangeInput = (_a) => {
@@ -1013,7 +1155,8 @@ var DateRangeInput = (_a) => {
1013
1155
  disabled,
1014
1156
  readOnly = false,
1015
1157
  single = false,
1016
- label: label
1158
+ disableRange = false,
1159
+ label
1017
1160
  } = _b, props = __objRest(_b, [
1018
1161
  "id",
1019
1162
  "value",
@@ -1022,10 +1165,12 @@ var DateRangeInput = (_a) => {
1022
1165
  "disabled",
1023
1166
  "readOnly",
1024
1167
  "single",
1025
- // Enables single date selection instead of range
1168
+ "disableRange",
1026
1169
  "label"
1027
1170
  ]);
1028
1171
  const [visible, setVisible] = (0, import_react3.useState)(false);
1172
+ const [inputValue, setInputValue] = (0, import_react3.useState)("");
1173
+ const [isTyping, setIsTyping] = (0, import_react3.useState)(false);
1029
1174
  const popoverRef = (0, import_react3.useRef)(null);
1030
1175
  const triggerRef = (0, import_react3.useRef)(null);
1031
1176
  const [calendarPosition, setCalendarPosition] = (0, import_react3.useState)({
@@ -1034,15 +1179,23 @@ var DateRangeInput = (_a) => {
1034
1179
  width: 0
1035
1180
  });
1036
1181
  const [from, to] = value.split("|");
1182
+ (0, import_react3.useEffect)(() => {
1183
+ if (!isTyping) {
1184
+ setInputValue(formatDisplayValue(from, to));
1185
+ }
1186
+ }, [from, to, isTyping, disableRange]);
1187
+ (0, import_react3.useLayoutEffect)(() => {
1188
+ if (visible) {
1189
+ updatePosition();
1190
+ }
1191
+ }, [visible]);
1037
1192
  const updatePosition = () => {
1038
1193
  if (triggerRef.current) {
1039
- requestAnimationFrame(() => {
1040
- const rect = triggerRef.current.getBoundingClientRect();
1041
- setCalendarPosition({
1042
- top: rect.bottom + window.scrollY,
1043
- left: rect.left + window.scrollX,
1044
- width: rect.width
1045
- });
1194
+ const rect = triggerRef.current.getBoundingClientRect();
1195
+ setCalendarPosition({
1196
+ top: rect.bottom + window.scrollY,
1197
+ left: rect.left + window.scrollX,
1198
+ width: rect.width
1046
1199
  });
1047
1200
  }
1048
1201
  };
@@ -1059,18 +1212,18 @@ var DateRangeInput = (_a) => {
1059
1212
  };
1060
1213
  }, []);
1061
1214
  (0, import_react3.useEffect)(() => {
1062
- const handleKeyDown = (event) => {
1215
+ const handleKeyDown2 = (event) => {
1063
1216
  var _a2;
1064
1217
  if (event.key === "Escape" && popoverRef.current) {
1065
1218
  setVisible(false);
1066
1219
  (_a2 = triggerRef.current) == null ? void 0 : _a2.blur();
1067
1220
  }
1068
1221
  };
1069
- document.addEventListener("keydown", handleKeyDown);
1222
+ document.addEventListener("keydown", handleKeyDown2);
1070
1223
  return () => {
1071
- document.removeEventListener("keydown", handleKeyDown);
1224
+ document.removeEventListener("keydown", handleKeyDown2);
1072
1225
  };
1073
- });
1226
+ }, []);
1074
1227
  (0, import_react3.useEffect)(() => {
1075
1228
  const handleClickOutside = (event) => {
1076
1229
  if (popoverRef.current && !popoverRef.current.contains(event.target) && triggerRef.current && !triggerRef.current.contains(event.target)) {
@@ -1083,24 +1236,312 @@ var DateRangeInput = (_a) => {
1083
1236
  };
1084
1237
  }, []);
1085
1238
  function handleRangeChange(fromValue, toValue) {
1086
- onChange(`${fromValue}|${toValue}`);
1239
+ if (disableRange) {
1240
+ onChange(`${fromValue}|${fromValue}`);
1241
+ } else {
1242
+ onChange(`${fromValue}|${toValue}`);
1243
+ }
1087
1244
  setVisible(false);
1245
+ setIsTyping(false);
1088
1246
  }
1089
1247
  const handleFocus = () => {
1090
1248
  if (readOnly) return;
1091
1249
  setVisible(true);
1092
- updatePosition();
1093
1250
  };
1094
- function formatDisplayValue(from2, to2) {
1095
- if (!from2 && !to2) return "";
1096
- if (from2 && to2) return `${formatDate(from2)} - ${formatDate(to2)}`;
1097
- if (from2) return `${formatDate(from2)} -`;
1098
- return "";
1099
- }
1100
- function formatDate(date) {
1101
- const [y, m, d] = date.split("-");
1102
- return `${m}/${d}/${y}`;
1103
- }
1251
+ const handleClick = () => {
1252
+ handleFocus();
1253
+ };
1254
+ const handleInputChange = (event) => {
1255
+ if (readOnly) return;
1256
+ const rawValue = event.target.value;
1257
+ const cursorPosition = event.target.selectionStart || 0;
1258
+ if (shouldPreventManualDash(rawValue)) {
1259
+ handleManualDashRemoval(rawValue, cursorPosition);
1260
+ return;
1261
+ }
1262
+ setIsTyping(true);
1263
+ const formattedValue = formatInputValue2(rawValue);
1264
+ const finalValue = shouldAutoInsertDash(formattedValue, rawValue) ? `${formattedValue} - ` : formattedValue;
1265
+ setInputValue(finalValue);
1266
+ const newCursorPosition = calculateNewCursorPosition(
1267
+ rawValue,
1268
+ formattedValue,
1269
+ finalValue,
1270
+ cursorPosition
1271
+ );
1272
+ requestAnimationFrame(() => {
1273
+ setCursorPosition(newCursorPosition);
1274
+ });
1275
+ updateParentValue(finalValue);
1276
+ };
1277
+ const shouldPreventManualDash = (value2) => {
1278
+ return !disableRange && value2.includes("-") && !value2.includes(" - ");
1279
+ };
1280
+ const handleManualDashRemoval = (rawValue, cursorPosition) => {
1281
+ const cleanValue = rawValue.replace(/-/g, "");
1282
+ const formattedCleanValue = formatInputValue2(cleanValue);
1283
+ setInputValue(formattedCleanValue);
1284
+ requestAnimationFrame(() => {
1285
+ const newPosition = Math.min(cursorPosition - 1, formattedCleanValue.length);
1286
+ setCursorPosition(newPosition);
1287
+ });
1288
+ };
1289
+ const shouldAutoInsertDash = (formattedValue, rawValue) => {
1290
+ if (disableRange || formattedValue.includes(" - ")) {
1291
+ return false;
1292
+ }
1293
+ const completeDate = formattedValue.match(/^(\d{2})\/(\d{2})\/(\d{4})$/);
1294
+ if (!completeDate || rawValue.length !== formattedValue.length) {
1295
+ return false;
1296
+ }
1297
+ const prevLength = rawValue.length - 1;
1298
+ const prevFormatted = formatInputValue2(rawValue.slice(0, prevLength));
1299
+ return !prevFormatted.match(/^(\d{2})\/(\d{2})\/(\d{4})$/);
1300
+ };
1301
+ const calculateNewCursorPosition = (rawValue, formattedValue, finalValue, originalPosition) => {
1302
+ if (finalValue !== formattedValue) {
1303
+ return finalValue.length;
1304
+ }
1305
+ return calculateCursorPositionHelper(rawValue, finalValue, originalPosition, disableRange);
1306
+ };
1307
+ const setCursorPosition = (position) => {
1308
+ if (triggerRef.current) {
1309
+ triggerRef.current.setSelectionRange(position, position);
1310
+ }
1311
+ };
1312
+ const updateParentValue = (value2) => {
1313
+ if (disableRange) {
1314
+ updateSingleDateValue(value2);
1315
+ } else {
1316
+ updateRangeValue(value2);
1317
+ }
1318
+ };
1319
+ const updateSingleDateValue = (value2) => {
1320
+ const parsedDate = parseInputDate(value2);
1321
+ if (parsedDate && isValidDate(parsedDate)) {
1322
+ onChange(`${parsedDate}|${parsedDate}`);
1323
+ }
1324
+ };
1325
+ const updateRangeValue = (value2) => {
1326
+ if (value2 === "") {
1327
+ onChange("");
1328
+ return;
1329
+ }
1330
+ const rangeMatch = value2.match(/^(.+?)\s*-\s*(.+)$/);
1331
+ if (rangeMatch) {
1332
+ updateCompleteRange(rangeMatch);
1333
+ } else {
1334
+ updatePartialRange(value2);
1335
+ }
1336
+ };
1337
+ const updateCompleteRange = (rangeMatch) => {
1338
+ const [, fromStr, toStr] = rangeMatch;
1339
+ const fromDate = parseInputDate(fromStr.trim());
1340
+ const toDate = parseInputDate(toStr.trim());
1341
+ if (fromDate && toDate && isValidDateRange2(fromDate, toDate)) {
1342
+ onChange(`${fromDate}|${toDate}`);
1343
+ }
1344
+ };
1345
+ const updatePartialRange = (value2) => {
1346
+ const singleDate = parseInputDate(value2);
1347
+ if (singleDate && isValidDate(singleDate)) {
1348
+ onChange(`${singleDate}|`);
1349
+ }
1350
+ };
1351
+ const handleBlur = () => {
1352
+ setIsTyping(false);
1353
+ if (disableRange) {
1354
+ const parsedDate = parseInputDate(inputValue);
1355
+ if (!parsedDate || !isValidDate(parsedDate)) {
1356
+ const lastValidValue = formatDisplayValue(from, to);
1357
+ setInputValue(lastValidValue || "");
1358
+ }
1359
+ } else {
1360
+ const rangeMatch = inputValue.match(/^(.+?)\s*-\s*(.+)$/);
1361
+ if (rangeMatch) {
1362
+ const [, fromStr, toStr] = rangeMatch;
1363
+ const fromDate = parseInputDate(fromStr.trim());
1364
+ const toDate = parseInputDate(toStr.trim());
1365
+ if (!fromDate || !toDate || !isValidDateRange2(fromDate, toDate)) {
1366
+ setInputValue("");
1367
+ onChange("");
1368
+ }
1369
+ } else {
1370
+ if (inputValue.includes(" - ")) {
1371
+ setInputValue("");
1372
+ onChange("");
1373
+ } else {
1374
+ const singleDate = parseInputDate(inputValue);
1375
+ if (!singleDate || !isValidDate(singleDate)) {
1376
+ setInputValue("");
1377
+ onChange("");
1378
+ } else {
1379
+ setInputValue("");
1380
+ onChange("");
1381
+ }
1382
+ }
1383
+ }
1384
+ }
1385
+ };
1386
+ const handleKeyDown = (event) => {
1387
+ if (!disableRange && event.key === "-") {
1388
+ event.preventDefault();
1389
+ return;
1390
+ }
1391
+ if (event.key === "Backspace") {
1392
+ const input = event.target;
1393
+ const cursorPosition = input.selectionStart || 0;
1394
+ const value2 = input.value;
1395
+ if (cursorPosition > 0 && value2[cursorPosition - 1] === "/") {
1396
+ event.preventDefault();
1397
+ const newValue = value2.slice(0, cursorPosition - 2) + value2.slice(cursorPosition);
1398
+ const formattedValue = formatInputValue2(newValue);
1399
+ setInputValue(formattedValue);
1400
+ requestAnimationFrame(() => {
1401
+ if (triggerRef.current) {
1402
+ const newPosition = Math.max(0, cursorPosition - 2);
1403
+ triggerRef.current.setSelectionRange(newPosition, newPosition);
1404
+ }
1405
+ });
1406
+ setIsTyping(true);
1407
+ return;
1408
+ }
1409
+ if (!disableRange && value2.includes(" - ")) {
1410
+ const dashIndex = value2.indexOf(" - ");
1411
+ const dashStart = dashIndex;
1412
+ const dashEnd = dashIndex + 3;
1413
+ if (cursorPosition >= dashStart && cursorPosition <= dashEnd) {
1414
+ event.preventDefault();
1415
+ const beforeDash = value2.slice(0, dashStart).trim();
1416
+ const yearMatch = beforeDash.match(/^(\d{2})\/(\d{2})\/(\d{4})$/);
1417
+ if (yearMatch) {
1418
+ const [, month, day, year] = yearMatch;
1419
+ const truncatedYear = year.slice(0, -1);
1420
+ const newValue = `${month}/${day}/${truncatedYear}`;
1421
+ const formattedValue = formatInputValue2(newValue);
1422
+ setInputValue(formattedValue);
1423
+ onChange("");
1424
+ requestAnimationFrame(() => {
1425
+ if (triggerRef.current) {
1426
+ triggerRef.current.setSelectionRange(formattedValue.length, formattedValue.length);
1427
+ }
1428
+ });
1429
+ } else {
1430
+ const formattedValue = formatInputValue2(beforeDash);
1431
+ setInputValue(formattedValue);
1432
+ const singleDate = parseInputDate(beforeDash);
1433
+ if (singleDate && isValidDate(singleDate)) {
1434
+ onChange(`${singleDate}|`);
1435
+ } else {
1436
+ onChange("");
1437
+ }
1438
+ requestAnimationFrame(() => {
1439
+ if (triggerRef.current) {
1440
+ const newPosition = formattedValue.length;
1441
+ triggerRef.current.setSelectionRange(newPosition, newPosition);
1442
+ }
1443
+ });
1444
+ }
1445
+ setIsTyping(true);
1446
+ return;
1447
+ }
1448
+ if (cursorPosition === dashEnd) {
1449
+ event.preventDefault();
1450
+ const beforeDash = value2.slice(0, dashStart).trim();
1451
+ const newValue = `${beforeDash} - `;
1452
+ setInputValue(newValue);
1453
+ const singleDate = parseInputDate(beforeDash);
1454
+ if (singleDate && isValidDate(singleDate)) {
1455
+ onChange(`${singleDate}|`);
1456
+ }
1457
+ requestAnimationFrame(() => {
1458
+ if (triggerRef.current) {
1459
+ triggerRef.current.setSelectionRange(newValue.length, newValue.length);
1460
+ }
1461
+ });
1462
+ setIsTyping(true);
1463
+ return;
1464
+ }
1465
+ }
1466
+ }
1467
+ if (event.key === "Delete") {
1468
+ const input = event.target;
1469
+ const cursorPosition = input.selectionStart || 0;
1470
+ const value2 = input.value;
1471
+ if (!disableRange && value2.includes(" - ")) {
1472
+ const dashIndex = value2.indexOf(" - ");
1473
+ const dashStart = dashIndex;
1474
+ const dashEnd = dashIndex + 3;
1475
+ if (cursorPosition >= dashStart && cursorPosition <= dashEnd) {
1476
+ event.preventDefault();
1477
+ const beforeDash = value2.slice(0, dashStart).trim();
1478
+ const yearMatch = beforeDash.match(/^(\d{2})\/(\d{2})\/(\d{4})$/);
1479
+ if (yearMatch) {
1480
+ const [, month, day, year] = yearMatch;
1481
+ const truncatedYear = year.slice(0, -1);
1482
+ const newValue = `${month}/${day}/${truncatedYear}`;
1483
+ const formattedValue = formatInputValue2(newValue);
1484
+ setInputValue(formattedValue);
1485
+ onChange("");
1486
+ requestAnimationFrame(() => {
1487
+ if (triggerRef.current) {
1488
+ triggerRef.current.setSelectionRange(formattedValue.length, formattedValue.length);
1489
+ }
1490
+ });
1491
+ } else {
1492
+ const formattedValue = formatInputValue2(beforeDash);
1493
+ setInputValue(formattedValue);
1494
+ const singleDate = parseInputDate(beforeDash);
1495
+ if (singleDate && isValidDate(singleDate)) {
1496
+ onChange(`${singleDate}|`);
1497
+ } else {
1498
+ onChange("");
1499
+ }
1500
+ requestAnimationFrame(() => {
1501
+ if (triggerRef.current) {
1502
+ const newPosition = formattedValue.length;
1503
+ triggerRef.current.setSelectionRange(newPosition, newPosition);
1504
+ }
1505
+ });
1506
+ }
1507
+ setIsTyping(true);
1508
+ return;
1509
+ }
1510
+ }
1511
+ }
1512
+ if (event.key === "Enter") {
1513
+ if (disableRange) {
1514
+ const parsedDate = parseInputDate(inputValue);
1515
+ if (parsedDate && isValidDate(parsedDate)) {
1516
+ onChange(`${parsedDate}|${parsedDate}`);
1517
+ setVisible(false);
1518
+ setIsTyping(false);
1519
+ }
1520
+ } else {
1521
+ const rangeMatch = inputValue.match(/^(.+?)\s*-\s*(.+)$/);
1522
+ if (rangeMatch) {
1523
+ const [, fromStr, toStr] = rangeMatch;
1524
+ const fromDate = parseInputDate(fromStr.trim());
1525
+ const toDate = parseInputDate(toStr.trim());
1526
+ if (fromDate && toDate && isValidDateRange2(fromDate, toDate)) {
1527
+ onChange(`${fromDate}|${toDate}`);
1528
+ setVisible(false);
1529
+ setIsTyping(false);
1530
+ } else {
1531
+ setInputValue("");
1532
+ onChange("");
1533
+ setVisible(false);
1534
+ setIsTyping(false);
1535
+ }
1536
+ } else {
1537
+ setInputValue("");
1538
+ onChange("");
1539
+ setVisible(false);
1540
+ setIsTyping(false);
1541
+ }
1542
+ }
1543
+ }
1544
+ };
1104
1545
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative", children: [
1105
1546
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1106
1547
  InputBase,
@@ -1110,15 +1551,17 @@ var DateRangeInput = (_a) => {
1110
1551
  triggerRef.current = el;
1111
1552
  }
1112
1553
  }, props), {
1113
- value: formatDisplayValue(from, to),
1114
- placeholder,
1554
+ value: inputValue,
1555
+ placeholder: disableRange ? "MM/DD/YYYY" : placeholder,
1115
1556
  disabled,
1557
+ readOnly,
1116
1558
  after: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "calendar_month" }),
1117
1559
  onFocus: handleFocus,
1118
- readOnly,
1119
- label,
1120
- onChange: () => {
1121
- }
1560
+ onClick: handleClick,
1561
+ onChange: handleInputChange,
1562
+ onBlur: handleBlur,
1563
+ onKeyDown: handleKeyDown,
1564
+ label
1122
1565
  })
1123
1566
  ),
1124
1567
  visible && !readOnly && (0, import_react_dom.createPortal)(
@@ -1142,7 +1585,8 @@ var DateRangeInput = (_a) => {
1142
1585
  to,
1143
1586
  onChange: handleRangeChange,
1144
1587
  cardStyle: true,
1145
- mode: single ? "single" : "double"
1588
+ mode: single ? "single" : "double",
1589
+ disableRange
1146
1590
  }
1147
1591
  )
1148
1592
  }
@@ -1150,8 +1594,77 @@ var DateRangeInput = (_a) => {
1150
1594
  findDocumentRoot(popoverRef.current)
1151
1595
  )
1152
1596
  ] });
1597
+ function formatInputValue2(value2) {
1598
+ return formatInputValueHelper(value2, disableRange);
1599
+ }
1600
+ function formatDisplayValue(from2, to2) {
1601
+ return formatDisplayValueHelper(from2, to2, disableRange);
1602
+ }
1153
1603
  };
1154
1604
  DateRangeInput.displayName = "DateRangeInput";
1605
+ function isValidDateRange2(fromDate, toDate) {
1606
+ return isValidDateRangeOrder(fromDate, toDate);
1607
+ }
1608
+ function formatInputValueHelper(value, disableRange) {
1609
+ if (disableRange) {
1610
+ return formatInputValue(value);
1611
+ }
1612
+ if (value.includes(" - ")) {
1613
+ const [from, to] = value.split(" - ");
1614
+ const fromFormatted = formatInputValue(from);
1615
+ const toFormatted = formatInputValue(to || "");
1616
+ return `${fromFormatted} - ${toFormatted}`;
1617
+ }
1618
+ const cleanValue = value.replace(/-/g, "");
1619
+ return formatInputValue(cleanValue);
1620
+ }
1621
+ function calculateCursorPositionHelper(originalValue, formattedValue, originalPosition, disableRange) {
1622
+ if (!disableRange && formattedValue.includes(" - ")) {
1623
+ const dashPosition = formattedValue.indexOf(" - ");
1624
+ const originalDashPosition = originalValue.indexOf("-");
1625
+ if (originalDashPosition !== -1 && originalPosition > originalDashPosition) {
1626
+ const afterDashDigits = originalValue.slice(originalDashPosition + 1).replace(/\D/g, "").length;
1627
+ const formattedAfterDash = formattedValue.slice(dashPosition + 3);
1628
+ let newPosition = dashPosition + 3;
1629
+ let digitCount = 0;
1630
+ for (let i = 0; i < formattedAfterDash.length; i++) {
1631
+ if (/\d/.test(formattedAfterDash[i])) {
1632
+ digitCount++;
1633
+ if (digitCount >= afterDashDigits) {
1634
+ if (i + 1 < formattedAfterDash.length && formattedAfterDash[i + 1] === "/") {
1635
+ newPosition = dashPosition + 3 + i + 2;
1636
+ } else {
1637
+ newPosition = dashPosition + 3 + i + 1;
1638
+ }
1639
+ break;
1640
+ }
1641
+ }
1642
+ if (digitCount < afterDashDigits) {
1643
+ newPosition = dashPosition + 3 + i + 1;
1644
+ }
1645
+ }
1646
+ return Math.min(newPosition, formattedValue.length);
1647
+ }
1648
+ }
1649
+ return calculateCursorPosition(originalValue, formattedValue, originalPosition);
1650
+ }
1651
+ function formatDisplayValueHelper(from, to, disableRange) {
1652
+ if (!from && !to) {
1653
+ return "";
1654
+ }
1655
+ const fromValid = from ? isValidDate(from) : false;
1656
+ const toValid = to ? isValidDate(to) : false;
1657
+ if (disableRange) {
1658
+ return fromValid && from ? formatDate(from) : "";
1659
+ }
1660
+ if (fromValid && toValid && from && to && isValidDateRange2(from, to)) {
1661
+ return `${formatDate(from)} - ${formatDate(to)}`;
1662
+ }
1663
+ if (fromValid && !to && from) {
1664
+ return `${formatDate(from)} - `;
1665
+ }
1666
+ return "";
1667
+ }
1155
1668
  // Annotate the CommonJS export names for ESM import in node:
1156
1669
  0 && (module.exports = {
1157
1670
  DateRangeInput