@formio/js 5.1.0-dev.6086.0b0957a → 5.1.0-dev.6094.90c04d1

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.
@@ -1,6 +1,6 @@
1
1
  import { Formio } from '../Formio';
2
2
  import InputWidget from './InputWidget';
3
- import { convertFormatToFlatpickr, convertFormatToMask, convertFormatToMoment, formatDate, formatOffset, getBrowserInfo, getDateSetting, getLocaleDateFormatInfo, momentDate, zonesLoaded, shouldLoadZones, loadZones, } from '../utils/utils';
3
+ import { convertFormatToFlatpickr, convertFormatToMask, convertFormatToDayjs, formatDate, formatOffset, getBrowserInfo, getDateSetting, getLocaleDateFormatInfo, dayjsDate, hasEncodedTimezone, } from '../utils/utils';
4
4
  import moment from 'moment';
5
5
  import _ from 'lodash';
6
6
  const DEFAULT_FORMAT = 'yyyy-MM-dd hh:mm a';
@@ -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 = convertFormatToMoment(this.valueFormat);
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 momentDate(date, this.valueFormat, this.timezone).format(convertFormatToMoment(format));
221
+ return dayjsDate(date, this.valueFormat, this.timezone).format(convertFormatToDayjs(format));
245
222
  }
246
- return moment(date).format(convertFormatToMoment(format));
223
+ return moment(date).format(convertFormatToDayjs(format));
247
224
  }
248
225
  /**
249
226
  * Return the value of the selected date.
@@ -275,13 +252,17 @@ 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(this.timezonesUrl, value, convertFormatToMoment(this.settings.format), this.timezone, convertFormatToMoment(this.valueMomentFormat)) : value;
255
+ value = value ? formatDate(value, convertFormatToDayjs(this.settings.format), this.timezone, convertFormatToDayjs(this.valueMomentFormat)) : value;
279
256
  return super.setValue(value);
280
257
  }
281
- const zonesLoading = this.loadZones();
258
+ // If the component is a textfield that does not have timezone information included in the string value then skip
259
+ // the timezone offset
260
+ if (this.component.type === 'textfield' && !hasEncodedTimezone(value)) {
261
+ this.settings.skipOffset = true;
262
+ }
282
263
  if (value) {
283
- if (!saveAsText && this.settings.readOnly && !zonesLoading) {
284
- this.calendar.setDate(momentDate(value, this.valueFormat, this.timezone).format(), false);
264
+ if (!saveAsText && this.settings.readOnly) {
265
+ this.calendar.setDate(dayjsDate(value, this.valueFormat, this.timezone).format(), false);
285
266
  }
286
267
  else if (this.isValueISO8601(value)) {
287
268
  this.calendar.setDate(value, false);
@@ -298,9 +279,9 @@ export default class CalendarWidget extends InputWidget {
298
279
  const inputFormat = format || this.dateFormat;
299
280
  const valueFormat = this.calendar ? this.valueFormat : this.settings.dateFormat;
300
281
  if (this.settings.saveAs === 'text' && this.componentInstance.parent && !this.settings.readOnly) {
301
- return moment(value, convertFormatToMoment(valueFormat)).format(convertFormatToMoment(valueFormat));
282
+ return moment(value, convertFormatToDayjs(valueFormat)).format(convertFormatToDayjs(valueFormat));
302
283
  }
303
- return formatDate(this.timezonesUrl, value, inputFormat, this.timezone, convertFormatToMoment(valueFormat));
284
+ return formatDate(value, inputFormat, this.timezone, convertFormatToDayjs(valueFormat));
304
285
  }
305
286
  setErrorClasses(hasErrors) {
306
287
  if (!this.input) {
@@ -391,7 +372,7 @@ export default class CalendarWidget extends InputWidget {
391
372
  const relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;
392
373
  if (!(isIEBrowser && !relatedTarget) && !this.isCalendarElement(relatedTarget)) {
393
374
  const inputValue = this.calendar.input.value;
394
- const dateValue = inputValue ? moment(this.calendar.input.value, convertFormatToMoment(this.valueFormat)).toDate() : inputValue;
375
+ const dateValue = inputValue ? moment(this.calendar.input.value, convertFormatToDayjs(this.valueFormat)).toDate() : inputValue;
395
376
  this.calendar.setDate(dateValue, true, this.settings.altFormat);
396
377
  }
397
378
  else if (!this.calendar.input.value && this.calendar.config.noCalendar) {
@@ -443,14 +424,14 @@ export default class CalendarWidget extends InputWidget {
443
424
  return (date, format) => {
444
425
  // Only format this if this is the altFormat and the form is readOnly.
445
426
  if (this.settings.readOnly && (format === this.settings.altFormat)) {
446
- if (!this.settings.enableTime || this.loadZones()) {
427
+ if (!this.settings.enableTime || this.settings.skipOffset) {
447
428
  return Flatpickr.formatDate(date, format);
448
429
  }
449
430
  const currentValue = new Date(this.getValue());
450
431
  if (currentValue.toString() === date.toString()) {
451
- return formatOffset(this.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
432
+ return formatOffset(Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
452
433
  }
453
- return formatOffset(this.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);
434
+ return formatOffset(Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);
454
435
  }
455
436
  return Flatpickr.formatDate(date, format);
456
437
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-dev.6086.0b0957a",
3
+ "version": "5.1.0-dev.6094.90c04d1",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {
@@ -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.1.6",
@@ -108,7 +109,7 @@
108
109
  "jwt-decode": "^3.1.2",
109
110
  "lodash": "^4.17.21",
110
111
  "moment": "^2.29.4",
111
- "moment-timezone": "^0.5.44",
112
+ "moment-timezone": "^0.5.48",
112
113
  "quill": "^2.0.2",
113
114
  "signature_pad": "^4.2.0",
114
115
  "string-hash": "^1.1.3",