@wernfried/daterangepicker 5.6.1 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -384,8 +384,6 @@ var DateRangePicker = (function(exports, luxon2) {
384
384
  }
385
385
  if (!this.#startDate && this.initialMonth) {
386
386
  this.#endDate = null;
387
- if (this.timePicker)
388
- console.error(`Option 'initialMonth' works only with 'timePicker: false'`);
389
387
  } else {
390
388
  const violations = this.validateInput(null, false);
391
389
  if (violations != null) {
@@ -872,6 +870,31 @@ var DateRangePicker = (function(exports, luxon2) {
872
870
  this.updateView(monthChange);
873
871
  return violations;
874
872
  }
873
+ /**
874
+ * Clear selected date values.
875
+ * Does not invoke callback function, disables "Apply" button
876
+ * @param {sting|external:DateTime|Date} month - The month to be shown, if null then current month is selected.
877
+ */
878
+ clearDate(month) {
879
+ const initialMonth = this.parseDate(month ?? this.#startDate.startOf("month"));
880
+ this.oldStartDate = this.#startDate;
881
+ this.oldEndDate = this.#endDate;
882
+ this.#startDate = null;
883
+ this.#endDate = null;
884
+ if (this.isInputText)
885
+ this.element.value = "";
886
+ if (!this.singleDatePicker)
887
+ this.chosenLabel = null;
888
+ if (this.altInput) {
889
+ if (this.singleDatePicker) {
890
+ this.altInput.value = "";
891
+ } else {
892
+ this.altInput[0].value = "";
893
+ this.altInput[1].value = "";
894
+ }
895
+ }
896
+ this.updateView(!initialMonth.hasSame(this.oldStartDate, "month"));
897
+ }
875
898
  /**
876
899
  * Parse date value
877
900
  * @param {sting|external:DateTime|Date} value - The value to be parsed
@@ -884,7 +907,7 @@ var DateRangePicker = (function(exports, luxon2) {
884
907
  } else if (value instanceof Date) {
885
908
  return luxon2.DateTime.fromJSDate(value);
886
909
  } else {
887
- throw RangeError(`Value must be a luxon.DateTime or Date or string`);
910
+ throw RangeError(`Value must be a luxon.DateTime or Date or string. Or use clearDate() to clear date values`);
888
911
  }
889
912
  } else if (typeof value === "string") {
890
913
  const format = typeof this.locale.format === "string" ? this.locale.format : luxon2.DateTime.parseFormatForOpts(this.locale.format);
@@ -1214,42 +1237,48 @@ var DateRangePicker = (function(exports, luxon2) {
1214
1237
  updateCalendars(monthChange) {
1215
1238
  if (this.timePicker) {
1216
1239
  var hour, minute, second;
1217
- if (this.#endDate) {
1218
- hour = parseInt(this.container.querySelector(".start-time .hourselect").value, 10);
1219
- if (isNaN(hour))
1220
- hour = parseInt(this.container.querySelector(".start-time .hourselect option:last-child").value, 10);
1221
- minute = 0;
1222
- if (this.timePickerOpts.showMinutes) {
1223
- minute = parseInt(this.container.querySelector(".start-time .minuteselect").value, 10);
1224
- if (isNaN(minute))
1225
- minute = parseInt(this.container.querySelector(".start-time .minuteselect option:last-child").value, 10);
1226
- }
1227
- second = 0;
1228
- if (this.timePickerOpts.showSeconds) {
1229
- second = parseInt(this.container.querySelector(".start-time .secondselect").value, 10);
1230
- if (isNaN(second))
1231
- second = parseInt(this.container.querySelector(".start-time .secondselect option:last-child").value, 10);
1232
- }
1240
+ if (this.#startDate == null && this.#endDate == null) {
1241
+ this.leftCalendar.month = this.leftCalendar.month.set({ hour: 0, minute: 0, second: 0 });
1242
+ if (!this.singleMonthView)
1243
+ this.rightCalendar.month = this.rightCalendar.month.set({ hour: 0, minute: 0, second: 0 });
1233
1244
  } else {
1234
- hour = parseInt(this.container.querySelector(".end-time .hourselect").value, 10);
1235
- if (isNaN(hour))
1236
- hour = parseInt(this.container.querySelector(".end-time .hourselect option:last-child").value, 10);
1237
- minute = 0;
1238
- if (this.timePickerOpts.showMinutes) {
1239
- minute = parseInt(this.container.querySelector(".end-time .minuteselect").value, 10);
1240
- if (isNaN(minute))
1241
- minute = parseInt(this.container.querySelector(".end-time .minuteselect option:last-child").value, 10);
1242
- }
1243
- second = 0;
1244
- if (this.timePickerOpts.showSeconds) {
1245
- second = parseInt(this.container.querySelector(".end-time .secondselect").value, 10);
1246
- if (isNaN(second))
1247
- second = parseInt(this.container.querySelector(".end-time .secondselect option:last-child").value, 10);
1245
+ if (this.#endDate) {
1246
+ hour = parseInt(this.container.querySelector(".start-time .hourselect").value, 10);
1247
+ if (isNaN(hour))
1248
+ hour = parseInt(this.container.querySelector(".start-time .hourselect option:last-child").value, 10);
1249
+ minute = 0;
1250
+ if (this.timePickerOpts.showMinutes) {
1251
+ minute = parseInt(this.container.querySelector(".start-time .minuteselect").value, 10);
1252
+ if (isNaN(minute))
1253
+ minute = parseInt(this.container.querySelector(".start-time .minuteselect option:last-child").value, 10);
1254
+ }
1255
+ second = 0;
1256
+ if (this.timePickerOpts.showSeconds) {
1257
+ second = parseInt(this.container.querySelector(".start-time .secondselect").value, 10);
1258
+ if (isNaN(second))
1259
+ second = parseInt(this.container.querySelector(".start-time .secondselect option:last-child").value, 10);
1260
+ }
1261
+ } else {
1262
+ hour = parseInt(this.container.querySelector(".end-time .hourselect").value, 10);
1263
+ if (isNaN(hour))
1264
+ hour = parseInt(this.container.querySelector(".end-time .hourselect option:last-child").value, 10);
1265
+ minute = 0;
1266
+ if (this.timePickerOpts.showMinutes) {
1267
+ minute = parseInt(this.container.querySelector(".end-time .minuteselect").value, 10);
1268
+ if (isNaN(minute))
1269
+ minute = parseInt(this.container.querySelector(".end-time .minuteselect option:last-child").value, 10);
1270
+ }
1271
+ second = 0;
1272
+ if (this.timePickerOpts.showSeconds) {
1273
+ second = parseInt(this.container.querySelector(".end-time .secondselect").value, 10);
1274
+ if (isNaN(second))
1275
+ second = parseInt(this.container.querySelector(".end-time .secondselect option:last-child").value, 10);
1276
+ }
1248
1277
  }
1278
+ this.leftCalendar.month = this.leftCalendar.month.set({ hour, minute, second });
1279
+ if (!this.singleMonthView)
1280
+ this.rightCalendar.month = this.rightCalendar.month.set({ hour, minute, second });
1249
1281
  }
1250
- this.leftCalendar.month = this.leftCalendar.month.set({ hour, minute, second });
1251
- if (!this.singleMonthView)
1252
- this.rightCalendar.month = this.rightCalendar.month.set({ hour, minute, second });
1253
1282
  } else {
1254
1283
  this.leftCalendar.month = this.leftCalendar.month.set({ hour: 0, minute: 0, second: 0 });
1255
1284
  if (!this.singleMonthView)
@@ -1404,20 +1433,27 @@ var DateRangePicker = (function(exports, luxon2) {
1404
1433
  * @emits "beforeRenderTimePicker"
1405
1434
  */
1406
1435
  renderTimePicker(side) {
1407
- if (side === "end" && !this.#endDate) return;
1436
+ if (side === "end" && !this.#endDate && this.#startDate) return;
1408
1437
  var selected, minLimit, minDate, maxDate = this.maxDate;
1409
1438
  let html = "";
1410
1439
  if (this.showWeekNumbers || this.showISOWeekNumbers)
1411
1440
  html += "<th></th>";
1412
- if (this.maxSpan && (!this.maxDate || this.#startDate.plus(this.maxSpan) < this.maxDate))
1413
- maxDate = this.#startDate.plus(this.maxSpan);
1414
- if (this.minSpan && side === "end")
1415
- minLimit = this.#startDate.plus(this.minSpan);
1441
+ if (this.#startDate) {
1442
+ if (this.maxSpan && (!this.maxDate || this.#startDate.plus(this.maxSpan) < this.maxDate))
1443
+ maxDate = this.#startDate.plus(this.maxSpan);
1444
+ if (this.minSpan && side === "end")
1445
+ minLimit = this.#startDate.plus(this.minSpan);
1446
+ } else {
1447
+ if (this.maxSpan && (!this.maxDate || this.initialMonth.plus(this.maxSpan) < this.maxDate))
1448
+ maxDate = this.initialMonth.plus(this.maxSpan);
1449
+ if (this.minSpan && side === "end")
1450
+ minLimit = this.initialMonth.plus(this.minSpan);
1451
+ }
1416
1452
  if (side === "start") {
1417
- selected = this.#startDate;
1453
+ selected = this.#startDate ?? this.initialMonth.startOf("day");
1418
1454
  minDate = this.minDate;
1419
1455
  } else if (side === "end") {
1420
- selected = this.#endDate;
1456
+ selected = this.#endDate ?? this.initialMonth.startOf("day");
1421
1457
  minDate = this.#startDate;
1422
1458
  let timeSelector = this.container.querySelector(".drp-calendar .calendar-time.end-time");
1423
1459
  if (timeSelector.innerHTML != "") {