@wernfried/daterangepicker 5.7.1 → 5.8.1
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 +80 -34
- 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 +81 -35
- 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 +80 -34
- 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;
|
|
@@ -876,24 +882,41 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
876
882
|
* @param {sting|external:DateTime|Date} month - The month to be shown, if null then current month is selected.
|
|
877
883
|
*/
|
|
878
884
|
clearDate(month) {
|
|
879
|
-
|
|
885
|
+
if (this.#startDate == null && this.#endDate == null)
|
|
886
|
+
return;
|
|
887
|
+
const monthChange = month !== void 0 && !this.parseDate(month).hasSame(this.#startDate, "month");
|
|
888
|
+
if (monthChange)
|
|
889
|
+
this.#startDate = this.parseDate(month);
|
|
890
|
+
this.updateMonthsInView();
|
|
880
891
|
this.oldStartDate = this.#startDate;
|
|
881
892
|
this.oldEndDate = this.#endDate;
|
|
882
893
|
this.#startDate = null;
|
|
883
894
|
this.#endDate = null;
|
|
895
|
+
this.updateCalendars(monthChange);
|
|
896
|
+
this.setApplyBtnState();
|
|
897
|
+
if (this.timePicker) {
|
|
898
|
+
this.triggerEvent(this.#events.onBeforeRenderTimePicker);
|
|
899
|
+
this.renderTimePicker("start");
|
|
900
|
+
this.renderTimePicker("end");
|
|
901
|
+
this.container.querySelectorAll(".calendar-time.end-time select").forEach((el) => {
|
|
902
|
+
el.disabled = !this.#endDate;
|
|
903
|
+
});
|
|
904
|
+
this.container.querySelectorAll(".calendar-time.end-time select").forEach((el) => {
|
|
905
|
+
el.classList.toggle("disabled", !this.#endDate);
|
|
906
|
+
});
|
|
907
|
+
}
|
|
884
908
|
if (this.isInputText)
|
|
885
909
|
this.element.value = "";
|
|
886
910
|
if (!this.singleDatePicker)
|
|
887
911
|
this.chosenLabel = null;
|
|
888
912
|
if (this.altInput) {
|
|
889
|
-
if (this.singleDatePicker) {
|
|
913
|
+
if (this.singleDatePicker || !Array.isArray(this.altInput)) {
|
|
890
914
|
this.altInput.value = "";
|
|
891
915
|
} else {
|
|
892
916
|
this.altInput[0].value = "";
|
|
893
917
|
this.altInput[1].value = "";
|
|
894
918
|
}
|
|
895
919
|
}
|
|
896
|
-
this.updateView(!initialMonth.hasSame(this.oldStartDate, "month"));
|
|
897
920
|
}
|
|
898
921
|
/**
|
|
899
922
|
* Parse date value
|
|
@@ -2300,7 +2323,7 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
2300
2323
|
updateAltInput() {
|
|
2301
2324
|
if (this.altInput == null)
|
|
2302
2325
|
return;
|
|
2303
|
-
if (this.altFormat == null) {
|
|
2326
|
+
if (this.altFormat == null || typeof this.altFormat === "object") {
|
|
2304
2327
|
let precision = "day";
|
|
2305
2328
|
if (this.timePicker) {
|
|
2306
2329
|
if (this.timePickerOpts.showSeconds) {
|
|
@@ -2311,18 +2334,37 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
2311
2334
|
precision = "hour";
|
|
2312
2335
|
}
|
|
2313
2336
|
}
|
|
2314
|
-
const
|
|
2315
|
-
|
|
2316
|
-
if (
|
|
2317
|
-
|
|
2318
|
-
|
|
2337
|
+
const isoOptions = this.altFormat ?? { format: "basic", precision, includeOffset: false };
|
|
2338
|
+
const startDate = this.#startDate.toISO(isoOptions);
|
|
2339
|
+
if (this.singleDatePicker) {
|
|
2340
|
+
this.altInput.value = startDate;
|
|
2341
|
+
} else if (this.#endDate) {
|
|
2342
|
+
const endDate = this.#endDate.toISO(isoOptions);
|
|
2343
|
+
if (Array.isArray(this.altInput)) {
|
|
2344
|
+
this.altInput[0].value = startDate;
|
|
2345
|
+
this.altInput[1].value = endDate;
|
|
2346
|
+
} else {
|
|
2347
|
+
const interval = luxon2.Interval.fromDateTimes(this.#startDate, this.#endDate);
|
|
2348
|
+
this.altInput.value = interval.toISO(isoOptions);
|
|
2349
|
+
}
|
|
2319
2350
|
}
|
|
2320
2351
|
} else {
|
|
2321
|
-
const startDate = typeof this.altFormat === "function" ? this.altFormat(this.#startDate) : this.
|
|
2322
|
-
(this.singleDatePicker
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
this.
|
|
2352
|
+
const startDate = typeof this.altFormat === "function" ? this.altFormat(this.#startDate) : this.toFormat(this.#startDate, this.altFormat);
|
|
2353
|
+
if (this.singleDatePicker) {
|
|
2354
|
+
this.altInput.value = startDate;
|
|
2355
|
+
} else if (this.#endDate) {
|
|
2356
|
+
const endDate = typeof this.altFormat === "function" ? this.altFormat(this.#endDate) : this.toFormat(this.#endDate, this.altFormat);
|
|
2357
|
+
if (Array.isArray(this.altInput)) {
|
|
2358
|
+
this.altInput[0].value = startDate;
|
|
2359
|
+
this.altInput[1].value = endDate;
|
|
2360
|
+
} else {
|
|
2361
|
+
const interval = luxon2.Interval.fromDateTimes(this.#startDate, this.#endDate);
|
|
2362
|
+
if (typeof this.altFormat === "function") {
|
|
2363
|
+
this.altInput.value = this.altFormat(interval);
|
|
2364
|
+
} else {
|
|
2365
|
+
this.altInput.value = this.toFormat(interval, this.altFormat, { separator: "/" });
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2326
2368
|
}
|
|
2327
2369
|
}
|
|
2328
2370
|
}
|
|
@@ -2384,6 +2426,7 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
2384
2426
|
* @param {boolean|object} [options] - Optional event options:
|
|
2385
2427
|
* - `boolean capture`: Whether to listen in the capture phase (default: `false`)
|
|
2386
2428
|
* - `object signal`: An `AbortSignal` for later removal of the listener (default: `undefined`)
|
|
2429
|
+
* @returns {DateRangePicker} - The DateRangePicker instance, usefull for chaining
|
|
2387
2430
|
*
|
|
2388
2431
|
* @example
|
|
2389
2432
|
* picker.addEventListener('hide', (e) => {
|
|
@@ -2393,6 +2436,7 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
2393
2436
|
*/
|
|
2394
2437
|
addEventListener(type, listener, options) {
|
|
2395
2438
|
this.element.addEventListener(type, listener, options);
|
|
2439
|
+
return this;
|
|
2396
2440
|
}
|
|
2397
2441
|
/**
|
|
2398
2442
|
* Counterpart to `addEventListener()`
|
|
@@ -2403,9 +2447,11 @@ var DateRangePicker = (function(exports, luxon2) {
|
|
|
2403
2447
|
* @param {boolean|object} [options] - Optional event options:
|
|
2404
2448
|
* - `boolean capture`: Whether to listen in the capture phase (default: `false`)
|
|
2405
2449
|
* - `object signal`: An `AbortSignal` for later removal of the listener (default: `undefined`)
|
|
2406
|
-
|
|
2450
|
+
* @returns {DateRangePicker} - The DateRangePicker instance, usefull for chaining
|
|
2451
|
+
*/
|
|
2407
2452
|
removeEventListener(type, listener, options) {
|
|
2408
2453
|
this.element.removeEventListener(type, listener, options);
|
|
2454
|
+
return this;
|
|
2409
2455
|
}
|
|
2410
2456
|
}
|
|
2411
2457
|
function createElementFromHTML(html) {
|