@wernfried/daterangepicker 5.4.6 → 5.4.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.
package/API_Doc.md CHANGED
@@ -13,7 +13,7 @@
13
13
  <dt><a href="#daterangepicker">daterangepicker(element, options, callback)</a> ⇒ <code><a href="#DateRangePicker">DateRangePicker</a></code> | <code><a href="#DateRangePicker">Array.&lt;DateRangePicker&gt;</a></code></dt>
14
14
  <dd><p>Initiate a new DateRangePicker</p>
15
15
  </dd>
16
- <dt><a href="#getDateRangePicker">getDateRangePicker(target)</a> ⇒ <code><a href="#DateRangePicker">DateRangePicker</a></code></dt>
16
+ <dt><a href="#getDateRangePicker">getDateRangePicker(element)</a> ⇒ <code><a href="#DateRangePicker">DateRangePicker</a></code></dt>
17
17
  <dd><p>Returns the DateRangePicker. Equivalent to <code>element._daterangepicker</code></p>
18
18
  </dd>
19
19
  </dl>
@@ -118,6 +118,7 @@ Ranges are not validated against <code>minDate</code>, <code>maxDate</code>, <co
118
118
  * [.updateAltInput()](#DateRangePicker+updateAltInput)
119
119
  * [.remove()](#DateRangePicker+remove)
120
120
  * [.triggerEvent(ev, ...args)](#DateRangePicker+triggerEvent)
121
+ * [.addEventListener(type, listener, [options])](#DateRangePicker+addEventListener)
121
122
 
122
123
  <a name="new_DateRangePicker_new"></a>
123
124
 
@@ -359,6 +360,26 @@ Helper function to dispatch events
359
360
  | ev | <code>object</code> | Event template from this.#events |
360
361
  | ...args | <code>object</code> | Additional parameters if needed |
361
362
 
363
+ <a name="DateRangePicker+addEventListener"></a>
364
+
365
+ ### dateRangePicker.addEventListener(type, listener, [options])
366
+ Adds an event listener to the anchor element (e.g., `<input>`) the DateRangePicker is attached to.
367
+ This allows external code to subscribe to native DOM events such as 'click', 'focus', 'keyup', etc.
368
+
369
+ **Kind**: instance method of [<code>DateRangePicker</code>](#DateRangePicker)
370
+
371
+ | Param | Type | Description |
372
+ | --- | --- | --- |
373
+ | type | <code>string</code> | The event name (e.g., 'click', 'focus', 'keyup') |
374
+ | listener | <code>function</code> | The callback function invoked when the event fires |
375
+ | [options] | <code>boolean</code> \| <code>object</code> | Optional event options: - `boolean capture`: Whether to listen in the capture phase (default: `false`) - `object signal`: An `AbortSignal` for later removal of the listener (default: `undefined`) |
376
+
377
+ **Example**
378
+ ```js
379
+ daterangepicker.addEventListener('click', (e) => {
380
+ console.log('Picker element was clicked', e);
381
+ });
382
+ ```
362
383
  <a name="DateRangePickerEvent"></a>
363
384
 
364
385
  ## DateRangePickerEvent ⇐ <code>Event</code>
@@ -380,7 +401,7 @@ Initiate a new DateRangePicker
380
401
 
381
402
  <a name="getDateRangePicker"></a>
382
403
 
383
- ## getDateRangePicker(target) ⇒ [<code>DateRangePicker</code>](#DateRangePicker)
404
+ ## getDateRangePicker(element) ⇒ [<code>DateRangePicker</code>](#DateRangePicker)
384
405
  Returns the DateRangePicker. Equivalent to `element._daterangepicker`
385
406
 
386
407
  **Kind**: global function
@@ -388,7 +409,7 @@ Returns the DateRangePicker. Equivalent to `element._daterangepicker`
388
409
 
389
410
  | Param | Type | Description |
390
411
  | --- | --- | --- |
391
- | target | <code>HTMLElement</code> \| <code>string</code> | The HTMLElement or querySelector string where the DateRangePicker is attached. |
412
+ | element | <code>HTMLElement</code> \| <code>string</code> | The HTMLElement or querySelector string where the DateRangePicker is attached. |
392
413
 
393
414
  <a name="event_violate"></a>
394
415
 
@@ -657,7 +678,7 @@ Options for DateRangePicker
657
678
  | timePicker24Hour | <code>boolean</code> | | Use 24-hour instead of 12-hour times, removing the AM/PM selection.<br> Default is derived from current locale [Intl.DateTimeFormat.resolvedOptions.hour12](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions#hour12). |
658
679
  | timePickerStepSize | [<code>Duration</code>](https://moment.github.io/luxon/api-docs/index.html#duration) \| <code>string</code> \| <code>number</code> | | Default: `Duration.fromObject({minutes:1})`<br>Set the time picker step size.<br> Must be a `luxon.Duration` or the number of seconds or a string according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) duration.<br> Valid values are 1,2,3,4,5,6,10,12,15,20,30 for `Duration.fromObject({seconds: ...})` and `Duration.fromObject({minutes: ...})` and 1,2,3,4,6,(8,12) for `Duration.fromObject({hours: ...})`.<br> Duration must be greater than `minSpan` and smaller than `maxSpan`.<br> For example `timePickerStepSize: 600` will disable time picker seconds and time picker minutes are set to step size of 10 Minutes. |
659
680
  | autoUpdateInput | <code>boolean</code> | <code>true</code> | Indicates whether the DateRangePicker should instantly update the value of the attached `<input>` element when the selected dates change.<br>The `<input>` element will be always updated on `Apply` and reverted when user clicks on `Cancel`. |
660
- | onOutsideClick | <code>string</code> | <code>&quot;apply&quot;</code> | Defines what picker shall do when user clicks outside the calendar. `'apply'` or `'cancel'`. Event [onOutsideClick](#event_outsideClick) is always emitted. |
681
+ | onOutsideClick | <code>string</code> | <code>&quot;apply&quot;</code> | Defines what picker shall do when user clicks outside the calendar. `'apply'` or `'cancel'`. Event [onOutsideClick](#event_outsideClick) is always emitted.return; If you like to do nothing (i.e. neither `apply` nor `cancel`), call `event.preventDefault()` in the event listener. |
661
682
  | linkedCalendars | <code>boolean</code> | <code>true</code> | When enabled, the two calendars displayed will always be for two sequential months (i.e. January and February), and both will be advanced when clicking the left or right arrows above the calendars.<br> When disabled, the two calendars can be individually advanced and display any month/year |
662
683
  | isInvalidDate | <code>function</code> | <code>false</code> | A function that is passed each date in the two calendars before they are displayed,<br> and may return `true` or `false` to indicate whether that date should be available for selection or not.<br> Signature: `isInvalidDate(date)`<br> |
663
684
  | isInvalidTime | <code>function</code> | <code>false</code> | A function that is passed each hour/minute/second/am-pm in the two calendars before they are displayed,<br> and may return `true` or `false` to indicate whether that date should be available for selection or not.<br> Signature: `isInvalidTime(time, side, unit)`<br> `side` is `'start'` or `'end'` or `null` for `singleDatePicker: true`<br> `unit` is `'hour'`, `'minute'`, `'second'` or `'ampm'`<br> Hours are always given as 24-hour clock<br> Ensure that your function returns `false` for at least one item. Otherwise the calender is not rendered.<br> |
package/README.md CHANGED
@@ -19,8 +19,8 @@ Above samples are based on the [original repository](https://github.com/dangross
19
19
  #### Global import with `<script>` tags
20
20
  ```html
21
21
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/luxon@3.5.0/build/global/luxon.min.js"></script>
22
- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.6/dist/global/daterangepicker.min.js"></script>
23
- <link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.6/css/daterangepicker.min.css" rel="stylesheet" />
22
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.10/dist/global/daterangepicker.min.js"></script>
23
+ <link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.10/css/daterangepicker.min.css" rel="stylesheet" />
24
24
 
25
25
  <input type="text" id="picker" />
26
26
 
@@ -40,11 +40,11 @@ Above samples are based on the [original repository](https://github.com/dangross
40
40
  {
41
41
  "imports": {
42
42
  "luxon": "https://cdn.jsdelivr.net/npm/luxon@3.7.2/+esm",
43
- "daterangepicker": "https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.6/+esm"
43
+ "daterangepicker": "https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.10/+esm"
44
44
  }
45
45
  }
46
46
  </script>
47
- <link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.6/css/daterangepicker.min.css" rel="stylesheet" />
47
+ <link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.10/css/daterangepicker.min.css" rel="stylesheet" />
48
48
 
49
49
  <input type="text" id="picker" />
50
50
 
@@ -63,9 +63,9 @@ Above samples are based on the [original repository](https://github.com/dangross
63
63
  #### Style with Bulma
64
64
  ```html
65
65
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/luxon@3.5.0/build/global/luxon.min.js"></script>
66
- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.6/dist/global/daterangepicker.min.js"></script>
66
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.10/dist/global/daterangepicker.min.js"></script>
67
67
  <link type="text/css" href="https://cdn.jsdelivr.net/npm/bulma@1.0.4/css/bulma.min.css" rel="stylesheet" />
68
- <link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.6/css/daterangepicker.bulma.min.css" rel="stylesheet" />
68
+ <link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.10/css/daterangepicker.bulma.min.css" rel="stylesheet" />
69
69
 
70
70
  <input type="text" id="picker" />
71
71
 
@@ -121,8 +121,8 @@ Initialisation with jQuery is supported in version 5.x
121
121
  ```html
122
122
  <script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
123
123
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/luxon@3.5.0/build/global/luxon.min.js"></script>
124
- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.6/dist/global/daterangepicker.min.js"></script>
125
- <link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.6/css/daterangepicker.min.css" rel="stylesheet" />
124
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.10/dist/global/daterangepicker.min.js"></script>
125
+ <link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@5.4.10/css/daterangepicker.min.css" rel="stylesheet" />
126
126
 
127
127
  <input type="text" id="picker" />
128
128
 
@@ -370,7 +370,7 @@ Options for DateRangePicker
370
370
  | timePicker24Hour | <code>boolean</code> | | Use 24-hour instead of 12-hour times, removing the AM/PM selection.<br> Default is derived from current locale [Intl.DateTimeFormat.resolvedOptions.hour12](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions#hour12). |
371
371
  | timePickerStepSize | [<code>Duration</code>](https://moment.github.io/luxon/api-docs/index.html#duration) \| <code>string</code> \| <code>number</code> | | Default: `Duration.fromObject({minutes:1})`<br>Set the time picker step size.<br> Must be a `luxon.Duration` or the number of seconds or a string according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) duration.<br> Valid values are 1,2,3,4,5,6,10,12,15,20,30 for `Duration.fromObject({seconds: ...})` and `Duration.fromObject({minutes: ...})` and 1,2,3,4,6,(8,12) for `Duration.fromObject({hours: ...})`.<br> Duration must be greater than `minSpan` and smaller than `maxSpan`.<br> For example `timePickerStepSize: 600` will disable time picker seconds and time picker minutes are set to step size of 10 Minutes. |
372
372
  | autoUpdateInput | <code>boolean</code> | <code>true</code> | Indicates whether the DateRangePicker should instantly update the value of the attached `<input>` element when the selected dates change.<br>The `<input>` element will be always updated on `Apply` and reverted when user clicks on `Cancel`. |
373
- | onOutsideClick | <code>string</code> | <code>&quot;apply&quot;</code> | Defines what picker shall do when user clicks outside the calendar. `'apply'` or `'cancel'`. Event [onOutsideClick](#event_outsideClick) is always emitted. |
373
+ | onOutsideClick | <code>string</code> | <code>&quot;apply&quot;</code> | Defines what picker shall do when user clicks outside the calendar. `'apply'` or `'cancel'`. Event [onOutsideClick](#event_outsideClick) is always emitted.return; If you like to do nothing (i.e. neither `apply` nor `cancel`), call `event.preventDefault()` in the event listener. |
374
374
  | linkedCalendars | <code>boolean</code> | <code>true</code> | When enabled, the two calendars displayed will always be for two sequential months (i.e. January and February), and both will be advanced when clicking the left or right arrows above the calendars.<br> When disabled, the two calendars can be individually advanced and display any month/year |
375
375
  | isInvalidDate | <code>function</code> | <code>false</code> | A function that is passed each date in the two calendars before they are displayed,<br> and may return `true` or `false` to indicate whether that date should be available for selection or not.<br> Signature: `isInvalidDate(date)`<br> |
376
376
  | isInvalidTime | <code>function</code> | <code>false</code> | A function that is passed each hour/minute/second/am-pm in the two calendars before they are displayed,<br> and may return `true` or `false` to indicate whether that date should be available for selection or not.<br> Signature: `isInvalidTime(time, side, unit)`<br> `side` is `'start'` or `'end'` or `null` for `singleDatePicker: true`<br> `unit` is `'hour'`, `'minute'`, `'second'` or `'ampm'`<br> Hours are always given as 24-hour clock<br> Ensure that your function returns `false` for at least one item. Otherwise the calender is not rendered.<br> |
@@ -166,6 +166,8 @@ class DateRangePicker {
166
166
  } else if (typeof options.parentEl === "string") {
167
167
  this.parentEl = document.querySelector(options.parentEl) ?? this.parentEl;
168
168
  }
169
+ if (this.parentEl.matches("input"))
170
+ console.error('Parent element "parentEl" must not a self-closing "<input>"');
169
171
  this.parentEl.appendChild(this.container);
170
172
  if (typeof options.timePicker === "boolean")
171
173
  this.timePicker = options.timePicker;
@@ -1605,7 +1607,7 @@ class DateRangePicker {
1605
1607
  top: offset(this.parentEl).top - this.parentEl.scrollTop,
1606
1608
  left: offset(this.parentEl).left - this.parentEl.scrollLeft
1607
1609
  };
1608
- parentRightEdge = this.parentEl.clientWidth + offset(this.parentEl).left;
1610
+ parentRightEdge = this.parentEl.clientWidth + parentOffset.left;
1609
1611
  }
1610
1612
  switch (this.drops) {
1611
1613
  case "auto":
@@ -2326,6 +2328,25 @@ class DateRangePicker {
2326
2328
  });
2327
2329
  });
2328
2330
  }
2331
+ /**
2332
+ * Adds an event listener to the anchor element (e.g., `<input>`) the DateRangePicker is attached to.
2333
+ * This allows external code to subscribe to native DOM events such as 'click', 'focus', 'keyup', etc.
2334
+ *
2335
+ * @param {string} type - The event name (e.g., 'click', 'focus', 'keyup')
2336
+ * @param {function} listener - The callback function invoked when the event fires
2337
+ * @param {boolean|object} [options] - Optional event options:
2338
+ * - `boolean capture`: Whether to listen in the capture phase (default: `false`)
2339
+ * - `object signal`: An `AbortSignal` for later removal of the listener (default: `undefined`)
2340
+ *
2341
+ * @example
2342
+ * daterangepicker.addEventListener('click', (e) => {
2343
+ * console.log('Picker element was clicked', e);
2344
+ * });
2345
+ *
2346
+ */
2347
+ addEventListener(type, listener, options) {
2348
+ this.element.addEventListener(type, listener, options);
2349
+ }
2329
2350
  }
2330
2351
  function createElementFromHTML(html) {
2331
2352
  const template = document.createElement("template");
@@ -2371,13 +2392,16 @@ function outerHeight(el, withMargin = false) {
2371
2392
  }
2372
2393
  function daterangepicker(element, options, callback) {
2373
2394
  if (element instanceof HTMLElement) {
2374
- return new DateRangePicker(element, options || {}, callback);
2375
- } else if (elements instanceof NodeList || element instanceof HTMLCollection) {
2395
+ element._daterangepicker = new DateRangePicker(element, options || {}, callback);
2396
+ return element._daterangepicker;
2397
+ } else if (element instanceof NodeList || element instanceof HTMLCollection) {
2376
2398
  const ret = [];
2377
2399
  for (const el of Array.from(element)) {
2378
2400
  if (el._daterangepicker && typeof el._daterangepicker.remove === "function")
2379
2401
  el._daterangepicker.remove();
2380
- ret.push(new DateRangePicker(el, options || {}, callback));
2402
+ const picker = new DateRangePicker(el, options || {}, callback);
2403
+ el._daterangepicker = picker;
2404
+ ret.push(picker);
2381
2405
  }
2382
2406
  return ret;
2383
2407
  } else if (typeof element === "string") {
@@ -2386,22 +2410,30 @@ function daterangepicker(element, options, callback) {
2386
2410
  for (const el of Array.from(document.querySelectorAll(element))) {
2387
2411
  if (el._daterangepicker && typeof el._daterangepicker.remove === "function")
2388
2412
  el._daterangepicker.remove();
2389
- ret.push(new DateRangePicker(el, options || {}, callback));
2413
+ const picker = new DateRangePicker(el, options || {}, callback);
2414
+ el._daterangepicker = picker;
2415
+ ret.push(picker);
2390
2416
  }
2391
2417
  return ret;
2392
2418
  } else if (document.querySelectorAll(element).length === 1) {
2393
- return new DateRangePicker(element, options || {}, callback);
2419
+ const picker = new DateRangePicker(element, options || {}, callback);
2420
+ document.querySelector(element)._daterangepicker = picker;
2421
+ return picker;
2394
2422
  } else {
2395
- return null;
2423
+ return void 0;
2396
2424
  }
2425
+ } else if (element == null) {
2426
+ return new DateRangePicker(element, options || {}, callback);
2397
2427
  } else {
2398
- return null;
2428
+ return void 0;
2399
2429
  }
2400
2430
  }
2401
- function getDateRangePicker(target) {
2402
- if (typeof target === "string")
2403
- target = document.querySelector(target);
2404
- return target instanceof HTMLElement ? target._daterangepicker : void 0;
2431
+ function getDateRangePicker(element) {
2432
+ if (typeof element === "string") {
2433
+ return document.querySelector(element)._daterangepicker;
2434
+ } else {
2435
+ return element instanceof HTMLElement ? element._daterangepicker : void 0;
2436
+ }
2405
2437
  }
2406
2438
  if (window.jQuery?.fn) {
2407
2439
  jQuery.fn.daterangepicker = function(options, callback) {