@formio/js 5.1.0-dev.6094.c49181e → 5.1.0-dev.6102.8eddaab
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/dist/formio.form.js +84 -117
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.full.js +90 -123
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.js +33 -44
- package/dist/formio.min.js +1 -1
- package/dist/formio.utils.js +44 -66
- package/dist/formio.utils.min.js +1 -1
- package/lib/cjs/Element.js +13 -36
- package/lib/cjs/EventEmitter.js +2 -25
- package/lib/cjs/Form.js +2 -25
- package/lib/cjs/PDF.js +1 -1
- package/lib/cjs/PDFBuilder.js +4 -5
- package/lib/cjs/Webform.js +5 -6
- package/lib/cjs/WebformBuilder.d.ts +1 -0
- package/lib/cjs/WebformBuilder.js +22 -9
- package/lib/cjs/Wizard.js +1 -1
- package/lib/cjs/WizardBuilder.js +1 -1
- package/lib/cjs/components/_classes/component/Component.d.ts +0 -1
- package/lib/cjs/components/_classes/component/Component.js +29 -53
- package/lib/cjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
- package/lib/cjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
- package/lib/cjs/components/_classes/componentModal/ComponentModal.js +1 -1
- package/lib/cjs/components/_classes/input/Input.js +1 -1
- package/lib/cjs/components/_classes/list/ListComponent.js +1 -1
- package/lib/cjs/components/_classes/nested/NestedComponent.js +6 -6
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
- package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
- package/lib/cjs/components/address/Address.js +1 -1
- package/lib/cjs/components/alert/Alert.js +1 -1
- package/lib/cjs/components/button/Button.d.ts +1 -1
- package/lib/cjs/components/button/Button.js +4 -4
- package/lib/cjs/components/checkbox/Checkbox.js +1 -1
- package/lib/cjs/components/container/Container.js +1 -1
- package/lib/cjs/components/currency/Currency.js +1 -1
- package/lib/cjs/components/datagrid/DataGrid.js +1 -1
- package/lib/cjs/components/datamap/DataMap.d.ts +1 -1
- package/lib/cjs/components/datamap/DataMap.js +4 -4
- package/lib/cjs/components/datetime/DateTime.d.ts +1 -1
- package/lib/cjs/components/datetime/DateTime.js +13 -15
- package/lib/cjs/components/day/Day.js +1 -1
- package/lib/cjs/components/editgrid/EditGrid.js +1 -1
- package/lib/cjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
- package/lib/cjs/components/file/File.js +1 -1
- package/lib/cjs/components/form/Form.js +1 -1
- package/lib/cjs/components/number/Number.js +1 -1
- package/lib/cjs/components/panel/Panel.js +1 -1
- package/lib/cjs/components/radio/Radio.js +1 -1
- package/lib/cjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
- package/lib/cjs/components/select/Select.js +1 -1
- package/lib/cjs/components/select/editForm/Select.edit.data.js +1 -1
- package/lib/cjs/components/selectboxes/SelectBoxes.js +1 -1
- package/lib/cjs/components/signature/Signature.js +1 -1
- package/lib/cjs/components/survey/Survey.js +1 -1
- package/lib/cjs/components/tags/Tags.js +1 -1
- package/lib/cjs/components/textarea/TextArea.js +3 -3
- package/lib/cjs/components/textfield/TextField.js +7 -30
- package/lib/cjs/components/time/Time.js +1 -1
- package/lib/cjs/formio.form.js +3 -3
- package/lib/cjs/i18n.js +1 -1
- package/lib/cjs/providers/storage/uploadAdapter.js +1 -1
- package/lib/cjs/utils/Evaluator.d.ts +13 -6
- package/lib/cjs/utils/Evaluator.js +27 -15
- package/lib/cjs/utils/builder.js +5 -5
- package/lib/cjs/utils/conditionOperators/IsEqualTo.js +3 -3
- package/lib/cjs/utils/i18n.js +3 -3
- package/lib/cjs/utils/index.d.ts +160 -2
- package/lib/cjs/utils/index.js +12 -2
- package/lib/cjs/utils/utils.d.ts +28 -23
- package/lib/cjs/utils/utils.js +91 -89
- package/lib/cjs/widgets/CalendarWidget.d.ts +7 -0
- package/lib/cjs/widgets/CalendarWidget.js +37 -13
- package/lib/mjs/Element.js +6 -6
- package/lib/mjs/EventEmitter.js +2 -2
- package/lib/mjs/Form.js +1 -1
- package/lib/mjs/PDF.js +1 -1
- package/lib/mjs/PDFBuilder.js +1 -2
- package/lib/mjs/Webform.js +3 -4
- package/lib/mjs/WebformBuilder.d.ts +1 -0
- package/lib/mjs/WebformBuilder.js +14 -2
- package/lib/mjs/Wizard.js +1 -1
- package/lib/mjs/WizardBuilder.js +1 -1
- package/lib/mjs/components/_classes/component/Component.d.ts +0 -1
- package/lib/mjs/components/_classes/component/Component.js +2 -3
- package/lib/mjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
- package/lib/mjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
- package/lib/mjs/components/_classes/componentModal/ComponentModal.js +1 -1
- package/lib/mjs/components/_classes/input/Input.js +1 -1
- package/lib/mjs/components/_classes/list/ListComponent.js +1 -1
- package/lib/mjs/components/_classes/nested/NestedComponent.js +6 -6
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
- package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
- package/lib/mjs/components/address/Address.js +1 -1
- package/lib/mjs/components/alert/Alert.js +1 -1
- package/lib/mjs/components/button/Button.d.ts +1 -1
- package/lib/mjs/components/button/Button.js +1 -1
- package/lib/mjs/components/checkbox/Checkbox.js +1 -1
- package/lib/mjs/components/container/Container.js +1 -1
- package/lib/mjs/components/currency/Currency.js +1 -1
- package/lib/mjs/components/datagrid/DataGrid.js +1 -1
- package/lib/mjs/components/datamap/DataMap.d.ts +1 -1
- package/lib/mjs/components/datamap/DataMap.js +1 -1
- package/lib/mjs/components/datetime/DateTime.d.ts +1 -1
- package/lib/mjs/components/datetime/DateTime.js +13 -15
- package/lib/mjs/components/day/Day.js +1 -1
- package/lib/mjs/components/editgrid/EditGrid.js +1 -1
- package/lib/mjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
- package/lib/mjs/components/file/File.js +1 -1
- package/lib/mjs/components/form/Form.js +1 -1
- package/lib/mjs/components/number/Number.js +1 -1
- package/lib/mjs/components/panel/Panel.js +1 -1
- package/lib/mjs/components/radio/Radio.js +1 -1
- package/lib/mjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
- package/lib/mjs/components/select/Select.js +1 -1
- package/lib/mjs/components/select/editForm/Select.edit.data.js +1 -1
- package/lib/mjs/components/selectboxes/SelectBoxes.js +1 -1
- package/lib/mjs/components/signature/Signature.js +1 -1
- package/lib/mjs/components/survey/Survey.js +1 -1
- package/lib/mjs/components/tags/Tags.js +1 -1
- package/lib/mjs/components/textarea/TextArea.js +3 -3
- package/lib/mjs/components/textfield/TextField.js +1 -1
- package/lib/mjs/components/time/Time.js +1 -1
- package/lib/mjs/formio.form.js +2 -2
- package/lib/mjs/i18n.js +1 -1
- package/lib/mjs/providers/storage/uploadAdapter.js +1 -1
- package/lib/mjs/utils/Evaluator.d.ts +13 -6
- package/lib/mjs/utils/Evaluator.js +21 -13
- package/lib/mjs/utils/builder.js +1 -1
- package/lib/mjs/utils/conditionOperators/IsEqualTo.js +1 -1
- package/lib/mjs/utils/i18n.js +1 -1
- package/lib/mjs/utils/index.d.ts +160 -2
- package/lib/mjs/utils/index.js +11 -1
- package/lib/mjs/utils/utils.d.ts +28 -23
- package/lib/mjs/utils/utils.js +83 -67
- package/lib/mjs/widgets/CalendarWidget.d.ts +7 -0
- package/lib/mjs/widgets/CalendarWidget.js +37 -13
- package/package.json +2 -3
package/lib/mjs/utils/utils.js
CHANGED
@@ -1,38 +1,12 @@
|
|
1
1
|
/* global jQuery */
|
2
2
|
import _ from 'lodash';
|
3
|
-
import jsonLogic from 'json-logic-js';
|
4
3
|
import moment from 'moment-timezone/moment-timezone';
|
5
4
|
import jtz from 'jstimezonedetect';
|
6
|
-
import { lodashOperators } from './jsonlogic/operators';
|
7
5
|
import dompurify from 'dompurify';
|
8
6
|
import { getValue } from './formUtils';
|
9
7
|
import { Evaluator } from './Evaluator';
|
10
8
|
import ConditionOperators from './conditionOperators';
|
11
|
-
import { convertShowToBoolean } from '@formio/core';
|
12
|
-
import dayjs from "dayjs";
|
13
|
-
import utc from 'dayjs/plugin/utc';
|
14
|
-
import timezone from 'dayjs/plugin/timezone';
|
15
|
-
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
16
|
-
dayjs.extend(timezone);
|
17
|
-
dayjs.extend(advancedFormat);
|
18
|
-
dayjs.extend(utc);
|
19
|
-
const interpolate = Evaluator.interpolate;
|
20
|
-
export * from './formUtils';
|
21
|
-
// Configure JsonLogic
|
22
|
-
lodashOperators.forEach((name) => jsonLogic.add_operation(`_${name}`, _[name]));
|
23
|
-
// Retrieve Any Date
|
24
|
-
jsonLogic.add_operation('getDate', (date) => {
|
25
|
-
return moment(date).toISOString();
|
26
|
-
});
|
27
|
-
// Set Relative Minimum Date
|
28
|
-
jsonLogic.add_operation('relativeMinDate', (relativeMinDate) => {
|
29
|
-
return moment().subtract(relativeMinDate, 'days').toISOString();
|
30
|
-
});
|
31
|
-
// Set Relative Maximum Date
|
32
|
-
jsonLogic.add_operation('relativeMaxDate', (relativeMaxDate) => {
|
33
|
-
return moment().add(relativeMaxDate, 'days').toISOString();
|
34
|
-
});
|
35
|
-
export { jsonLogic, ConditionOperators, moment };
|
9
|
+
import { jsonLogic, convertShowToBoolean } from '@formio/core';
|
36
10
|
/**
|
37
11
|
* Evaluate a method.
|
38
12
|
* @param {Function|string|object} func - The function to evaluate.
|
@@ -512,7 +486,7 @@ export function guid() {
|
|
512
486
|
/**
|
513
487
|
* Return a translated date setting.
|
514
488
|
* @param {string|Date} date - The date to translate.
|
515
|
-
* @returns {(null|
|
489
|
+
* @returns {(null|Date)} - The translated date.
|
516
490
|
*/
|
517
491
|
export function getDateSetting(date) {
|
518
492
|
if (_.isNil(date) || _.isNaN(date) || date === '') {
|
@@ -532,13 +506,13 @@ export function getDateSetting(date) {
|
|
532
506
|
try {
|
533
507
|
const value = Evaluator.evaluator(`return ${date};`, 'moment')(moment);
|
534
508
|
if (typeof value === 'string') {
|
535
|
-
dateSetting =
|
509
|
+
dateSetting = moment(value);
|
536
510
|
}
|
537
511
|
else if (typeof value.toDate === 'function') {
|
538
|
-
dateSetting =
|
512
|
+
dateSetting = moment(value.toDate().toUTCString());
|
539
513
|
}
|
540
514
|
else if (value instanceof Date) {
|
541
|
-
dateSetting =
|
515
|
+
dateSetting = moment(value);
|
542
516
|
}
|
543
517
|
}
|
544
518
|
catch (e) {
|
@@ -566,17 +540,17 @@ export function isValidDate(date) {
|
|
566
540
|
* @returns {string} - The current timezone.
|
567
541
|
*/
|
568
542
|
export function currentTimezone() {
|
569
|
-
if (
|
570
|
-
return
|
543
|
+
if (moment.currentTimezone) {
|
544
|
+
return moment.currentTimezone;
|
571
545
|
}
|
572
|
-
|
573
|
-
return
|
546
|
+
moment.currentTimezone = jtz.determine().name();
|
547
|
+
return moment.currentTimezone;
|
574
548
|
}
|
575
549
|
/**
|
576
550
|
* Get an offset date provided a date object and timezone object.
|
577
551
|
* @param {Date} date - The date to offset.
|
578
552
|
* @param {string} timezone - The timezone to offset the date to.
|
579
|
-
* @returns {
|
553
|
+
* @returns {Date} - The offset date.
|
580
554
|
*/
|
581
555
|
export function offsetDate(date, timezone) {
|
582
556
|
if (timezone === 'UTC') {
|
@@ -585,89 +559,134 @@ export function offsetDate(date, timezone) {
|
|
585
559
|
abbr: 'UTC'
|
586
560
|
};
|
587
561
|
}
|
588
|
-
const dateMoment =
|
562
|
+
const dateMoment = moment(date).tz(timezone);
|
589
563
|
return {
|
590
564
|
date: new Date(date.getTime() + ((dateMoment.utcOffset() + date.getTimezoneOffset()) * 60000)),
|
591
565
|
abbr: dateMoment.format('z')
|
592
566
|
};
|
593
567
|
}
|
594
568
|
/**
|
595
|
-
* Returns if
|
569
|
+
* Returns if the zones are loaded.
|
570
|
+
* @returns {boolean} - TRUE if the zones are loaded; FALSE otherwise.
|
571
|
+
*/
|
572
|
+
export function zonesLoaded() {
|
573
|
+
return moment.zonesLoaded;
|
574
|
+
}
|
575
|
+
/**
|
576
|
+
* Returns if we should load the zones.
|
596
577
|
* @param {string} timezone - The timezone to check if we should load the zones.
|
597
|
-
* @returns {boolean} - TRUE if we should
|
578
|
+
* @returns {boolean} - TRUE if we should load the zones; FALSE otherwise.
|
598
579
|
*/
|
599
|
-
export function
|
600
|
-
|
580
|
+
export function shouldLoadZones(timezone) {
|
581
|
+
if (timezone === currentTimezone() || timezone === 'UTC') {
|
582
|
+
return false;
|
583
|
+
}
|
584
|
+
return true;
|
601
585
|
}
|
602
586
|
/**
|
603
|
-
*
|
604
|
-
* @param {string
|
587
|
+
* Externally load the timezone data.
|
588
|
+
* @param {string} url - The URL to load the timezone data from.
|
589
|
+
* @param {string} timezone - The timezone to load.
|
590
|
+
* @returns {Promise<any> | *} - Resolves when the zones for this timezone are loaded.
|
591
|
+
*/
|
592
|
+
export function loadZones(url, timezone) {
|
593
|
+
if (timezone && !shouldLoadZones(timezone)) {
|
594
|
+
// Return non-resolving promise.
|
595
|
+
return new Promise(_.noop);
|
596
|
+
}
|
597
|
+
if (moment.zonesPromise) {
|
598
|
+
return moment.zonesPromise;
|
599
|
+
}
|
600
|
+
return moment.zonesPromise = fetch(url)
|
601
|
+
.then(resp => resp.json().then(zones => {
|
602
|
+
moment.tz.load(zones);
|
603
|
+
moment.zonesLoaded = true;
|
604
|
+
// Trigger a global event that the timezones have finished loading.
|
605
|
+
if (document && document.createEvent && document.body && document.body.dispatchEvent) {
|
606
|
+
var event = document.createEvent('Event');
|
607
|
+
event.initEvent('zonesLoaded', true, true);
|
608
|
+
document.body.dispatchEvent(event);
|
609
|
+
}
|
610
|
+
}));
|
611
|
+
}
|
612
|
+
/**
|
613
|
+
* Get the moment date object for translating dates with timezones.
|
614
|
+
* @param {string|Date} value - The value to convert into a moment date.
|
605
615
|
* @param {string} format - The format to convert the date to.
|
606
616
|
* @param {string} timezone - The timezone to convert the date to.
|
607
617
|
* @param {object} options - The options object
|
608
|
-
* @returns {
|
618
|
+
* @returns {Date} - The moment date object.
|
609
619
|
*/
|
610
|
-
export function
|
611
|
-
const
|
620
|
+
export function momentDate(value, format, timezone, options) {
|
621
|
+
const momentDate = moment(value);
|
612
622
|
if (!timezone) {
|
613
|
-
return
|
623
|
+
return momentDate;
|
614
624
|
}
|
615
625
|
if (timezone === 'UTC') {
|
616
626
|
timezone = 'Etc/UTC';
|
617
627
|
}
|
618
|
-
if ((timezone !== currentTimezone() || (format && format.match(/\s(z$|z\s)/))) && (
|
619
|
-
return
|
628
|
+
if ((timezone !== currentTimezone() || (format && format.match(/\s(z$|z\s)/))) && (moment.zonesLoaded || options?.email)) {
|
629
|
+
return momentDate.tz(timezone);
|
620
630
|
}
|
621
|
-
return
|
631
|
+
return momentDate;
|
622
632
|
}
|
623
633
|
/**
|
624
634
|
* Format a date provided a value, format, and timezone object.
|
635
|
+
* @param {string} timezonesUrl - The URL to load the timezone data from.
|
625
636
|
* @param {string|Date} value - The value to format.
|
626
637
|
* @param {string} format - The format to format the date to.
|
627
638
|
* @param {string} timezone - The timezone to format the date to.
|
628
639
|
* @param {string} flatPickrInputFormat - The format to use for flatpickr input.
|
629
640
|
* @returns {string} - The formatted date.
|
630
641
|
*/
|
631
|
-
export function formatDate(value, format, timezone, flatPickrInputFormat) {
|
632
|
-
const
|
642
|
+
export function formatDate(timezonesUrl, value, format, timezone, flatPickrInputFormat) {
|
643
|
+
const momentDate = moment(value, flatPickrInputFormat || undefined);
|
633
644
|
if (timezone === currentTimezone()) {
|
634
645
|
// See if our format contains a "z" timezone character.
|
635
646
|
if (format.match(/\s(z$|z\s)/)) {
|
636
|
-
|
637
|
-
|
647
|
+
loadZones(timezonesUrl);
|
648
|
+
if (moment.zonesLoaded) {
|
649
|
+
return momentDate.tz(timezone).format(convertFormatToMoment(format));
|
638
650
|
}
|
639
651
|
else {
|
640
|
-
return
|
652
|
+
return momentDate.format(convertFormatToMoment(format.replace(/\s(z$|z\s)/, '')));
|
641
653
|
}
|
642
654
|
}
|
643
655
|
// Return the standard format.
|
644
|
-
return
|
656
|
+
return momentDate.format(convertFormatToMoment(format));
|
645
657
|
}
|
646
658
|
if (timezone === 'UTC') {
|
647
|
-
const offset = offsetDate(
|
648
|
-
return `${
|
659
|
+
const offset = offsetDate(momentDate.toDate(), 'UTC');
|
660
|
+
return `${moment(offset.date).format(convertFormatToMoment(format))} UTC`;
|
649
661
|
}
|
650
|
-
|
651
|
-
|
662
|
+
// Load the zones since we need timezone information.
|
663
|
+
loadZones(timezonesUrl);
|
664
|
+
if (moment.zonesLoaded && timezone) {
|
665
|
+
return momentDate.tz(timezone).format(`${convertFormatToMoment(format)} z`);
|
666
|
+
}
|
667
|
+
else {
|
668
|
+
return momentDate.format(convertFormatToMoment(format));
|
652
669
|
}
|
653
|
-
return dayjsDate.format(convertFormatToDayjs(format));
|
654
670
|
}
|
655
671
|
/**
|
656
672
|
* Pass a format function to format within a timezone.
|
673
|
+
* @param {string} timezonesUrl - The URL to load the timezone data from.
|
657
674
|
* @param {Function} formatFn - The format function to use.
|
658
675
|
* @param {Date|string} date - The date to format.
|
659
676
|
* @param {string} format - The format to format the date to.
|
660
677
|
* @param {string} timezone - The timezone to format the date to.
|
661
678
|
* @returns {string} - The formatted date.
|
662
679
|
*/
|
663
|
-
export function formatOffset(formatFn, date, format, timezone) {
|
680
|
+
export function formatOffset(timezonesUrl, formatFn, date, format, timezone) {
|
664
681
|
if (timezone === currentTimezone()) {
|
665
682
|
return formatFn(date, format);
|
666
683
|
}
|
667
684
|
if (timezone === 'UTC') {
|
668
685
|
return `${formatFn(offsetDate(date, 'UTC').date, format)} UTC`;
|
669
686
|
}
|
670
|
-
|
687
|
+
// Load the zones since we need timezone information.
|
688
|
+
loadZones(timezonesUrl);
|
689
|
+
if (moment.zonesLoaded) {
|
671
690
|
const offset = offsetDate(date, timezone);
|
672
691
|
return `${formatFn(offset.date, format)} ${offset.abbr}`;
|
673
692
|
}
|
@@ -724,7 +743,7 @@ export function convertFormatToFlatpickr(format) {
|
|
724
743
|
* @param {string} format - The format to convert.
|
725
744
|
* @returns {string} - The converted format.
|
726
745
|
*/
|
727
|
-
export function
|
746
|
+
export function convertFormatToMoment(format) {
|
728
747
|
return format
|
729
748
|
// Year conversion.
|
730
749
|
.replace(/y/g, 'Y')
|
@@ -1273,7 +1292,6 @@ export function sanitize(string, options) {
|
|
1273
1292
|
export function fastCloneDeep(obj) {
|
1274
1293
|
return obj ? JSON.parse(JSON.stringify(obj)) : obj;
|
1275
1294
|
}
|
1276
|
-
export { Evaluator, interpolate };
|
1277
1295
|
/**
|
1278
1296
|
* Returns if the component is an input component.
|
1279
1297
|
* @param {import('@formio/core').Component} componentJson - The JSON of a component.
|
@@ -1475,8 +1493,6 @@ export function getFocusableElements(element) {
|
|
1475
1493
|
textarea:not([disabled]), button:not([disabled]), [href]`;
|
1476
1494
|
return element.querySelectorAll(focusableSelector);
|
1477
1495
|
}
|
1478
|
-
// Export lodash to save space with other libraries.
|
1479
|
-
export { _ };
|
1480
1496
|
export const componentValueTypes = {
|
1481
1497
|
number: 'number',
|
1482
1498
|
string: 'string',
|
@@ -22,6 +22,13 @@ export default class CalendarWidget extends InputWidget {
|
|
22
22
|
minDate: string;
|
23
23
|
maxDate: string;
|
24
24
|
};
|
25
|
+
zoneLoading: boolean;
|
26
|
+
timezonesUrl: string;
|
27
|
+
/**
|
28
|
+
* Load the timezones.
|
29
|
+
* @returns {boolean} TRUE if the zones are loading, FALSE otherwise.
|
30
|
+
*/
|
31
|
+
loadZones(): boolean;
|
25
32
|
attach(input: any): Promise<any>;
|
26
33
|
defaultFormat: {
|
27
34
|
date: string;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Formio } from '../Formio';
|
2
2
|
import InputWidget from './InputWidget';
|
3
|
-
import { convertFormatToFlatpickr, convertFormatToMask,
|
3
|
+
import { convertFormatToFlatpickr, convertFormatToMask, convertFormatToMoment, formatDate, formatOffset, getBrowserInfo, getDateSetting, getLocaleDateFormatInfo, momentDate, zonesLoaded, shouldLoadZones, loadZones, hasEncodedTimezone, } from '../utils';
|
4
4
|
import moment from 'moment';
|
5
5
|
import _ from 'lodash';
|
6
6
|
const DEFAULT_FORMAT = 'yyyy-MM-dd hh:mm a';
|
@@ -46,6 +46,29 @@ export default class CalendarWidget extends InputWidget {
|
|
46
46
|
else if (this.settings.time_24hr) {
|
47
47
|
this.settings.format = this.settings.format.replace(/hh:mm a$/g, 'HH:mm');
|
48
48
|
}
|
49
|
+
this.zoneLoading = false;
|
50
|
+
this.timezonesUrl = `${Formio.cdn['moment-timezone']}/data/packed/latest.json`;
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* Load the timezones.
|
54
|
+
* @returns {boolean} TRUE if the zones are loading, FALSE otherwise.
|
55
|
+
*/
|
56
|
+
loadZones() {
|
57
|
+
const timezone = this.timezone;
|
58
|
+
if (this.zoneLoading) {
|
59
|
+
return true;
|
60
|
+
}
|
61
|
+
if (!zonesLoaded() && shouldLoadZones(timezone)) {
|
62
|
+
this.zoneLoading = true;
|
63
|
+
loadZones(this.timezonesUrl, timezone).then(() => {
|
64
|
+
this.zoneLoading = false;
|
65
|
+
this.emit('redraw');
|
66
|
+
});
|
67
|
+
// Return zones are loading.
|
68
|
+
return true;
|
69
|
+
}
|
70
|
+
// Zones are already loaded.
|
71
|
+
return false;
|
49
72
|
}
|
50
73
|
attach(input) {
|
51
74
|
const superAttach = super.attach(input);
|
@@ -56,7 +79,7 @@ export default class CalendarWidget extends InputWidget {
|
|
56
79
|
};
|
57
80
|
this.closedOn = 0;
|
58
81
|
this.valueFormat = (this.settings.saveAs === 'date') ? ISO_8601_FORMAT : this.settings.dateFormat || ISO_8601_FORMAT;
|
59
|
-
this.valueMomentFormat =
|
82
|
+
this.valueMomentFormat = convertFormatToMoment(this.valueFormat);
|
60
83
|
const isReadOnly = this.settings.readOnly;
|
61
84
|
this.settings.minDate = isReadOnly ? null : getDateSetting(this.settings.minDate);
|
62
85
|
this.settings.maxDate = isReadOnly ? null : getDateSetting(this.settings.maxDate);
|
@@ -218,9 +241,9 @@ export default class CalendarWidget extends InputWidget {
|
|
218
241
|
*/
|
219
242
|
getDateValue(date, format, useTimezone) {
|
220
243
|
if (useTimezone) {
|
221
|
-
return
|
244
|
+
return momentDate(date, this.valueFormat, this.timezone).format(convertFormatToMoment(format));
|
222
245
|
}
|
223
|
-
return moment(date).format(
|
246
|
+
return moment(date).format(convertFormatToMoment(format));
|
224
247
|
}
|
225
248
|
/**
|
226
249
|
* Return the value of the selected date.
|
@@ -252,7 +275,7 @@ export default class CalendarWidget extends InputWidget {
|
|
252
275
|
setValue(value) {
|
253
276
|
const saveAsText = (this.settings.saveAs === 'text');
|
254
277
|
if (!this.calendar) {
|
255
|
-
value = value ? formatDate(value,
|
278
|
+
value = value ? formatDate(this.timezonesUrl, value, convertFormatToMoment(this.settings.format), this.timezone, convertFormatToMoment(this.valueMomentFormat)) : value;
|
256
279
|
return super.setValue(value);
|
257
280
|
}
|
258
281
|
// If the component is a textfield that does not have timezone information included in the string value then skip
|
@@ -260,9 +283,10 @@ export default class CalendarWidget extends InputWidget {
|
|
260
283
|
if (this.component.type === 'textfield' && !hasEncodedTimezone(value)) {
|
261
284
|
this.settings.skipOffset = true;
|
262
285
|
}
|
286
|
+
const zonesLoading = this.loadZones();
|
263
287
|
if (value) {
|
264
|
-
if (!saveAsText && this.settings.readOnly) {
|
265
|
-
this.calendar.setDate(
|
288
|
+
if (!saveAsText && this.settings.readOnly && !zonesLoading) {
|
289
|
+
this.calendar.setDate(momentDate(value, this.valueFormat, this.timezone).format(), false);
|
266
290
|
}
|
267
291
|
else if (this.isValueISO8601(value)) {
|
268
292
|
this.calendar.setDate(value, false);
|
@@ -279,9 +303,9 @@ export default class CalendarWidget extends InputWidget {
|
|
279
303
|
const inputFormat = format || this.dateFormat;
|
280
304
|
const valueFormat = this.calendar ? this.valueFormat : this.settings.dateFormat;
|
281
305
|
if (this.settings.saveAs === 'text' && this.componentInstance.parent && !this.settings.readOnly) {
|
282
|
-
return moment(value,
|
306
|
+
return moment(value, convertFormatToMoment(valueFormat)).format(convertFormatToMoment(valueFormat));
|
283
307
|
}
|
284
|
-
return formatDate(value, inputFormat, this.timezone,
|
308
|
+
return formatDate(this.timezonesUrl, value, inputFormat, this.timezone, convertFormatToMoment(valueFormat));
|
285
309
|
}
|
286
310
|
setErrorClasses(hasErrors) {
|
287
311
|
if (!this.input) {
|
@@ -372,7 +396,7 @@ export default class CalendarWidget extends InputWidget {
|
|
372
396
|
const relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;
|
373
397
|
if (!(isIEBrowser && !relatedTarget) && !this.isCalendarElement(relatedTarget)) {
|
374
398
|
const inputValue = this.calendar.input.value;
|
375
|
-
const dateValue = inputValue ? moment(this.calendar.input.value,
|
399
|
+
const dateValue = inputValue ? moment(this.calendar.input.value, convertFormatToMoment(this.valueFormat)).toDate() : inputValue;
|
376
400
|
this.calendar.setDate(dateValue, true, this.settings.altFormat);
|
377
401
|
}
|
378
402
|
else if (!this.calendar.input.value && this.calendar.config.noCalendar) {
|
@@ -424,14 +448,14 @@ export default class CalendarWidget extends InputWidget {
|
|
424
448
|
return (date, format) => {
|
425
449
|
// Only format this if this is the altFormat and the form is readOnly.
|
426
450
|
if (this.settings.readOnly && (format === this.settings.altFormat)) {
|
427
|
-
if (!this.settings.enableTime || this.settings.skipOffset) {
|
451
|
+
if (!this.settings.enableTime || this.loadZones() || this.settings.skipOffset) {
|
428
452
|
return Flatpickr.formatDate(date, format);
|
429
453
|
}
|
430
454
|
const currentValue = new Date(this.getValue());
|
431
455
|
if (currentValue.toString() === date.toString()) {
|
432
|
-
return formatOffset(Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
|
456
|
+
return formatOffset(this.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
|
433
457
|
}
|
434
|
-
return formatOffset(Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);
|
458
|
+
return formatOffset(this.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);
|
435
459
|
}
|
436
460
|
return Flatpickr.formatDate(date, format);
|
437
461
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@formio/js",
|
3
|
-
"version": "5.1.0-dev.
|
3
|
+
"version": "5.1.0-dev.6102.8eddaab",
|
4
4
|
"description": "JavaScript powered Forms with JSON Form Builder",
|
5
5
|
"main": "lib/cjs/index.js",
|
6
6
|
"exports": {
|
@@ -81,7 +81,7 @@
|
|
81
81
|
"homepage": "https://github.com/formio/formio.js#readme",
|
82
82
|
"dependencies": {
|
83
83
|
"@formio/bootstrap": "v3.0.0-dev.121.085d187",
|
84
|
-
"@formio/core": "
|
84
|
+
"@formio/core": "2.4.0-dev.245.3d53057",
|
85
85
|
"@formio/text-mask-addons": "3.8.0-formio.4",
|
86
86
|
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
|
87
87
|
"abortcontroller-polyfill": "^1.7.5",
|
@@ -92,7 +92,6 @@
|
|
92
92
|
"choices.js": "^11.0.6",
|
93
93
|
"compare-versions": "^6.1.1",
|
94
94
|
"core-js": "^3.37.1",
|
95
|
-
"dayjs": "^1.11.13",
|
96
95
|
"dialog-polyfill": "^0.5.6",
|
97
96
|
"dom-autoscroller": "^2.3.4",
|
98
97
|
"dompurify": "^3.1.6",
|