@wernfried/daterangepicker 5.2.7 → 5.2.10

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.
@@ -15,7 +15,7 @@ class DateRangePicker {
15
15
  this.maxSpan = null;
16
16
  this.minSpan = null;
17
17
  this.defaultSpan = null;
18
- this.initalMonth = DateTime.now().startOf("month");
18
+ this.initialMonth = DateTime.now().startOf("month");
19
19
  this.autoApply = false;
20
20
  this.singleDatePicker = false;
21
21
  this.singleMonthView = false;
@@ -80,7 +80,7 @@ class DateRangePicker {
80
80
  if (!Object.keys(this).concat(["startDate", "endDate"]).includes(name) || Object.keys(options).includes(name))
81
81
  continue;
82
82
  let ts = DateTime.fromISO(item.value);
83
- const isDate = ["startDate", "endDate", "minDate", "maxDate", "initalMonth"].includes(name);
83
+ const isDate = ["startDate", "endDate", "minDate", "maxDate", "initialMonth"].includes(name);
84
84
  dataOptions[name] = ts.isValid && isDate ? ts : JSON.parse(item.value);
85
85
  }
86
86
  options = { ...dataOptions, ...options };
@@ -295,7 +295,7 @@ class DateRangePicker {
295
295
  secondStep: this.timePickerStepSize.seconds
296
296
  };
297
297
  }
298
- for (let opt of ["startDate", "endDate", "minDate", "maxDate", "initalMonth"]) {
298
+ for (let opt of ["startDate", "endDate", "minDate", "maxDate", "initialMonth"]) {
299
299
  if (opt === "endDate" && this.singleDatePicker)
300
300
  continue;
301
301
  if (typeof options[opt] === "object") {
@@ -358,10 +358,10 @@ class DateRangePicker {
358
358
  if (this.#startDate) this.#startDate = this.#startDate.startOf("day");
359
359
  if (this.#endDate) this.#endDate = this.#endDate.endOf("day");
360
360
  }
361
- if (!this.#startDate && this.initalMonth) {
361
+ if (!this.#startDate && this.initialMonth) {
362
362
  this.#endDate = null;
363
363
  if (this.timePicker)
364
- console.error(`Option 'initalMonth' works only with 'timePicker: false'`);
364
+ console.error(`Option 'initialMonth' works only with 'timePicker: false'`);
365
365
  } else {
366
366
  const violations = this.validateInput(null, false);
367
367
  if (violations != null) {
@@ -1152,10 +1152,10 @@ class DateRangePicker {
1152
1152
  }
1153
1153
  }
1154
1154
  } else {
1155
- if (!this.#startDate && this.initalMonth) {
1156
- this.leftCalendar.month = this.initalMonth;
1155
+ if (!this.#startDate && this.initialMonth) {
1156
+ this.leftCalendar.month = this.initialMonth;
1157
1157
  if (!this.singleMonthView)
1158
- this.rightCalendar.month = this.initalMonth.plus({ month: 1 });
1158
+ this.rightCalendar.month = this.initialMonth.plus({ month: 1 });
1159
1159
  } else {
1160
1160
  if (!this.leftCalendar.month.hasSame(this.#startDate, "month") && !this.rightCalendar.month.hasSame(this.#startDate, "month")) {
1161
1161
  this.leftCalendar.month = this.#startDate.startOf("month");
@@ -1238,8 +1238,8 @@ class DateRangePicker {
1238
1238
  if (side === "right" && this.singleMonthView)
1239
1239
  return;
1240
1240
  var calendar = side === "left" ? this.leftCalendar : this.rightCalendar;
1241
- if (calendar.month == null && !this.#startDate && this.initalMonth)
1242
- calendar.month = this.initalMonth.startOf("month");
1241
+ if (calendar.month == null && !this.#startDate && this.initialMonth)
1242
+ calendar.month = this.initialMonth.startOf("month");
1243
1243
  const firstDay = calendar.month.startOf("month");
1244
1244
  const lastDay = calendar.month.endOf("month").startOf("day");
1245
1245
  var theDate = calendar.month.startOf("month").minus({ day: 1 });
@@ -1396,6 +1396,7 @@ class DateRangePicker {
1396
1396
  if (maxDate && selected > maxDate)
1397
1397
  selected = maxDate;
1398
1398
  }
1399
+ let disabled = { hour: false, minute: false, second: false, ampm: false };
1399
1400
  html += `<th colspan="7">`;
1400
1401
  if (this.externalStyle === "bulma")
1401
1402
  html += '<div class="select is-small mx-1">';
@@ -1406,19 +1407,18 @@ class DateRangePicker {
1406
1407
  start = ampm === "AM" ? 1 : 13;
1407
1408
  for (var i = start; i <= start + 23; i += this.timePickerOpts.hourStep) {
1408
1409
  let time = selected.set({ hour: i % 24 });
1409
- let disabled = false;
1410
1410
  if (minDate && time.set({ minute: 59 }) < minDate)
1411
- disabled = true;
1411
+ disabled.hour = true;
1412
1412
  if (maxDate && time.set({ minute: 0 }) > maxDate)
1413
- disabled = true;
1413
+ disabled.hour = true;
1414
1414
  if (minLimit && time.endOf("hour") < minLimit)
1415
- disabled = true;
1416
- if (!disabled && this.isInvalidTime(time, this.singleDatePicker ? null : side, "hour"))
1417
- disabled = true;
1415
+ disabled.hour = true;
1416
+ if (!disabled.hour && this.isInvalidTime(time, this.singleDatePicker ? null : side, "hour"))
1417
+ disabled.hour = true;
1418
1418
  if (this.timePicker24Hour) {
1419
- if (!disabled && i == selected.hour) {
1419
+ if (!disabled.hour && i == selected.hour) {
1420
1420
  html += `<option value="${i}" selected>${i}</option>`;
1421
- } else if (disabled) {
1421
+ } else if (disabled.hour) {
1422
1422
  html += `<option value="${i}" disabled class="disabled">${i}</option>`;
1423
1423
  } else {
1424
1424
  html += `<option value="${i}">${i}</option>`;
@@ -1427,9 +1427,9 @@ class DateRangePicker {
1427
1427
  const i_12 = DateTime.fromFormat(`${i % 24}`, "H").toFormat("h");
1428
1428
  const i_ampm = DateTime.fromFormat(`${i % 24}`, "H").toFormat("a", { locale: "en-US" });
1429
1429
  if (ampm == i_ampm) {
1430
- if (!disabled && i == selected.hour) {
1430
+ if (!disabled.hour && i == selected.hour) {
1431
1431
  html += `<option ampm="${i_ampm}" value="${i % 24}" selected>${i_12}</option>`;
1432
- } else if (disabled) {
1432
+ } else if (disabled.hour) {
1433
1433
  html += `<option ampm="${i_ampm}" value="${i % 24}" disabled class="disabled">${i_12}</option>`;
1434
1434
  } else {
1435
1435
  html += `<option ampm="${i_ampm}" value="${i % 24}">${i_12}</option>`;
@@ -1450,18 +1450,19 @@ class DateRangePicker {
1450
1450
  for (var i = 0; i < 60; i += this.timePickerOpts.minuteStep) {
1451
1451
  var padded = i < 10 ? "0" + i : i;
1452
1452
  let time = selected.set({ minute: i });
1453
- let disabled = false;
1453
+ if (disabled.hour)
1454
+ disabled.minute = true;
1454
1455
  if (minDate && time.set({ second: 59 }) < minDate)
1455
- disabled = true;
1456
+ disabled.minute = true;
1456
1457
  if (maxDate && time.set({ second: 0 }) > maxDate)
1457
- disabled = true;
1458
+ disabled.minute = true;
1458
1459
  if (minLimit && time.endOf("minute") < minLimit)
1459
- disabled = true;
1460
- if (!disabled && this.isInvalidTime(time, this.singleDatePicker ? null : side, "minute"))
1461
- disabled = true;
1462
- if (selected.minute == i && !disabled) {
1460
+ disabled.minute = true;
1461
+ if (!disabled.minute && this.isInvalidTime(time, this.singleDatePicker ? null : side, "minute"))
1462
+ disabled.minute = true;
1463
+ if (selected.minute == i && !disabled.minute) {
1463
1464
  html += `<option value="${i}" selected>${padded}</option>`;
1464
- } else if (disabled) {
1465
+ } else if (disabled.minute) {
1465
1466
  html += `<option value="${i}" disabled class="disabled">${padded}</option>`;
1466
1467
  } else {
1467
1468
  html += `<option value="${i}">${padded}</option>`;
@@ -1479,18 +1480,19 @@ class DateRangePicker {
1479
1480
  for (var i = 0; i < 60; i += this.timePickerOpts.secondStep) {
1480
1481
  var padded = i < 10 ? "0" + i : i;
1481
1482
  let time = selected.set({ second: i });
1482
- let disabled = false;
1483
+ if (disabled.minute)
1484
+ disabled.second = true;
1483
1485
  if (minDate && time < minDate)
1484
- disabled = true;
1486
+ disabled.second = true;
1485
1487
  if (maxDate && time > maxDate)
1486
- disabled = true;
1488
+ disabled.second = true;
1487
1489
  if (minLimit && time < minLimit)
1488
- disabled = true;
1489
- if (!disabled && this.isInvalidTime(time, this.singleDatePicker ? null : side, "second"))
1490
- disabled = true;
1491
- if (selected.second == i && !disabled) {
1490
+ disabled.second = true;
1491
+ if (!disabled.second && this.isInvalidTime(time, this.singleDatePicker ? null : side, "second"))
1492
+ disabled.second = true;
1493
+ if (selected.second == i && !disabled.second) {
1492
1494
  html += `<option value="${i}" selected>${padded}</option>`;
1493
- } else if (disabled) {
1495
+ } else if (disabled.second) {
1494
1496
  html += `<option value="${i}" disabled class="disabled">${padded}</option>`;
1495
1497
  } else {
1496
1498
  html += `<option value="${i}">${padded}</option>`;
@@ -1506,14 +1508,15 @@ class DateRangePicker {
1506
1508
  html += '<select class="ampmselect">';
1507
1509
  var am_html = "";
1508
1510
  var pm_html = "";
1509
- let disabled = false;
1511
+ if (disabled.hour)
1512
+ disabled.ampm = true;
1510
1513
  if (minDate && selected.startOf("day") < minDate)
1511
- disabled = true;
1514
+ disabled.ampm = true;
1512
1515
  if (maxDate && selected.endOf("day") > maxDate)
1513
- disabled = true;
1516
+ disabled.ampm = true;
1514
1517
  if (minLimit && selected.startOf("day") < minLimit)
1515
- disabled = true;
1516
- if (disabled) {
1518
+ disabled.ampm = true;
1519
+ if (disabled.ampm) {
1517
1520
  am_html = ' disabled class="disabled "';
1518
1521
  pm_html = ' disabled class="disabled"';
1519
1522
  } else {
@@ -1779,7 +1782,7 @@ class DateRangePicker {
1779
1782
  const leftCalendar = this.leftCalendar;
1780
1783
  const rightCalendar = this.rightCalendar;
1781
1784
  const startDate = this.#startDate;
1782
- const initalMonth = this.initalMonth;
1785
+ const initialMonth = this.initialMonth;
1783
1786
  if (!this.#endDate) {
1784
1787
  this.container.querySelectorAll(".drp-calendar tbody td").forEach((el) => {
1785
1788
  if (el.classList.contains("week")) return;
@@ -1788,7 +1791,7 @@ class DateRangePicker {
1788
1791
  const col2 = title2.substring(3, 4);
1789
1792
  const cal2 = el.closest(".drp-calendar");
1790
1793
  const dt = cal2.classList.contains("left") ? leftCalendar.calendar[row2][col2] : rightCalendar.calendar[row2][col2];
1791
- if (!startDate && initalMonth) {
1794
+ if (!startDate && initialMonth) {
1792
1795
  el.classList.remove("in-range");
1793
1796
  } else {
1794
1797
  el.classList.toggle("in-range", dt > startDate && dt < date || dt.hasSame(date, "day"));
@@ -2179,7 +2182,7 @@ class DateRangePicker {
2179
2182
  * @emits external:change
2180
2183
  */
2181
2184
  updateElement() {
2182
- if (this.#startDate == null && this.initalMonth)
2185
+ if (this.#startDate == null && this.initialMonth)
2183
2186
  return;
2184
2187
  if (this.isInputText) {
2185
2188
  let newValue = this.formatDate(this.#startDate);