@formio/js 5.1.0-dev.5913.5ccc183 → 5.1.0-dev.5936.81a1533
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/README.md +2 -0
- package/dist/formio.form.js +112 -123
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.full.js +119 -130
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.js +62 -51
- package/dist/formio.min.js +1 -1
- package/dist/formio.utils.js +73 -73
- 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.js +20 -15
- 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 +36 -57
- 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.js +1 -1
- 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/datetime/DateTime.d.ts +1 -1
- package/lib/cjs/components/datetime/DateTime.js +15 -13
- package/lib/cjs/components/day/Day.js +2 -2
- 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 +14 -2
- package/lib/cjs/components/form/editForm/Form.edit.form.js +4 -3
- package/lib/cjs/components/number/Number.js +1 -1
- package/lib/cjs/components/panel/Panel.js +1 -1
- package/lib/cjs/components/radio/Radio.d.ts +4 -0
- package/lib/cjs/components/radio/Radio.js +69 -23
- 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 +20 -6
- package/lib/cjs/utils/Evaluator.js +38 -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 +169 -2
- package/lib/cjs/utils/index.js +22 -2
- package/lib/cjs/utils/utils.d.ts +22 -37
- package/lib/cjs/utils/utils.js +54 -132
- package/lib/cjs/widgets/CalendarWidget.d.ts +1 -8
- package/lib/cjs/widgets/CalendarWidget.js +17 -43
- 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.js +12 -7
- 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 +9 -7
- 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.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/datetime/DateTime.d.ts +1 -1
- package/lib/mjs/components/datetime/DateTime.js +15 -13
- package/lib/mjs/components/day/Day.js +2 -2
- 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 +13 -2
- package/lib/mjs/components/form/editForm/Form.edit.form.js +3 -2
- package/lib/mjs/components/number/Number.js +1 -1
- package/lib/mjs/components/panel/Panel.js +1 -1
- package/lib/mjs/components/radio/Radio.d.ts +4 -0
- package/lib/mjs/components/radio/Radio.js +68 -23
- 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 +20 -6
- package/lib/mjs/utils/Evaluator.js +31 -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 +169 -2
- package/lib/mjs/utils/index.js +18 -1
- package/lib/mjs/utils/utils.d.ts +22 -37
- package/lib/mjs/utils/utils.js +47 -107
- package/lib/mjs/widgets/CalendarWidget.d.ts +1 -8
- package/lib/mjs/widgets/CalendarWidget.js +17 -43
- package/package.json +5 -3
package/lib/mjs/utils/utils.d.ts
CHANGED
@@ -164,9 +164,9 @@ export function guid(): string;
|
|
164
164
|
/**
|
165
165
|
* Return a translated date setting.
|
166
166
|
* @param {string|Date} date - The date to translate.
|
167
|
-
* @returns {(null|
|
167
|
+
* @returns {(null|dayjs.Dayjs)} - The translated date.
|
168
168
|
*/
|
169
|
-
export function getDateSetting(date: string | Date): (null |
|
169
|
+
export function getDateSetting(date: string | Date): (null | dayjs.Dayjs);
|
170
170
|
/**
|
171
171
|
* Returns true if the date is a valid date. False otherwise.
|
172
172
|
* @param {Date|string} date - The date to check for validity.
|
@@ -182,56 +182,45 @@ export function currentTimezone(): string;
|
|
182
182
|
* Get an offset date provided a date object and timezone object.
|
183
183
|
* @param {Date} date - The date to offset.
|
184
184
|
* @param {string} timezone - The timezone to offset the date to.
|
185
|
-
* @returns {Date} - The offset date.
|
185
|
+
* @returns {{date: Date, abbr: string}} - The offset date.
|
186
186
|
*/
|
187
|
-
export function offsetDate(date: Date, timezone: string):
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
*/
|
192
|
-
export function zonesLoaded(): boolean;
|
187
|
+
export function offsetDate(date: Date, timezone: string): {
|
188
|
+
date: Date;
|
189
|
+
abbr: string;
|
190
|
+
};
|
193
191
|
/**
|
194
|
-
* Returns if we should
|
192
|
+
* Returns if we should handle a timezone difference.
|
195
193
|
* @param {string} timezone - The timezone to check if we should load the zones.
|
196
|
-
* @returns {boolean} - TRUE if we should
|
197
|
-
*/
|
198
|
-
export function shouldLoadZones(timezone: string): boolean;
|
199
|
-
/**
|
200
|
-
* Externally load the timezone data.
|
201
|
-
* @param {string} url - The URL to load the timezone data from.
|
202
|
-
* @param {string} timezone - The timezone to load.
|
203
|
-
* @returns {Promise<any> | *} - Resolves when the zones for this timezone are loaded.
|
194
|
+
* @returns {boolean} - TRUE if we should handle timezones; FALSE otherwise.
|
204
195
|
*/
|
205
|
-
export function
|
196
|
+
export function shouldHandleTimezone(timezone: string): boolean;
|
206
197
|
/**
|
207
|
-
* Get the
|
208
|
-
* @param {string|Date} value - The value to convert into a
|
198
|
+
* Get the Dayjs date object for translating dates with timezones.
|
199
|
+
* @param {string|Date} value - The value to convert into a dayjs date.
|
209
200
|
* @param {string} format - The format to convert the date to.
|
210
201
|
* @param {string} timezone - The timezone to convert the date to.
|
211
202
|
* @param {object} options - The options object
|
212
|
-
* @returns {
|
203
|
+
* @returns {dayjs.Dayjs} - The dayjs date object.
|
213
204
|
*/
|
214
|
-
export function
|
205
|
+
export function dayjsDate(value: string | Date, format: string, timezone: string, options: object): dayjs.Dayjs;
|
215
206
|
/**
|
216
207
|
* Format a date provided a value, format, and timezone object.
|
217
|
-
* @param {string} timezonesUrl - The URL to load the timezone data from.
|
218
208
|
* @param {string|Date} value - The value to format.
|
219
209
|
* @param {string} format - The format to format the date to.
|
220
210
|
* @param {string} timezone - The timezone to format the date to.
|
221
211
|
* @param {string} flatPickrInputFormat - The format to use for flatpickr input.
|
222
212
|
* @returns {string} - The formatted date.
|
223
213
|
*/
|
224
|
-
export function formatDate(
|
214
|
+
export function formatDate(value: string | Date, format: string, timezone: string, flatPickrInputFormat: string): string;
|
225
215
|
/**
|
226
216
|
* Pass a format function to format within a timezone.
|
227
|
-
* @param {string} timezonesUrl - The URL to load the timezone data from.
|
228
217
|
* @param {Function} formatFn - The format function to use.
|
229
218
|
* @param {Date|string} date - The date to format.
|
230
219
|
* @param {string} format - The format to format the date to.
|
231
220
|
* @param {string} timezone - The timezone to format the date to.
|
232
221
|
* @returns {string} - The formatted date.
|
233
222
|
*/
|
234
|
-
export function formatOffset(
|
223
|
+
export function formatOffset(formatFn: Function, date: Date | string, format: string, timezone: string): string;
|
235
224
|
/**
|
236
225
|
* Returns the local date format information.
|
237
226
|
* @param {Intl.LocalesArgument} locale - The locale to get the date format for.
|
@@ -249,7 +238,7 @@ export function convertFormatToFlatpickr(format: string): string;
|
|
249
238
|
* @param {string} format - The format to convert.
|
250
239
|
* @returns {string} - The converted format.
|
251
240
|
*/
|
252
|
-
export function
|
241
|
+
export function convertFormatToDayjs(format: string): string;
|
253
242
|
/**
|
254
243
|
* Convert the format from the angular-datepicker module to mask format.
|
255
244
|
* @param {string} format - The format to convert.
|
@@ -414,15 +403,15 @@ export function fastCloneDeep(obj: any): any;
|
|
414
403
|
/**
|
415
404
|
* Returns if the component is an input component.
|
416
405
|
* @param {import('@formio/core').Component} componentJson - The JSON of a component.
|
417
|
-
* @returns {
|
406
|
+
* @returns {boolean} - TRUE if the component is an input component; FALSE otherwise.
|
418
407
|
*/
|
419
|
-
export function isInputComponent(componentJson: import('@formio/core').Component):
|
408
|
+
export function isInputComponent(componentJson: import('@formio/core').Component): boolean;
|
420
409
|
/**
|
421
410
|
* Takes a component path, and returns a component path array.
|
422
411
|
* @param {string} pathStr - The path string to convert to an array.
|
423
|
-
* @returns {
|
412
|
+
* @returns {Array<string>} - The array of paths.
|
424
413
|
*/
|
425
|
-
export function getArrayFromComponentPath(pathStr: string):
|
414
|
+
export function getArrayFromComponentPath(pathStr: string): Array<string>;
|
426
415
|
/**
|
427
416
|
* Returns true if the component is a child of the parent.
|
428
417
|
* @param {any} child - The child component to check.
|
@@ -499,7 +488,6 @@ export function getComponentSavedTypes(fullSchema: import('@formio/core').Compon
|
|
499
488
|
* @returns {boolean} if value has encoded timezone
|
500
489
|
*/
|
501
490
|
export function hasEncodedTimezone(value: string): boolean;
|
502
|
-
export * from "./formUtils";
|
503
491
|
/**
|
504
492
|
* Map values through unfold and return first non-nil value.
|
505
493
|
* @param {Array<T>} collection - The collection to map through unfold.;
|
@@ -516,7 +504,4 @@ export namespace componentValueTypes {
|
|
516
504
|
let any: string;
|
517
505
|
}
|
518
506
|
export function interpolateErrors(component: Component, errors: FieldError[], interpolateFn: Function): [];
|
519
|
-
import
|
520
|
-
import { Evaluator } from './Evaluator';
|
521
|
-
export const interpolate: typeof Evaluator.interpolate;
|
522
|
-
export { jsonLogic, ConditionOperators, moment, Evaluator, _ };
|
507
|
+
import dayjs from "dayjs";
|
package/lib/mjs/utils/utils.js
CHANGED
@@ -1,31 +1,19 @@
|
|
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';
|
6
|
+
import dayjs from "dayjs";
|
7
|
+
import utc from 'dayjs/plugin/utc';
|
8
|
+
import timezone from 'dayjs/plugin/timezone';
|
9
|
+
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
10
|
+
import { jsonLogic, convertShowToBoolean } from '@formio/core';
|
8
11
|
import { getValue } from './formUtils';
|
9
12
|
import { Evaluator } from './Evaluator';
|
10
13
|
import ConditionOperators from './conditionOperators';
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
// Configure JsonLogic
|
15
|
-
lodashOperators.forEach((name) => jsonLogic.add_operation(`_${name}`, _[name]));
|
16
|
-
// Retrieve Any Date
|
17
|
-
jsonLogic.add_operation('getDate', (date) => {
|
18
|
-
return moment(date).toISOString();
|
19
|
-
});
|
20
|
-
// Set Relative Minimum Date
|
21
|
-
jsonLogic.add_operation('relativeMinDate', (relativeMinDate) => {
|
22
|
-
return moment().subtract(relativeMinDate, 'days').toISOString();
|
23
|
-
});
|
24
|
-
// Set Relative Maximum Date
|
25
|
-
jsonLogic.add_operation('relativeMaxDate', (relativeMaxDate) => {
|
26
|
-
return moment().add(relativeMaxDate, 'days').toISOString();
|
27
|
-
});
|
28
|
-
export { jsonLogic, ConditionOperators, moment };
|
14
|
+
dayjs.extend(timezone);
|
15
|
+
dayjs.extend(advancedFormat);
|
16
|
+
dayjs.extend(utc);
|
29
17
|
/**
|
30
18
|
* Evaluate a method.
|
31
19
|
* @param {Function|string|object} func - The function to evaluate.
|
@@ -505,7 +493,7 @@ export function guid() {
|
|
505
493
|
/**
|
506
494
|
* Return a translated date setting.
|
507
495
|
* @param {string|Date} date - The date to translate.
|
508
|
-
* @returns {(null|
|
496
|
+
* @returns {(null|dayjs.Dayjs)} - The translated date.
|
509
497
|
*/
|
510
498
|
export function getDateSetting(date) {
|
511
499
|
if (_.isNil(date) || _.isNaN(date) || date === '') {
|
@@ -525,13 +513,13 @@ export function getDateSetting(date) {
|
|
525
513
|
try {
|
526
514
|
const value = Evaluator.evaluator(`return ${date};`, 'moment')(moment);
|
527
515
|
if (typeof value === 'string') {
|
528
|
-
dateSetting =
|
516
|
+
dateSetting = dayjs(value);
|
529
517
|
}
|
530
518
|
else if (typeof value.toDate === 'function') {
|
531
|
-
dateSetting =
|
519
|
+
dateSetting = dayjs(value.toDate().toUTCString());
|
532
520
|
}
|
533
521
|
else if (value instanceof Date) {
|
534
|
-
dateSetting =
|
522
|
+
dateSetting = dayjs(value);
|
535
523
|
}
|
536
524
|
}
|
537
525
|
catch (e) {
|
@@ -559,17 +547,17 @@ export function isValidDate(date) {
|
|
559
547
|
* @returns {string} - The current timezone.
|
560
548
|
*/
|
561
549
|
export function currentTimezone() {
|
562
|
-
if (
|
563
|
-
return
|
550
|
+
if (dayjs.currentTimezone) {
|
551
|
+
return dayjs.currentTimezone;
|
564
552
|
}
|
565
|
-
|
566
|
-
return
|
553
|
+
dayjs.currentTimezone = jtz.determine().name();
|
554
|
+
return dayjs.currentTimezone;
|
567
555
|
}
|
568
556
|
/**
|
569
557
|
* Get an offset date provided a date object and timezone object.
|
570
558
|
* @param {Date} date - The date to offset.
|
571
559
|
* @param {string} timezone - The timezone to offset the date to.
|
572
|
-
* @returns {Date} - The offset date.
|
560
|
+
* @returns {{date: Date, abbr: string}} - The offset date.
|
573
561
|
*/
|
574
562
|
export function offsetDate(date, timezone) {
|
575
563
|
if (timezone === 'UTC') {
|
@@ -578,134 +566,89 @@ export function offsetDate(date, timezone) {
|
|
578
566
|
abbr: 'UTC'
|
579
567
|
};
|
580
568
|
}
|
581
|
-
const dateMoment =
|
569
|
+
const dateMoment = dayjs(date).tz(timezone);
|
582
570
|
return {
|
583
571
|
date: new Date(date.getTime() + ((dateMoment.utcOffset() + date.getTimezoneOffset()) * 60000)),
|
584
572
|
abbr: dateMoment.format('z')
|
585
573
|
};
|
586
574
|
}
|
587
575
|
/**
|
588
|
-
* Returns if
|
589
|
-
* @returns {boolean} - TRUE if the zones are loaded; FALSE otherwise.
|
590
|
-
*/
|
591
|
-
export function zonesLoaded() {
|
592
|
-
return moment.zonesLoaded;
|
593
|
-
}
|
594
|
-
/**
|
595
|
-
* Returns if we should load the zones.
|
576
|
+
* Returns if we should handle a timezone difference.
|
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 handle timezones; FALSE otherwise.
|
598
579
|
*/
|
599
|
-
export function
|
600
|
-
|
601
|
-
return false;
|
602
|
-
}
|
603
|
-
return true;
|
580
|
+
export function shouldHandleTimezone(timezone) {
|
581
|
+
return !(timezone === currentTimezone() || timezone === 'UTC');
|
604
582
|
}
|
605
583
|
/**
|
606
|
-
*
|
607
|
-
* @param {string}
|
608
|
-
* @param {string} timezone - The timezone to load.
|
609
|
-
* @returns {Promise<any> | *} - Resolves when the zones for this timezone are loaded.
|
610
|
-
*/
|
611
|
-
export function loadZones(url, timezone) {
|
612
|
-
if (timezone && !shouldLoadZones(timezone)) {
|
613
|
-
// Return non-resolving promise.
|
614
|
-
return new Promise(_.noop);
|
615
|
-
}
|
616
|
-
if (moment.zonesPromise) {
|
617
|
-
return moment.zonesPromise;
|
618
|
-
}
|
619
|
-
return moment.zonesPromise = fetch(url)
|
620
|
-
.then(resp => resp.json().then(zones => {
|
621
|
-
moment.tz.load(zones);
|
622
|
-
moment.zonesLoaded = true;
|
623
|
-
// Trigger a global event that the timezones have finished loading.
|
624
|
-
if (document && document.createEvent && document.body && document.body.dispatchEvent) {
|
625
|
-
var event = document.createEvent('Event');
|
626
|
-
event.initEvent('zonesLoaded', true, true);
|
627
|
-
document.body.dispatchEvent(event);
|
628
|
-
}
|
629
|
-
}));
|
630
|
-
}
|
631
|
-
/**
|
632
|
-
* Get the moment date object for translating dates with timezones.
|
633
|
-
* @param {string|Date} value - The value to convert into a moment date.
|
584
|
+
* Get the Dayjs date object for translating dates with timezones.
|
585
|
+
* @param {string|Date} value - The value to convert into a dayjs date.
|
634
586
|
* @param {string} format - The format to convert the date to.
|
635
587
|
* @param {string} timezone - The timezone to convert the date to.
|
636
588
|
* @param {object} options - The options object
|
637
|
-
* @returns {
|
589
|
+
* @returns {dayjs.Dayjs} - The dayjs date object.
|
638
590
|
*/
|
639
|
-
export function
|
640
|
-
const
|
591
|
+
export function dayjsDate(value, format, timezone, options) {
|
592
|
+
const dayjsDate = dayjs(value);
|
641
593
|
if (!timezone) {
|
642
|
-
return
|
594
|
+
return dayjsDate;
|
643
595
|
}
|
644
596
|
if (timezone === 'UTC') {
|
645
597
|
timezone = 'Etc/UTC';
|
646
598
|
}
|
647
|
-
if ((timezone !== currentTimezone() || (format && format.match(/\s(z$|z\s)/))) && (
|
648
|
-
return
|
599
|
+
if ((timezone !== currentTimezone() || (format && format.match(/\s(z$|z\s)/))) && (shouldHandleTimezone(timezone) || options?.email)) {
|
600
|
+
return dayjsDate.tz(timezone);
|
649
601
|
}
|
650
|
-
return
|
602
|
+
return dayjsDate;
|
651
603
|
}
|
652
604
|
/**
|
653
605
|
* Format a date provided a value, format, and timezone object.
|
654
|
-
* @param {string} timezonesUrl - The URL to load the timezone data from.
|
655
606
|
* @param {string|Date} value - The value to format.
|
656
607
|
* @param {string} format - The format to format the date to.
|
657
608
|
* @param {string} timezone - The timezone to format the date to.
|
658
609
|
* @param {string} flatPickrInputFormat - The format to use for flatpickr input.
|
659
610
|
* @returns {string} - The formatted date.
|
660
611
|
*/
|
661
|
-
export function formatDate(
|
662
|
-
const
|
612
|
+
export function formatDate(value, format, timezone, flatPickrInputFormat) {
|
613
|
+
const dayjsDate = dayjs(value, flatPickrInputFormat || undefined);
|
663
614
|
if (timezone === currentTimezone()) {
|
664
615
|
// See if our format contains a "z" timezone character.
|
665
616
|
if (format.match(/\s(z$|z\s)/)) {
|
666
|
-
|
667
|
-
|
668
|
-
return momentDate.tz(timezone).format(convertFormatToMoment(format));
|
617
|
+
if (shouldHandleTimezone(timezone)) {
|
618
|
+
return dayjsDate.tz(timezone).format(convertFormatToDayjs(format));
|
669
619
|
}
|
670
620
|
else {
|
671
|
-
return
|
621
|
+
return dayjsDate.format(convertFormatToDayjs(format.replace(/\s(z$|z\s)/, '')));
|
672
622
|
}
|
673
623
|
}
|
674
624
|
// Return the standard format.
|
675
|
-
return
|
625
|
+
return dayjsDate.format(convertFormatToDayjs(format));
|
676
626
|
}
|
677
627
|
if (timezone === 'UTC') {
|
678
|
-
const offset = offsetDate(
|
679
|
-
return `${
|
628
|
+
const offset = offsetDate(dayjsDate.toDate(), 'UTC');
|
629
|
+
return `${dayjs(offset.date).format(convertFormatToDayjs(format))} UTC`;
|
680
630
|
}
|
681
|
-
|
682
|
-
|
683
|
-
if (moment.zonesLoaded && timezone) {
|
684
|
-
return momentDate.tz(timezone).format(`${convertFormatToMoment(format)} z`);
|
685
|
-
}
|
686
|
-
else {
|
687
|
-
return momentDate.format(convertFormatToMoment(format));
|
631
|
+
if (shouldHandleTimezone(timezone)) {
|
632
|
+
return dayjsDate.tz(timezone).format(`${convertFormatToDayjs(format)} z`);
|
688
633
|
}
|
634
|
+
return dayjsDate.format(convertFormatToDayjs(format));
|
689
635
|
}
|
690
636
|
/**
|
691
637
|
* Pass a format function to format within a timezone.
|
692
|
-
* @param {string} timezonesUrl - The URL to load the timezone data from.
|
693
638
|
* @param {Function} formatFn - The format function to use.
|
694
639
|
* @param {Date|string} date - The date to format.
|
695
640
|
* @param {string} format - The format to format the date to.
|
696
641
|
* @param {string} timezone - The timezone to format the date to.
|
697
642
|
* @returns {string} - The formatted date.
|
698
643
|
*/
|
699
|
-
export function formatOffset(
|
644
|
+
export function formatOffset(formatFn, date, format, timezone) {
|
700
645
|
if (timezone === currentTimezone()) {
|
701
646
|
return formatFn(date, format);
|
702
647
|
}
|
703
648
|
if (timezone === 'UTC') {
|
704
649
|
return `${formatFn(offsetDate(date, 'UTC').date, format)} UTC`;
|
705
650
|
}
|
706
|
-
|
707
|
-
loadZones(timezonesUrl);
|
708
|
-
if (moment.zonesLoaded) {
|
651
|
+
if (shouldHandleTimezone(timezone)) {
|
709
652
|
const offset = offsetDate(date, timezone);
|
710
653
|
return `${formatFn(offset.date, format)} ${offset.abbr}`;
|
711
654
|
}
|
@@ -762,7 +705,7 @@ export function convertFormatToFlatpickr(format) {
|
|
762
705
|
* @param {string} format - The format to convert.
|
763
706
|
* @returns {string} - The converted format.
|
764
707
|
*/
|
765
|
-
export function
|
708
|
+
export function convertFormatToDayjs(format) {
|
766
709
|
return format
|
767
710
|
// Year conversion.
|
768
711
|
.replace(/y/g, 'Y')
|
@@ -1311,11 +1254,10 @@ export function sanitize(string, options) {
|
|
1311
1254
|
export function fastCloneDeep(obj) {
|
1312
1255
|
return obj ? JSON.parse(JSON.stringify(obj)) : obj;
|
1313
1256
|
}
|
1314
|
-
export { Evaluator, interpolate };
|
1315
1257
|
/**
|
1316
1258
|
* Returns if the component is an input component.
|
1317
1259
|
* @param {import('@formio/core').Component} componentJson - The JSON of a component.
|
1318
|
-
* @returns {
|
1260
|
+
* @returns {boolean} - TRUE if the component is an input component; FALSE otherwise.
|
1319
1261
|
*/
|
1320
1262
|
export function isInputComponent(componentJson) {
|
1321
1263
|
if (componentJson.input === false || componentJson.input === true) {
|
@@ -1339,7 +1281,7 @@ export function isInputComponent(componentJson) {
|
|
1339
1281
|
/**
|
1340
1282
|
* Takes a component path, and returns a component path array.
|
1341
1283
|
* @param {string} pathStr - The path string to convert to an array.
|
1342
|
-
* @returns {
|
1284
|
+
* @returns {Array<string>} - The array of paths.
|
1343
1285
|
*/
|
1344
1286
|
export function getArrayFromComponentPath(pathStr) {
|
1345
1287
|
if (!pathStr || !_.isString(pathStr)) {
|
@@ -1513,8 +1455,6 @@ export function getFocusableElements(element) {
|
|
1513
1455
|
textarea:not([disabled]), button:not([disabled]), [href]`;
|
1514
1456
|
return element.querySelectorAll(focusableSelector);
|
1515
1457
|
}
|
1516
|
-
// Export lodash to save space with other libraries.
|
1517
|
-
export { _ };
|
1518
1458
|
export const componentValueTypes = {
|
1519
1459
|
number: 'number',
|
1520
1460
|
string: 'string',
|
@@ -22,13 +22,6 @@ 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;
|
32
25
|
attach(input: any): Promise<any>;
|
33
26
|
defaultFormat: {
|
34
27
|
date: string;
|
@@ -84,7 +77,7 @@ export default class CalendarWidget extends InputWidget {
|
|
84
77
|
* @returns {void}
|
85
78
|
*/
|
86
79
|
setValue(value: any): void;
|
87
|
-
getValueAsString(value: any, format
|
80
|
+
getValueAsString(value: any, format?: string): string;
|
88
81
|
setErrorClasses(hasErrors: any): void;
|
89
82
|
isCalendarElement(element: any): any;
|
90
83
|
initFlatpickr(Flatpickr: any): void;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { Formio } from '../Formio';
|
2
|
-
import InputWidget from './InputWidget';
|
3
|
-
import { convertFormatToFlatpickr, convertFormatToMask, convertFormatToMoment, formatDate, formatOffset, getBrowserInfo, getDateSetting, getLocaleDateFormatInfo, momentDate, zonesLoaded, shouldLoadZones, loadZones, hasEncodedTimezone, } from '../utils/utils';
|
4
1
|
import moment from 'moment';
|
5
2
|
import _ from 'lodash';
|
3
|
+
import { Formio } from '../Formio';
|
4
|
+
import InputWidget from './InputWidget';
|
5
|
+
import { convertFormatToFlatpickr, convertFormatToMask, convertFormatToDayjs, formatDate, formatOffset, getBrowserInfo, getDateSetting, getLocaleDateFormatInfo, hasEncodedTimezone, dayjsDate } from '../utils';
|
6
6
|
const DEFAULT_FORMAT = 'yyyy-MM-dd hh:mm a';
|
7
7
|
const ISO_8601_FORMAT = 'yyyy-MM-ddTHH:mm:ssZ';
|
8
8
|
const isIEBrowser = getBrowserInfo().ie;
|
@@ -46,29 +46,6 @@ 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;
|
72
49
|
}
|
73
50
|
attach(input) {
|
74
51
|
const superAttach = super.attach(input);
|
@@ -79,7 +56,7 @@ export default class CalendarWidget extends InputWidget {
|
|
79
56
|
};
|
80
57
|
this.closedOn = 0;
|
81
58
|
this.valueFormat = (this.settings.saveAs === 'date') ? ISO_8601_FORMAT : this.settings.dateFormat || ISO_8601_FORMAT;
|
82
|
-
this.valueMomentFormat =
|
59
|
+
this.valueMomentFormat = convertFormatToDayjs(this.valueFormat);
|
83
60
|
const isReadOnly = this.settings.readOnly;
|
84
61
|
this.settings.minDate = isReadOnly ? null : getDateSetting(this.settings.minDate);
|
85
62
|
this.settings.maxDate = isReadOnly ? null : getDateSetting(this.settings.maxDate);
|
@@ -241,9 +218,9 @@ export default class CalendarWidget extends InputWidget {
|
|
241
218
|
*/
|
242
219
|
getDateValue(date, format, useTimezone) {
|
243
220
|
if (useTimezone) {
|
244
|
-
return
|
221
|
+
return dayjsDate(date, this.valueFormat, this.timezone).format(convertFormatToDayjs(format));
|
245
222
|
}
|
246
|
-
return moment(date).format(
|
223
|
+
return moment(date).format(convertFormatToDayjs(format));
|
247
224
|
}
|
248
225
|
/**
|
249
226
|
* Return the value of the selected date.
|
@@ -275,18 +252,15 @@ export default class CalendarWidget extends InputWidget {
|
|
275
252
|
setValue(value) {
|
276
253
|
const saveAsText = (this.settings.saveAs === 'text');
|
277
254
|
if (!this.calendar) {
|
278
|
-
value = value ? formatDate(
|
255
|
+
value = value ? formatDate(value, convertFormatToDayjs(this.settings.format), this.timezone, convertFormatToDayjs(this.valueMomentFormat)) : value;
|
279
256
|
return super.setValue(value);
|
280
257
|
}
|
281
258
|
// If the component is a textfield that does not have timezone information included in the string value then skip
|
282
259
|
// the timezone offset
|
283
|
-
|
284
|
-
this.settings.skipOffset = true;
|
285
|
-
}
|
286
|
-
const zonesLoading = this.loadZones();
|
260
|
+
this.settings.skipOffset = this.component.type === 'textfield' && !hasEncodedTimezone(value);
|
287
261
|
if (value) {
|
288
|
-
if (!saveAsText && this.settings.readOnly
|
289
|
-
this.calendar.setDate(
|
262
|
+
if (!saveAsText && this.settings.readOnly) {
|
263
|
+
this.calendar.setDate(dayjsDate(value, this.valueFormat, this.timezone).format(), false);
|
290
264
|
}
|
291
265
|
else if (this.isValueISO8601(value)) {
|
292
266
|
this.calendar.setDate(value, false);
|
@@ -299,13 +273,13 @@ export default class CalendarWidget extends InputWidget {
|
|
299
273
|
this.calendar.clear(false);
|
300
274
|
}
|
301
275
|
}
|
302
|
-
getValueAsString(value, format) {
|
276
|
+
getValueAsString(value, format = '') {
|
303
277
|
const inputFormat = format || this.dateFormat;
|
304
278
|
const valueFormat = this.calendar ? this.valueFormat : this.settings.dateFormat;
|
305
279
|
if (this.settings.saveAs === 'text' && this.componentInstance.parent && !this.settings.readOnly) {
|
306
|
-
return moment(value,
|
280
|
+
return moment(value, convertFormatToDayjs(valueFormat)).format(convertFormatToDayjs(valueFormat));
|
307
281
|
}
|
308
|
-
return formatDate(
|
282
|
+
return formatDate(value, inputFormat, this.timezone, convertFormatToDayjs(valueFormat));
|
309
283
|
}
|
310
284
|
setErrorClasses(hasErrors) {
|
311
285
|
if (!this.input) {
|
@@ -396,7 +370,7 @@ export default class CalendarWidget extends InputWidget {
|
|
396
370
|
const relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;
|
397
371
|
if (!(isIEBrowser && !relatedTarget) && !this.isCalendarElement(relatedTarget)) {
|
398
372
|
const inputValue = this.calendar.input.value;
|
399
|
-
const dateValue = inputValue ? moment(this.calendar.input.value,
|
373
|
+
const dateValue = inputValue ? moment(this.calendar.input.value, convertFormatToDayjs(this.valueFormat)).toDate() : inputValue;
|
400
374
|
this.calendar.setDate(dateValue, true, this.settings.altFormat);
|
401
375
|
}
|
402
376
|
else if (!this.calendar.input.value && this.calendar.config.noCalendar) {
|
@@ -448,14 +422,14 @@ export default class CalendarWidget extends InputWidget {
|
|
448
422
|
return (date, format) => {
|
449
423
|
// Only format this if this is the altFormat and the form is readOnly.
|
450
424
|
if (this.settings.readOnly && (format === this.settings.altFormat)) {
|
451
|
-
if (!this.settings.enableTime || this.
|
425
|
+
if (!this.settings.enableTime || this.settings.skipOffset) {
|
452
426
|
return Flatpickr.formatDate(date, format);
|
453
427
|
}
|
454
428
|
const currentValue = new Date(this.getValue());
|
455
429
|
if (currentValue.toString() === date.toString()) {
|
456
|
-
return formatOffset(
|
430
|
+
return formatOffset(Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
|
457
431
|
}
|
458
|
-
return formatOffset(
|
432
|
+
return formatOffset(Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);
|
459
433
|
}
|
460
434
|
return Flatpickr.formatDate(date, format);
|
461
435
|
};
|
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.5936.81a1533",
|
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": "v2.4.0-dev.
|
84
|
+
"@formio/core": "v2.4.0-dev.255.7fab6ff",
|
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,6 +92,7 @@
|
|
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",
|
95
96
|
"dialog-polyfill": "^0.5.6",
|
96
97
|
"dom-autoscroller": "^2.3.4",
|
97
98
|
"dompurify": "^3.2.5",
|
@@ -175,7 +176,8 @@
|
|
175
176
|
"webpack-bundle-analyzer": "^4.10.2",
|
176
177
|
"webpack-cli": "^5.1.1",
|
177
178
|
"webpack-node-externals": "^3.0.0",
|
178
|
-
"webpack-stream": "^7.0.0"
|
179
|
+
"webpack-stream": "^7.0.0",
|
180
|
+
"zx": "^8.5.4"
|
179
181
|
},
|
180
182
|
"nyc": {
|
181
183
|
"check-coverage": true,
|