@wernfried/daterangepicker 5.7.1 → 5.8.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.
- package/API_Doc.md +8 -6
- package/README.md +10 -10
- package/dist/cjs/daterangepicker.cjs +61 -32
- package/dist/cjs/daterangepicker.cjs.map +1 -1
- package/dist/cjs/daterangepicker.min.cjs +1 -1
- package/dist/cjs/daterangepicker.min.cjs.map +1 -1
- package/dist/esm/daterangepicker.js +62 -33
- package/dist/esm/daterangepicker.js.map +1 -1
- package/dist/esm/daterangepicker.min.js +1 -1
- package/dist/esm/daterangepicker.min.js.map +1 -1
- package/dist/global/daterangepicker.js +61 -32
- package/dist/global/daterangepicker.js.map +1 -1
- package/dist/global/daterangepicker.min.js +1 -1
- package/dist/global/daterangepicker.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -413,27 +413,33 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
|
-
if (
|
|
417
|
-
|
|
416
|
+
if (["function", "string", "object"].includes(typeof options.altFormat))
|
|
417
|
+
this.altFormat = options.altFormat;
|
|
418
|
+
if (typeof options.altInput === "string") {
|
|
419
|
+
if (this.singleDatePicker) {
|
|
418
420
|
const el = document.querySelector(options.altInput);
|
|
419
|
-
this.altInput = el instanceof HTMLInputElement && ["text", "hidden"].includes(el.type) ? el : null;
|
|
420
|
-
} else if (options.altInput instanceof HTMLElement) {
|
|
421
|
-
this.altInput = options.altInput instanceof HTMLInputElement && ["text", "hidden"].includes(options.altInput.type) ? options.altInput : null;
|
|
422
|
-
}
|
|
423
|
-
} else if (!this.singleDatePicker && Array.isArray(options.altInput) && options.altInput.length === 2) {
|
|
424
|
-
this.altInput = [];
|
|
425
|
-
for (let item of options.altInput) {
|
|
426
|
-
const el = typeof item === "string" ? document.querySelector(item) : item;
|
|
427
421
|
if (el instanceof HTMLInputElement && ["text", "hidden"].includes(el.type))
|
|
428
|
-
this.altInput
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
|
|
422
|
+
this.altInput = el;
|
|
423
|
+
} else {
|
|
424
|
+
const el = Array.from(document.querySelectorAll(options.altInput));
|
|
425
|
+
if ([1, 2].includes(el.length) && el.every((x) => x instanceof HTMLInputElement && ["text", "hidden"].includes(x.type)))
|
|
426
|
+
this.altInput = el.length === 1 ? el[0] : el;
|
|
427
|
+
}
|
|
428
|
+
} else if (options.altInput instanceof HTMLElement && ["text", "hidden"].includes(options.altInput.type)) {
|
|
429
|
+
this.altInput = options.altInput;
|
|
430
|
+
} else if (Array.isArray(options.altInput) || options.altInput instanceof HTMLCollection || options.altInput instanceof NodeList) {
|
|
431
|
+
let el = Array.isArray(options.altInput) ? options.altInput : Array.from(options.altInput);
|
|
432
|
+
if (!this.singleDatePicker && el.length === 2) {
|
|
433
|
+
if (el.every((x) => typeof x === "string"))
|
|
434
|
+
el = el.map((x) => {
|
|
435
|
+
return document.querySelector(x);
|
|
436
|
+
});
|
|
437
|
+
if (el.every((x) => x instanceof HTMLInputElement && ["text", "hidden"].includes(x.type)))
|
|
438
|
+
this.altInput = el;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (options.altInput != null && this.altInput == null)
|
|
442
|
+
console.error(`Option 'altInput' ${JSON.stringify(options.altInput)} is not valid`);
|
|
437
443
|
if (typeof options.opens === "string") {
|
|
438
444
|
if (["left", "right", "center"].includes(options.opens))
|
|
439
445
|
this.opens = options.opens;
|
|
@@ -886,7 +892,7 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
886
892
|
if (!this.singleDatePicker)
|
|
887
893
|
this.chosenLabel = null;
|
|
888
894
|
if (this.altInput) {
|
|
889
|
-
if (this.singleDatePicker) {
|
|
895
|
+
if (this.singleDatePicker || !Array.isArray(this.altInput)) {
|
|
890
896
|
this.altInput.value = "";
|
|
891
897
|
} else {
|
|
892
898
|
this.altInput[0].value = "";
|
|
@@ -2300,7 +2306,7 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
2300
2306
|
updateAltInput() {
|
|
2301
2307
|
if (this.altInput == null)
|
|
2302
2308
|
return;
|
|
2303
|
-
if (this.altFormat == null) {
|
|
2309
|
+
if (this.altFormat == null || typeof this.altFormat === "object") {
|
|
2304
2310
|
let precision = "day";
|
|
2305
2311
|
if (this.timePicker) {
|
|
2306
2312
|
if (this.timePickerOpts.showSeconds) {
|
|
@@ -2311,18 +2317,37 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
2311
2317
|
precision = "hour";
|
|
2312
2318
|
}
|
|
2313
2319
|
}
|
|
2314
|
-
const
|
|
2315
|
-
|
|
2316
|
-
if (
|
|
2317
|
-
|
|
2318
|
-
|
|
2320
|
+
const isoOptions = this.altFormat ?? { format: "basic", precision, includeOffset: false };
|
|
2321
|
+
const startDate = this.#startDate.toISO(isoOptions);
|
|
2322
|
+
if (this.singleDatePicker) {
|
|
2323
|
+
this.altInput.value = startDate;
|
|
2324
|
+
} else if (this.#endDate) {
|
|
2325
|
+
const endDate = this.#endDate.toISO(isoOptions);
|
|
2326
|
+
if (Array.isArray(this.altInput)) {
|
|
2327
|
+
this.altInput[0].value = startDate;
|
|
2328
|
+
this.altInput[1].value = endDate;
|
|
2329
|
+
} else {
|
|
2330
|
+
const interval = luxon2.Interval.fromDateTimes(this.#startDate, this.#endDate);
|
|
2331
|
+
this.altInput.value = interval.toISO(isoOptions);
|
|
2332
|
+
}
|
|
2319
2333
|
}
|
|
2320
2334
|
} else {
|
|
2321
|
-
const startDate = typeof this.altFormat === "function" ? this.altFormat(this.#startDate) : this.
|
|
2322
|
-
(this.singleDatePicker
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
this.
|
|
2335
|
+
const startDate = typeof this.altFormat === "function" ? this.altFormat(this.#startDate) : this.toFormat(this.#startDate, this.altFormat);
|
|
2336
|
+
if (this.singleDatePicker) {
|
|
2337
|
+
this.altInput.value = startDate;
|
|
2338
|
+
} else if (this.#endDate) {
|
|
2339
|
+
const endDate = typeof this.altFormat === "function" ? this.altFormat(this.#endDate) : this.toFormat(this.#endDate, this.altFormat);
|
|
2340
|
+
if (Array.isArray(this.altInput)) {
|
|
2341
|
+
this.altInput[0].value = startDate;
|
|
2342
|
+
this.altInput[1].value = endDate;
|
|
2343
|
+
} else {
|
|
2344
|
+
const interval = luxon2.Interval.fromDateTimes(this.#startDate, this.#endDate);
|
|
2345
|
+
if (typeof this.altFormat === "function") {
|
|
2346
|
+
this.altInput.value = this.altFormat(interval);
|
|
2347
|
+
} else {
|
|
2348
|
+
this.altInput.value = this.toFormat(interval, this.altFormat, { separator: "/" });
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2326
2351
|
}
|
|
2327
2352
|
}
|
|
2328
2353
|
}
|
|
@@ -2384,6 +2409,7 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
2384
2409
|
* @param {boolean|object} [options] - Optional event options:
|
|
2385
2410
|
* - `boolean capture`: Whether to listen in the capture phase (default: `false`)
|
|
2386
2411
|
* - `object signal`: An `AbortSignal` for later removal of the listener (default: `undefined`)
|
|
2412
|
+
* @returns {DateRangePicker} - The DateRangePicker instance, usefull for chaining
|
|
2387
2413
|
*
|
|
2388
2414
|
* @example
|
|
2389
2415
|
* picker.addEventListener('hide', (e) => {
|
|
@@ -2393,6 +2419,7 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
2393
2419
|
*/
|
|
2394
2420
|
addEventListener(type, listener, options) {
|
|
2395
2421
|
this.element.addEventListener(type, listener, options);
|
|
2422
|
+
return this;
|
|
2396
2423
|
}
|
|
2397
2424
|
/**
|
|
2398
2425
|
* Counterpart to `addEventListener()`
|
|
@@ -2403,9 +2430,11 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
2403
2430
|
* @param {boolean|object} [options] - Optional event options:
|
|
2404
2431
|
* - `boolean capture`: Whether to listen in the capture phase (default: `false`)
|
|
2405
2432
|
* - `object signal`: An `AbortSignal` for later removal of the listener (default: `undefined`)
|
|
2406
|
-
|
|
2433
|
+
* @returns {DateRangePicker} - The DateRangePicker instance, usefull for chaining
|
|
2434
|
+
*/
|
|
2407
2435
|
removeEventListener(type, listener, options) {
|
|
2408
2436
|
this.element.removeEventListener(type, listener, options);
|
|
2437
|
+
return this;
|
|
2409
2438
|
}
|
|
2410
2439
|
}
|
|
2411
2440
|
function createElementFromHTML(html) {
|