@wernfried/daterangepicker 5.5.1 → 5.6.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.
@@ -454,10 +454,10 @@ var DateRangePicker = (function(exports, luxon2) {
454
454
  this.buttonClasses = options.buttonClasses;
455
455
  }
456
456
  if (typeof options.onOutsideClick === "string") {
457
- if (["cancel", "apply"].includes(options.onOutsideClick))
457
+ if (["cancel", "apply", "hide"].includes(options.onOutsideClick))
458
458
  this.onOutsideClick = options.onOutsideClick;
459
459
  else
460
- console.error(`Option 'onOutsideClick' must be 'cancel' or 'apply'`);
460
+ console.error(`Option 'onOutsideClick' must be 'cancel', 'apply' or 'hide'`);
461
461
  }
462
462
  if (this.locale.firstDay != 1) {
463
463
  let iterator = this.locale.firstDay;
@@ -1698,14 +1698,10 @@ var DateRangePicker = (function(exports, luxon2) {
1698
1698
  */
1699
1699
  hide() {
1700
1700
  if (!this.isShowing) return;
1701
- if (!this.#endDate) {
1701
+ if (!this.#endDate && !this.singleDatePicker) {
1702
1702
  this.#startDate = this.oldStartDate;
1703
1703
  this.#endDate = this.oldEndDate;
1704
1704
  }
1705
- if (typeof this.callback === "function") {
1706
- if (this.#startDate && !this.#startDate.equals(this.oldStartDate ?? luxon2.DateTime) || this.#endDate && !this.singleDatePicker && !this.#endDate.equals(this.oldEndDate ?? luxon2.DateTime))
1707
- this.callback(this.startDate, this.endDate, this.chosenLabel);
1708
- }
1709
1705
  this.updateElement();
1710
1706
  const event = this.triggerEvent(this.#events.onBeforeHide);
1711
1707
  if (event.defaultPrevented)
@@ -1777,8 +1773,12 @@ var DateRangePicker = (function(exports, luxon2) {
1777
1773
  if (this.onOutsideClick === "cancel") {
1778
1774
  this.#startDate = this.oldStartDate;
1779
1775
  this.#endDate = this.oldEndDate;
1776
+ this.hide();
1777
+ } else if (this.onOutsideClick === "apply") {
1778
+ this.clickApply();
1779
+ } else {
1780
+ this.hide();
1780
1781
  }
1781
- this.hide();
1782
1782
  }
1783
1783
  /**
1784
1784
  * Move calendar to previous month
@@ -2141,6 +2141,11 @@ var DateRangePicker = (function(exports, luxon2) {
2141
2141
  * @private
2142
2142
  */
2143
2143
  clickApply() {
2144
+ this.updateElement();
2145
+ if (typeof this.callback === "function") {
2146
+ if (this.#startDate && (this.#endDate || !this.singleDatePicker))
2147
+ this.callback(this.startDate, this.endDate, this.chosenLabel);
2148
+ }
2144
2149
  this.hide();
2145
2150
  this.triggerEvent(this.#events.onApply);
2146
2151
  }
@@ -2335,24 +2340,37 @@ var DateRangePicker = (function(exports, luxon2) {
2335
2340
  });
2336
2341
  }
2337
2342
  /**
2338
- * Adds an event listener to the anchor element (e.g., `<input>`) the DateRangePicker is attached to.
2339
- * This allows external code to subscribe to native DOM events such as 'click', 'focus', 'keyup', etc.
2343
+ * Adding event listener to input element where dateragnepicker is attached to.
2344
+ * Wrapper to give easy access for `addEventListener()` on DateRangePicker instance.
2340
2345
  *
2341
- * @param {string} type - The event name (e.g., 'click', 'focus', 'keyup')
2346
+ * @param {string} type - The event name, either native DOM-Event or [DateRangePicker](API_Doc.md#event) specific event
2342
2347
  * @param {function} listener - The callback function invoked when the event fires
2343
2348
  * @param {boolean|object} [options] - Optional event options:
2344
2349
  * - `boolean capture`: Whether to listen in the capture phase (default: `false`)
2345
2350
  * - `object signal`: An `AbortSignal` for later removal of the listener (default: `undefined`)
2346
2351
  *
2347
2352
  * @example
2348
- * daterangepicker.addEventListener('click', (e) => {
2349
- * console.log('Picker element was clicked', e);
2353
+ * picker.addEventListener('hide', (e) => {
2354
+ * console.log('Picker element was hidden', e);
2350
2355
  * });
2351
2356
  *
2352
2357
  */
2353
2358
  addEventListener(type, listener, options) {
2354
2359
  this.element.addEventListener(type, listener, options);
2355
2360
  }
2361
+ /**
2362
+ * Counterpart to `addEventListener()`
2363
+ * Note, `listener` most be a named function to enable remove.
2364
+ *
2365
+ * @param {string} type - The event name, either native
2366
+ * @param {function} listener - The callback function invoked when the event fires
2367
+ * @param {boolean|object} [options] - Optional event options:
2368
+ * - `boolean capture`: Whether to listen in the capture phase (default: `false`)
2369
+ * - `object signal`: An `AbortSignal` for later removal of the listener (default: `undefined`)
2370
+ */
2371
+ removeEventListener(type, listener, options) {
2372
+ this.element.removeEventListener(type, listener, options);
2373
+ }
2356
2374
  }
2357
2375
  function createElementFromHTML(html) {
2358
2376
  const template = document.createElement("template");