@formio/js 5.1.0-dev.6094.c49181e → 5.1.0-dev.6096.8115e4f

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.
Files changed (33) hide show
  1. package/dist/formio.form.js +7 -7
  2. package/dist/formio.form.min.js +1 -1
  3. package/dist/formio.full.js +8 -8
  4. package/dist/formio.full.min.js +1 -1
  5. package/dist/formio.utils.js +1 -1
  6. package/dist/formio.utils.min.js +1 -1
  7. package/lib/cjs/Webform.js +2 -2
  8. package/lib/cjs/WebformBuilder.d.ts +1 -0
  9. package/lib/cjs/WebformBuilder.js +14 -0
  10. package/lib/cjs/components/button/Button.d.ts +1 -1
  11. package/lib/cjs/components/button/Button.js +6 -10
  12. package/lib/cjs/components/datetime/DateTime.d.ts +1 -1
  13. package/lib/cjs/components/datetime/DateTime.js +12 -14
  14. package/lib/cjs/components/file/File.js +4 -5
  15. package/lib/cjs/providers/storage/uploadAdapter.js +2 -2
  16. package/lib/cjs/utils/utils.d.ts +28 -18
  17. package/lib/cjs/utils/utils.js +89 -49
  18. package/lib/cjs/widgets/CalendarWidget.d.ts +7 -0
  19. package/lib/cjs/widgets/CalendarWidget.js +36 -12
  20. package/lib/mjs/Webform.js +2 -2
  21. package/lib/mjs/WebformBuilder.d.ts +1 -0
  22. package/lib/mjs/WebformBuilder.js +13 -0
  23. package/lib/mjs/components/button/Button.d.ts +1 -1
  24. package/lib/mjs/components/button/Button.js +6 -9
  25. package/lib/mjs/components/datetime/DateTime.d.ts +1 -1
  26. package/lib/mjs/components/datetime/DateTime.js +12 -14
  27. package/lib/mjs/components/file/File.js +4 -5
  28. package/lib/mjs/providers/storage/uploadAdapter.js +2 -2
  29. package/lib/mjs/utils/utils.d.ts +28 -18
  30. package/lib/mjs/utils/utils.js +82 -44
  31. package/lib/mjs/widgets/CalendarWidget.d.ts +7 -0
  32. package/lib/mjs/widgets/CalendarWidget.js +37 -13
  33. package/package.json +1 -2
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = __importDefault(require("lodash"));
7
+ const moment_1 = __importDefault(require("moment"));
7
8
  const compare_versions_1 = require("compare-versions");
8
9
  const EventEmitter_1 = __importDefault(require("./EventEmitter"));
9
10
  const i18n_1 = __importDefault(require("./i18n"));
@@ -12,7 +13,6 @@ const Components_1 = __importDefault(require("./components/Components"));
12
13
  const NestedDataComponent_1 = __importDefault(require("./components/_classes/nesteddata/NestedDataComponent"));
13
14
  const utils_1 = require("./utils/utils");
14
15
  const formUtils_1 = require("./utils/formUtils");
15
- const dayjs_1 = __importDefault(require("dayjs"));
16
16
  // We need this here because dragula pulls in CustomEvent class that requires global to exist.
17
17
  if (typeof window !== 'undefined' && typeof window.global === 'undefined') {
18
18
  window.global = window;
@@ -1314,7 +1314,7 @@ class Webform extends NestedDataComponent_1.default {
1314
1314
  submission.metadata = submission.metadata || {};
1315
1315
  lodash_1.default.defaults(submission.metadata, {
1316
1316
  timezone: lodash_1.default.get(this, '_submission.metadata.timezone', (0, utils_1.currentTimezone)()),
1317
- offset: parseInt(lodash_1.default.get(this, '_submission.metadata.offset', (0, dayjs_1.default)().utcOffset()), 10),
1317
+ offset: parseInt(lodash_1.default.get(this, '_submission.metadata.offset', (0, moment_1.default)().utcOffset()), 10),
1318
1318
  origin: document.location.origin,
1319
1319
  referrer: document.referrer,
1320
1320
  browserName: navigator.appName,
@@ -77,6 +77,7 @@ export default class WebformBuilder extends Component {
77
77
  removeComponent(component: any, parent: any, original: any, componentInstance: any): boolean | undefined;
78
78
  replaceDoubleQuotes(data: any, fieldsToRemoveDoubleQuotes?: any[]): any;
79
79
  updateComponent(component: any, changed: any): void;
80
+ originalDefaultValue: any;
80
81
  findRepeatablePaths(): any[];
81
82
  highlightInvalidComponents(): void;
82
83
  /**
@@ -1070,6 +1070,17 @@ class WebformBuilder extends Component_1.default {
1070
1070
  'fields.month.required',
1071
1071
  'fields.year.required',
1072
1072
  ]));
1073
+ if (defaultValueComponent.component.components) {
1074
+ if (!this.originalDefaultValue) {
1075
+ this.originalDefaultValue = (0, utils_1.fastCloneDeep)(defaultValueComponent.component);
1076
+ }
1077
+ (0, formUtils_1.eachComponent)(defaultValueComponent.component.components, (comp => {
1078
+ var _a;
1079
+ if ((_a = comp.validate) === null || _a === void 0 ? void 0 : _a.required) {
1080
+ comp.validate.required = false;
1081
+ }
1082
+ }));
1083
+ }
1073
1084
  const parentComponent = defaultValueComponent.parent;
1074
1085
  let tabIndex = -1;
1075
1086
  let index = -1;
@@ -1161,6 +1172,9 @@ class WebformBuilder extends Component_1.default {
1161
1172
  if (index !== -1) {
1162
1173
  let submissionData = this.editForm.submission.data;
1163
1174
  submissionData = submissionData.componentJson || submissionData;
1175
+ if (submissionData.components && this.originalDefaultValue) {
1176
+ submissionData.components = this.originalDefaultValue.components;
1177
+ }
1164
1178
  const fieldsToRemoveDoubleQuotes = ['label', 'tooltip'];
1165
1179
  this.replaceDoubleQuotes(submissionData, fieldsToRemoveDoubleQuotes);
1166
1180
  this.hook('beforeSaveComponentSettings', submissionData);
@@ -9,7 +9,7 @@ export default class ButtonComponent extends Field {
9
9
  };
10
10
  static savedValueTypes(schema: any): string[];
11
11
  constructor(component: any, options: any, data: any);
12
- filesUploading: any[];
12
+ filesUploading: number;
13
13
  get inputInfo(): any;
14
14
  get labelInfo(): {
15
15
  hidden: boolean;
@@ -39,7 +39,7 @@ class ButtonComponent extends Field_1.default {
39
39
  }
40
40
  constructor(component, options, data) {
41
41
  super(component, options, data);
42
- this.filesUploading = [];
42
+ this.filesUploading = 0;
43
43
  }
44
44
  get defaultSchema() {
45
45
  return ButtonComponent.schema();
@@ -147,16 +147,13 @@ class ButtonComponent extends Field_1.default {
147
147
  this.addClass(this.refs.buttonMessageContainer, 'has-error');
148
148
  this.setContent(this.refs.buttonMessage, resultMessage);
149
149
  }, true);
150
- this.on('fileUploadingStart', (filePromise) => {
151
- this.filesUploading.push(filePromise);
150
+ this.on('fileUploadingStart', () => {
151
+ this.filesUploading++;
152
152
  this.disabled = true;
153
153
  this.setDisabled(this.refs.button, this.disabled);
154
154
  }, true);
155
- this.on('fileUploadingEnd', (filePromise) => {
156
- const index = this.filesUploading.indexOf(filePromise);
157
- if (index !== -1) {
158
- this.filesUploading.splice(index, 1);
159
- }
155
+ this.on('fileUploadingEnd', () => {
156
+ this.filesUploading--;
160
157
  this.disabled = this.shouldDisabled ? true : false;
161
158
  this.setDisabled(this.refs.button, this.disabled);
162
159
  }, true);
@@ -252,8 +249,7 @@ class ButtonComponent extends Field_1.default {
252
249
  }
253
250
  }
254
251
  get shouldDisabled() {
255
- var _a;
256
- return super.shouldDisabled || !!((_a = this.filesUploading) === null || _a === void 0 ? void 0 : _a.length) || this.isDisabledOnInvalid;
252
+ return super.shouldDisabled || this.filesUploading > 0 || this.isDisabledOnInvalid;
257
253
  }
258
254
  attach(element) {
259
255
  this.loadRefs(element, {
@@ -17,7 +17,7 @@ export default class DateTimeComponent extends Input {
17
17
  };
18
18
  static savedValueTypes(schema: any): string[];
19
19
  get emptyValue(): string;
20
- get dayjsFormat(): string;
20
+ get momentFormat(): string;
21
21
  createWrapper(): boolean;
22
22
  checkValidity(data: any, dirty: any, rowData: any): boolean;
23
23
  getValueAsString(value: any, options: any): any;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = __importDefault(require("lodash"));
7
- const dayjs_1 = __importDefault(require("dayjs"));
7
+ const moment_1 = __importDefault(require("moment"));
8
8
  const utils_1 = __importDefault(require("../../utils"));
9
9
  const utils_2 = require("../../utils/utils");
10
10
  const Input_1 = __importDefault(require("../_classes/input/Input"));
@@ -123,8 +123,8 @@ class DateTimeComponent extends Input_1.default {
123
123
  get emptyValue() {
124
124
  return '';
125
125
  }
126
- get dayjsFormat() {
127
- return utils_1.default.convertFormatToDayjs(this.component.format);
126
+ get momentFormat() {
127
+ return utils_1.default.convertFormatToMoment(this.component.format);
128
128
  }
129
129
  isEmpty(value = this.dataValue) {
130
130
  if (value && (value.toString() === 'Invalid Date')) {
@@ -133,14 +133,12 @@ class DateTimeComponent extends Input_1.default {
133
133
  return super.isEmpty(value);
134
134
  }
135
135
  formatValue(input) {
136
- if ((0, dayjs_1.default)(input).isValid()) {
137
- return dayjs_1.default.utc(input).toISOString();
138
- }
139
- return input;
136
+ const result = moment_1.default.utc(input).toISOString();
137
+ return result === 'Invalid date' ? input : result;
140
138
  }
141
139
  isEqual(valueA, valueB = this.dataValue) {
142
140
  return (this.isEmpty(valueA) && this.isEmpty(valueB))
143
- || dayjs_1.default.utc(valueA).format(this.dayjsFormat) === dayjs_1.default.utc(valueB).format(this.dayjsFormat);
141
+ || moment_1.default.utc(valueA).format(this.momentFormat) === moment_1.default.utc(valueB).format(this.momentFormat);
144
142
  }
145
143
  createWrapper() {
146
144
  return false;
@@ -156,19 +154,19 @@ class DateTimeComponent extends Input_1.default {
156
154
  return super.checkValidity(data, dirty, rowData);
157
155
  }
158
156
  getValueAsString(value, options) {
159
- let format = utils_1.default.convertFormatToDayjs(this.component.format);
157
+ let format = utils_1.default.convertFormatToMoment(this.component.format);
158
+ format += format.match(/z$/) ? '' : ' z';
160
159
  const timezone = this.timezone;
161
160
  if (value && !this.attached && timezone) {
162
- format += format.match(/z$/) ? '' : ' z';
163
161
  if (Array.isArray(value) && this.component.multiple) {
164
- return value.map(item => lodash_1.default.trim(utils_1.default.dayjsDate(item, format, timezone, options).format(format))).join(', ');
162
+ return value.map(item => lodash_1.default.trim(utils_1.default.momentDate(item, format, timezone, options).format(format))).join(', ');
165
163
  }
166
- return lodash_1.default.trim(utils_1.default.dayjsDate(value, format, timezone, options).format(format));
164
+ return lodash_1.default.trim(utils_1.default.momentDate(value, format, timezone, options).format(format));
167
165
  }
168
166
  if (Array.isArray(value) && this.component.multiple) {
169
- return value.map(item => lodash_1.default.trim((0, dayjs_1.default)(item).format(format))).join(', ');
167
+ return value.map(item => lodash_1.default.trim((0, moment_1.default)(item).format(format))).join(', ');
170
168
  }
171
- return (value ? lodash_1.default.trim((0, dayjs_1.default)(value).format(format)) : value) || '';
169
+ return (value ? lodash_1.default.trim((0, moment_1.default)(value).format(format)) : value) || '';
172
170
  }
173
171
  }
174
172
  exports.default = DateTimeComponent;
@@ -905,17 +905,16 @@ class FileComponent extends Field_1.default {
905
905
  }
906
906
  uploadFile(fileToSync) {
907
907
  return __awaiter(this, void 0, void 0, function* () {
908
- const filePromise = this.fileService.uploadFile(fileToSync.storage, fileToSync.file, fileToSync.name, fileToSync.dir,
908
+ return yield this.fileService.uploadFile(fileToSync.storage, fileToSync.file, fileToSync.name, fileToSync.dir,
909
909
  // Progress callback
910
910
  this.updateProgress.bind(this, fileToSync), fileToSync.url, fileToSync.options, fileToSync.fileKey, fileToSync.groupPermissions, fileToSync.groupResourceId, () => {
911
- this.emit('fileUploadingStart', filePromise);
911
+ this.emit('fileUploadingStart');
912
912
  },
913
913
  // Abort upload callback
914
914
  (abort) => this.abortUploads.push({
915
915
  id: fileToSync.id,
916
916
  abort,
917
917
  }), this.getMultipartOptions(fileToSync));
918
- return yield filePromise;
919
918
  });
920
919
  }
921
920
  upload() {
@@ -937,7 +936,7 @@ class FileComponent extends Field_1.default {
937
936
  fileToSync.message = this.t('succefullyUploaded');
938
937
  fileInfo.originalName = fileToSync.originalName;
939
938
  fileInfo.hash = fileToSync.hash;
940
- this.emit('fileUploadingEnd', Promise.resolve(fileInfo));
939
+ this.emit('fileUploadingEnd');
941
940
  }
942
941
  catch (response) {
943
942
  fileToSync.status = 'error';
@@ -947,7 +946,7 @@ class FileComponent extends Field_1.default {
947
946
  : response.type === 'abort'
948
947
  ? this.t('Request was aborted')
949
948
  : response.toString();
950
- this.emit('fileUploadingEnd', Promise.reject(response));
949
+ this.emit('fileUploadingEnd');
951
950
  this.emit('fileUploadError', {
952
951
  fileToSync,
953
952
  response,
@@ -27,7 +27,7 @@ class FormioUploadAdapter {
27
27
  null,
28
28
  null
29
29
  ];
30
- const uploadPromise = this.fileService.uploadFile(...uploadParams, () => this.component.emit('fileUploadingStart', uploadPromise)).then((result) => {
30
+ this.fileService.uploadFile(...uploadParams, () => this.component.emit('fileUploadingStart')).then((result) => {
31
31
  return this.fileService.downloadFile(result);
32
32
  }).then((result) => {
33
33
  return resolve({
@@ -37,7 +37,7 @@ class FormioUploadAdapter {
37
37
  console.warn('An Error occured while uploading file', err);
38
38
  reject(err);
39
39
  }).finally(() => {
40
- this.component.emit('fileUploadingEnd', uploadPromise);
40
+ this.component.emit('fileUploadingEnd');
41
41
  });
42
42
  }));
43
43
  }
@@ -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|dayjs.Dayjs)} - The translated date.
167
+ * @returns {(null|Date)} - The translated date.
168
168
  */
169
- export function getDateSetting(date: string | Date): (null | dayjs.Dayjs);
169
+ export function getDateSetting(date: string | Date): (null | Date);
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,45 +182,56 @@ 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: Date, abbr: string}} - The offset date.
185
+ * @returns {Date} - The offset date.
186
186
  */
187
- export function offsetDate(date: Date, timezone: string): {
188
- date: Date;
189
- abbr: string;
190
- };
187
+ export function offsetDate(date: Date, timezone: string): Date;
188
+ /**
189
+ * Returns if the zones are loaded.
190
+ * @returns {boolean} - TRUE if the zones are loaded; FALSE otherwise.
191
+ */
192
+ export function zonesLoaded(): boolean;
191
193
  /**
192
- * Returns if we should handle a timezone difference.
194
+ * Returns if we should load the zones.
193
195
  * @param {string} timezone - The timezone to check if we should load the zones.
194
- * @returns {boolean} - TRUE if we should handle timezones; FALSE otherwise.
196
+ * @returns {boolean} - TRUE if we should load the zones; FALSE otherwise.
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.
195
204
  */
196
- export function shouldHandleTimezone(timezone: string): boolean;
205
+ export function loadZones(url: string, timezone: string): Promise<any> | any;
197
206
  /**
198
- * Get the Dayjs date object for translating dates with timezones.
199
- * @param {string|Date} value - The value to convert into a dayjs date.
207
+ * Get the moment date object for translating dates with timezones.
208
+ * @param {string|Date} value - The value to convert into a moment date.
200
209
  * @param {string} format - The format to convert the date to.
201
210
  * @param {string} timezone - The timezone to convert the date to.
202
211
  * @param {object} options - The options object
203
- * @returns {dayjs.Dayjs} - The dayjs date object.
212
+ * @returns {Date} - The moment date object.
204
213
  */
205
- export function dayjsDate(value: string | Date, format: string, timezone: string, options: object): dayjs.Dayjs;
214
+ export function momentDate(value: string | Date, format: string, timezone: string, options: object): Date;
206
215
  /**
207
216
  * Format a date provided a value, format, and timezone object.
217
+ * @param {string} timezonesUrl - The URL to load the timezone data from.
208
218
  * @param {string|Date} value - The value to format.
209
219
  * @param {string} format - The format to format the date to.
210
220
  * @param {string} timezone - The timezone to format the date to.
211
221
  * @param {string} flatPickrInputFormat - The format to use for flatpickr input.
212
222
  * @returns {string} - The formatted date.
213
223
  */
214
- export function formatDate(value: string | Date, format: string, timezone: string, flatPickrInputFormat: string): string;
224
+ export function formatDate(timezonesUrl: string, value: string | Date, format: string, timezone: string, flatPickrInputFormat: string): string;
215
225
  /**
216
226
  * Pass a format function to format within a timezone.
227
+ * @param {string} timezonesUrl - The URL to load the timezone data from.
217
228
  * @param {Function} formatFn - The format function to use.
218
229
  * @param {Date|string} date - The date to format.
219
230
  * @param {string} format - The format to format the date to.
220
231
  * @param {string} timezone - The timezone to format the date to.
221
232
  * @returns {string} - The formatted date.
222
233
  */
223
- export function formatOffset(formatFn: Function, date: Date | string, format: string, timezone: string): string;
234
+ export function formatOffset(timezonesUrl: string, formatFn: Function, date: Date | string, format: string, timezone: string): string;
224
235
  /**
225
236
  * Returns the local date format information.
226
237
  * @param {Intl.LocalesArgument} locale - The locale to get the date format for.
@@ -238,7 +249,7 @@ export function convertFormatToFlatpickr(format: string): string;
238
249
  * @param {string} format - The format to convert.
239
250
  * @returns {string} - The converted format.
240
251
  */
241
- export function convertFormatToDayjs(format: string): string;
252
+ export function convertFormatToMoment(format: string): string;
242
253
  /**
243
254
  * Convert the format from the angular-datepicker module to mask format.
244
255
  * @param {string} format - The format to convert.
@@ -505,7 +516,6 @@ export namespace componentValueTypes {
505
516
  let any: string;
506
517
  }
507
518
  export function interpolateErrors(component: Component, errors: FieldError[], interpolateFn: Function): [];
508
- import dayjs from "dayjs";
509
519
  import ConditionOperators from './conditionOperators';
510
520
  import { Evaluator } from './Evaluator';
511
521
  export const interpolate: typeof Evaluator.interpolate;
@@ -18,8 +18,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.observeOverload = exports.withSwitch = exports.firstNonNil = exports.unfold = exports.bootstrapVersion = exports.uniqueKey = exports.iterateKey = exports.delay = exports.fieldData = exports.getCurrencyAffixes = exports.getNumberDecimalLimit = exports.getNumberSeparators = exports.matchInputMask = exports.unmaskValue = exports.getInputMask = exports.convertFormatToMask = exports.convertFormatToDayjs = exports.convertFormatToFlatpickr = exports.getLocaleDateFormatInfo = exports.formatOffset = exports.formatDate = exports.dayjsDate = exports.shouldHandleTimezone = exports.offsetDate = exports.currentTimezone = exports.isValidDate = exports.getDateSetting = exports.guid = exports.uniqueName = exports.convertStringToHTMLElement = exports.unescapeHTML = exports.removeHTML = exports.setActionProperty = exports.checkTrigger = exports.checkCondition = exports.checkJsonConditional = exports.checkCustomConditional = exports.getComponentActualValue = exports.checkSimpleConditional = exports.checkCalculated = exports.isMongoId = exports.boolValue = exports.getScriptPlugin = exports.getElementRect = exports.getPropertyValue = exports.getRandomComponentId = exports.evaluate = exports.moment = exports.ConditionOperators = exports.jsonLogic = void 0;
22
- exports.hasEncodedTimezone = exports.interpolateErrors = exports.getComponentSavedTypes = exports.componentValueTypes = exports._ = exports.getFocusableElements = exports.isPromise = exports.getDataParentComponent = exports.getComponentPath = exports.getComponentPathWithoutIndicies = exports.getBrowserInfo = exports.getIEBrowserVersion = exports.round = exports.getStringFromComponentPath = exports.isChildOf = exports.getArrayFromComponentPath = exports.isInputComponent = exports.interpolate = exports.Evaluator = exports.fastCloneDeep = exports.sanitize = exports.translateHTMLTemplate = exports.getContextButtons = exports.getContextComponents = void 0;
21
+ exports.firstNonNil = exports.unfold = exports.bootstrapVersion = exports.uniqueKey = exports.iterateKey = exports.delay = exports.fieldData = exports.getCurrencyAffixes = exports.getNumberDecimalLimit = exports.getNumberSeparators = exports.matchInputMask = exports.unmaskValue = exports.getInputMask = exports.convertFormatToMask = exports.convertFormatToMoment = exports.convertFormatToFlatpickr = exports.getLocaleDateFormatInfo = exports.formatOffset = exports.formatDate = exports.momentDate = exports.loadZones = exports.shouldLoadZones = exports.zonesLoaded = exports.offsetDate = exports.currentTimezone = exports.isValidDate = exports.getDateSetting = exports.guid = exports.uniqueName = exports.convertStringToHTMLElement = exports.unescapeHTML = exports.removeHTML = exports.setActionProperty = exports.checkTrigger = exports.checkCondition = exports.checkJsonConditional = exports.checkCustomConditional = exports.getComponentActualValue = exports.checkSimpleConditional = exports.checkCalculated = exports.isMongoId = exports.boolValue = exports.getScriptPlugin = exports.getElementRect = exports.getPropertyValue = exports.getRandomComponentId = exports.evaluate = exports.moment = exports.ConditionOperators = exports.jsonLogic = void 0;
22
+ exports.hasEncodedTimezone = exports.interpolateErrors = exports.getComponentSavedTypes = exports.componentValueTypes = exports._ = exports.getFocusableElements = exports.isPromise = exports.getDataParentComponent = exports.getComponentPath = exports.getComponentPathWithoutIndicies = exports.getBrowserInfo = exports.getIEBrowserVersion = exports.round = exports.getStringFromComponentPath = exports.isChildOf = exports.getArrayFromComponentPath = exports.isInputComponent = exports.interpolate = exports.Evaluator = exports.fastCloneDeep = exports.sanitize = exports.translateHTMLTemplate = exports.getContextButtons = exports.getContextComponents = exports.observeOverload = exports.withSwitch = void 0;
23
23
  const lodash_1 = __importDefault(require("lodash"));
24
24
  exports._ = lodash_1.default;
25
25
  const json_logic_js_1 = __importDefault(require("json-logic-js"));
@@ -35,13 +35,6 @@ Object.defineProperty(exports, "Evaluator", { enumerable: true, get: function ()
35
35
  const conditionOperators_1 = __importDefault(require("./conditionOperators"));
36
36
  exports.ConditionOperators = conditionOperators_1.default;
37
37
  const core_1 = require("@formio/core");
38
- const dayjs_1 = __importDefault(require("dayjs"));
39
- const utc_1 = __importDefault(require("dayjs/plugin/utc"));
40
- const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
41
- const advancedFormat_1 = __importDefault(require("dayjs/plugin/advancedFormat"));
42
- dayjs_1.default.extend(timezone_1.default);
43
- dayjs_1.default.extend(advancedFormat_1.default);
44
- dayjs_1.default.extend(utc_1.default);
45
38
  const interpolate = Evaluator_1.Evaluator.interpolate;
46
39
  exports.interpolate = interpolate;
47
40
  __exportStar(require("./formUtils"), exports);
@@ -560,7 +553,7 @@ exports.guid = guid;
560
553
  /**
561
554
  * Return a translated date setting.
562
555
  * @param {string|Date} date - The date to translate.
563
- * @returns {(null|dayjs.Dayjs)} - The translated date.
556
+ * @returns {(null|Date)} - The translated date.
564
557
  */
565
558
  function getDateSetting(date) {
566
559
  if (lodash_1.default.isNil(date) || lodash_1.default.isNaN(date) || date === '') {
@@ -580,13 +573,13 @@ function getDateSetting(date) {
580
573
  try {
581
574
  const value = Evaluator_1.Evaluator.evaluator(`return ${date};`, 'moment')(moment_timezone_1.default);
582
575
  if (typeof value === 'string') {
583
- dateSetting = (0, dayjs_1.default)(value);
576
+ dateSetting = (0, moment_timezone_1.default)(value);
584
577
  }
585
578
  else if (typeof value.toDate === 'function') {
586
- dateSetting = (0, dayjs_1.default)(value.toDate().toUTCString());
579
+ dateSetting = (0, moment_timezone_1.default)(value.toDate().toUTCString());
587
580
  }
588
581
  else if (value instanceof Date) {
589
- dateSetting = (0, dayjs_1.default)(value);
582
+ dateSetting = (0, moment_timezone_1.default)(value);
590
583
  }
591
584
  }
592
585
  catch (e) {
@@ -616,18 +609,18 @@ exports.isValidDate = isValidDate;
616
609
  * @returns {string} - The current timezone.
617
610
  */
618
611
  function currentTimezone() {
619
- if (dayjs_1.default.currentTimezone) {
620
- return dayjs_1.default.currentTimezone;
612
+ if (moment_timezone_1.default.currentTimezone) {
613
+ return moment_timezone_1.default.currentTimezone;
621
614
  }
622
- dayjs_1.default.currentTimezone = jstimezonedetect_1.default.determine().name();
623
- return dayjs_1.default.currentTimezone;
615
+ moment_timezone_1.default.currentTimezone = jstimezonedetect_1.default.determine().name();
616
+ return moment_timezone_1.default.currentTimezone;
624
617
  }
625
618
  exports.currentTimezone = currentTimezone;
626
619
  /**
627
620
  * Get an offset date provided a date object and timezone object.
628
621
  * @param {Date} date - The date to offset.
629
622
  * @param {string} timezone - The timezone to offset the date to.
630
- * @returns {{date: Date, abbr: string}} - The offset date.
623
+ * @returns {Date} - The offset date.
631
624
  */
632
625
  function offsetDate(date, timezone) {
633
626
  if (timezone === 'UTC') {
@@ -636,7 +629,7 @@ function offsetDate(date, timezone) {
636
629
  abbr: 'UTC'
637
630
  };
638
631
  }
639
- const dateMoment = (0, dayjs_1.default)(date).tz(timezone);
632
+ const dateMoment = (0, moment_timezone_1.default)(date).tz(timezone);
640
633
  return {
641
634
  date: new Date(date.getTime() + ((dateMoment.utcOffset() + date.getTimezoneOffset()) * 60000)),
642
635
  abbr: dateMoment.format('z')
@@ -644,85 +637,132 @@ function offsetDate(date, timezone) {
644
637
  }
645
638
  exports.offsetDate = offsetDate;
646
639
  /**
647
- * Returns if we should handle a timezone difference.
640
+ * Returns if the zones are loaded.
641
+ * @returns {boolean} - TRUE if the zones are loaded; FALSE otherwise.
642
+ */
643
+ function zonesLoaded() {
644
+ return moment_timezone_1.default.zonesLoaded;
645
+ }
646
+ exports.zonesLoaded = zonesLoaded;
647
+ /**
648
+ * Returns if we should load the zones.
648
649
  * @param {string} timezone - The timezone to check if we should load the zones.
649
- * @returns {boolean} - TRUE if we should handle timezones; FALSE otherwise.
650
+ * @returns {boolean} - TRUE if we should load the zones; FALSE otherwise.
650
651
  */
651
- function shouldHandleTimezone(timezone) {
652
- return !(timezone === currentTimezone() || timezone === 'UTC');
652
+ function shouldLoadZones(timezone) {
653
+ if (timezone === currentTimezone() || timezone === 'UTC') {
654
+ return false;
655
+ }
656
+ return true;
657
+ }
658
+ exports.shouldLoadZones = shouldLoadZones;
659
+ /**
660
+ * Externally load the timezone data.
661
+ * @param {string} url - The URL to load the timezone data from.
662
+ * @param {string} timezone - The timezone to load.
663
+ * @returns {Promise<any> | *} - Resolves when the zones for this timezone are loaded.
664
+ */
665
+ function loadZones(url, timezone) {
666
+ if (timezone && !shouldLoadZones(timezone)) {
667
+ // Return non-resolving promise.
668
+ return new Promise(lodash_1.default.noop);
669
+ }
670
+ if (moment_timezone_1.default.zonesPromise) {
671
+ return moment_timezone_1.default.zonesPromise;
672
+ }
673
+ return moment_timezone_1.default.zonesPromise = fetch(url)
674
+ .then(resp => resp.json().then(zones => {
675
+ moment_timezone_1.default.tz.load(zones);
676
+ moment_timezone_1.default.zonesLoaded = true;
677
+ // Trigger a global event that the timezones have finished loading.
678
+ if (document && document.createEvent && document.body && document.body.dispatchEvent) {
679
+ var event = document.createEvent('Event');
680
+ event.initEvent('zonesLoaded', true, true);
681
+ document.body.dispatchEvent(event);
682
+ }
683
+ }));
653
684
  }
654
- exports.shouldHandleTimezone = shouldHandleTimezone;
685
+ exports.loadZones = loadZones;
655
686
  /**
656
- * Get the Dayjs date object for translating dates with timezones.
657
- * @param {string|Date} value - The value to convert into a dayjs date.
687
+ * Get the moment date object for translating dates with timezones.
688
+ * @param {string|Date} value - The value to convert into a moment date.
658
689
  * @param {string} format - The format to convert the date to.
659
690
  * @param {string} timezone - The timezone to convert the date to.
660
691
  * @param {object} options - The options object
661
- * @returns {dayjs.Dayjs} - The dayjs date object.
692
+ * @returns {Date} - The moment date object.
662
693
  */
663
- function dayjsDate(value, format, timezone, options) {
664
- const dayjsDate = (0, dayjs_1.default)(value);
694
+ function momentDate(value, format, timezone, options) {
695
+ const momentDate = (0, moment_timezone_1.default)(value);
665
696
  if (!timezone) {
666
- return dayjsDate;
697
+ return momentDate;
667
698
  }
668
699
  if (timezone === 'UTC') {
669
700
  timezone = 'Etc/UTC';
670
701
  }
671
- if ((timezone !== currentTimezone() || (format && format.match(/\s(z$|z\s)/))) && (shouldHandleTimezone(timezone) || (options === null || options === void 0 ? void 0 : options.email))) {
672
- return dayjsDate.tz(timezone);
702
+ if ((timezone !== currentTimezone() || (format && format.match(/\s(z$|z\s)/))) && (moment_timezone_1.default.zonesLoaded || (options === null || options === void 0 ? void 0 : options.email))) {
703
+ return momentDate.tz(timezone);
673
704
  }
674
- return dayjsDate;
705
+ return momentDate;
675
706
  }
676
- exports.dayjsDate = dayjsDate;
707
+ exports.momentDate = momentDate;
677
708
  /**
678
709
  * Format a date provided a value, format, and timezone object.
710
+ * @param {string} timezonesUrl - The URL to load the timezone data from.
679
711
  * @param {string|Date} value - The value to format.
680
712
  * @param {string} format - The format to format the date to.
681
713
  * @param {string} timezone - The timezone to format the date to.
682
714
  * @param {string} flatPickrInputFormat - The format to use for flatpickr input.
683
715
  * @returns {string} - The formatted date.
684
716
  */
685
- function formatDate(value, format, timezone, flatPickrInputFormat) {
686
- const dayjsDate = (0, dayjs_1.default)(value, flatPickrInputFormat || undefined);
717
+ function formatDate(timezonesUrl, value, format, timezone, flatPickrInputFormat) {
718
+ const momentDate = (0, moment_timezone_1.default)(value, flatPickrInputFormat || undefined);
687
719
  if (timezone === currentTimezone()) {
688
720
  // See if our format contains a "z" timezone character.
689
721
  if (format.match(/\s(z$|z\s)/)) {
690
- if (shouldHandleTimezone(timezone)) {
691
- return dayjsDate.tz(timezone).format(convertFormatToDayjs(format));
722
+ loadZones(timezonesUrl);
723
+ if (moment_timezone_1.default.zonesLoaded) {
724
+ return momentDate.tz(timezone).format(convertFormatToMoment(format));
692
725
  }
693
726
  else {
694
- return dayjsDate.format(convertFormatToDayjs(format.replace(/\s(z$|z\s)/, '')));
727
+ return momentDate.format(convertFormatToMoment(format.replace(/\s(z$|z\s)/, '')));
695
728
  }
696
729
  }
697
730
  // Return the standard format.
698
- return dayjsDate.format(convertFormatToDayjs(format));
731
+ return momentDate.format(convertFormatToMoment(format));
699
732
  }
700
733
  if (timezone === 'UTC') {
701
- const offset = offsetDate(dayjsDate.toDate(), 'UTC');
702
- return `${(0, dayjs_1.default)(offset.date).format(convertFormatToDayjs(format))} UTC`;
734
+ const offset = offsetDate(momentDate.toDate(), 'UTC');
735
+ return `${(0, moment_timezone_1.default)(offset.date).format(convertFormatToMoment(format))} UTC`;
703
736
  }
704
- if (shouldHandleTimezone(timezone)) {
705
- return dayjsDate.tz(timezone).format(`${convertFormatToDayjs(format)} z`);
737
+ // Load the zones since we need timezone information.
738
+ loadZones(timezonesUrl);
739
+ if (moment_timezone_1.default.zonesLoaded && timezone) {
740
+ return momentDate.tz(timezone).format(`${convertFormatToMoment(format)} z`);
741
+ }
742
+ else {
743
+ return momentDate.format(convertFormatToMoment(format));
706
744
  }
707
- return dayjsDate.format(convertFormatToDayjs(format));
708
745
  }
709
746
  exports.formatDate = formatDate;
710
747
  /**
711
748
  * Pass a format function to format within a timezone.
749
+ * @param {string} timezonesUrl - The URL to load the timezone data from.
712
750
  * @param {Function} formatFn - The format function to use.
713
751
  * @param {Date|string} date - The date to format.
714
752
  * @param {string} format - The format to format the date to.
715
753
  * @param {string} timezone - The timezone to format the date to.
716
754
  * @returns {string} - The formatted date.
717
755
  */
718
- function formatOffset(formatFn, date, format, timezone) {
756
+ function formatOffset(timezonesUrl, formatFn, date, format, timezone) {
719
757
  if (timezone === currentTimezone()) {
720
758
  return formatFn(date, format);
721
759
  }
722
760
  if (timezone === 'UTC') {
723
761
  return `${formatFn(offsetDate(date, 'UTC').date, format)} UTC`;
724
762
  }
725
- if (shouldHandleTimezone(timezone)) {
763
+ // Load the zones since we need timezone information.
764
+ loadZones(timezonesUrl);
765
+ if (moment_timezone_1.default.zonesLoaded) {
726
766
  const offset = offsetDate(date, timezone);
727
767
  return `${formatFn(offset.date, format)} ${offset.abbr}`;
728
768
  }
@@ -782,7 +822,7 @@ exports.convertFormatToFlatpickr = convertFormatToFlatpickr;
782
822
  * @param {string} format - The format to convert.
783
823
  * @returns {string} - The converted format.
784
824
  */
785
- function convertFormatToDayjs(format) {
825
+ function convertFormatToMoment(format) {
786
826
  return format
787
827
  // Year conversion.
788
828
  .replace(/y/g, 'Y')
@@ -795,7 +835,7 @@ function convertFormatToDayjs(format) {
795
835
  // Unix Timestamp
796
836
  .replace(/U/g, 'X');
797
837
  }
798
- exports.convertFormatToDayjs = convertFormatToDayjs;
838
+ exports.convertFormatToMoment = convertFormatToMoment;
799
839
  /**
800
840
  * Convert the format from the angular-datepicker module to mask format.
801
841
  * @param {string} format - The format to convert.
@@ -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;