@opengeoweb/form-fields 6.0.3 → 6.1.0

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 (2) hide show
  1. package/index.esm.js +138 -112
  2. package/package.json +2 -2
package/index.esm.js CHANGED
@@ -29563,11 +29563,24 @@ function _inheritsLoose(subClass, superClass) {
29563
29563
  _setPrototypeOf(subClass, superClass);
29564
29564
  }
29565
29565
 
29566
+ /**
29567
+ * Checks if a given element has a CSS class.
29568
+ *
29569
+ * @param element the element
29570
+ * @param className the CSS class name
29571
+ */
29566
29572
  function hasClass(element, className) {
29567
29573
  if (element.classList) return !!className && element.classList.contains(className);
29568
29574
  return (" " + (element.className.baseVal || element.className) + " ").indexOf(" " + className + " ") !== -1;
29569
29575
  }
29570
29576
 
29577
+ /**
29578
+ * Adds a CSS class to a given element.
29579
+ *
29580
+ * @param element the element
29581
+ * @param className the CSS class name
29582
+ */
29583
+
29571
29584
  function addClass(element, className) {
29572
29585
  if (element.classList) element.classList.add(className);else if (!hasClass(element, className)) if (typeof element.className === 'string') element.className = element.className + " " + className;else element.setAttribute('class', (element.className && element.className.baseVal || '') + " " + className);
29573
29586
  }
@@ -29575,6 +29588,13 @@ function addClass(element, className) {
29575
29588
  function replaceClassName(origClass, classToRemove) {
29576
29589
  return origClass.replace(new RegExp("(^|\\s)" + classToRemove + "(?:\\s|$)", 'g'), '$1').replace(/\s+/g, ' ').replace(/^\s*|\s*$/g, '');
29577
29590
  }
29591
+ /**
29592
+ * Removes a CSS class from a given element.
29593
+ *
29594
+ * @param element the element
29595
+ * @param className the CSS class name
29596
+ */
29597
+
29578
29598
 
29579
29599
  function removeClass$1(element, className) {
29580
29600
  if (element.classList) {
@@ -40066,7 +40086,7 @@ var ReactHookKeyboardDateTimePicker = function ReactHookKeyboardDateTimePicker(_
40066
40086
  }, otherProps)));
40067
40087
  };
40068
40088
 
40069
- var defaultFormats = {
40089
+ const defaultFormats = {
40070
40090
  normalDateWithWeekday: "ddd, MMM D",
40071
40091
  normalDate: "D MMMM",
40072
40092
  shortDate: "MMM D",
@@ -40095,253 +40115,261 @@ var defaultFormats = {
40095
40115
  keyboardDateTime12h: "L hh:mm A",
40096
40116
  keyboardDateTime24h: "L HH:mm",
40097
40117
  };
40098
- var MomentUtils = /** @class */ (function () {
40099
- function MomentUtils(_a) {
40100
- var _this = this;
40101
- var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats, instance = _b.instance;
40118
+ class MomentUtils {
40119
+ constructor({ locale, formats, instance } = {}) {
40102
40120
  this.lib = "moment";
40103
- this.is12HourCycleInCurrentLocale = function () {
40104
- return /A|a/.test(_this.moment.localeData(_this.getCurrentLocaleCode()).longDateFormat("LT"));
40121
+ this.is12HourCycleInCurrentLocale = () => {
40122
+ return /A|a/.test(this.moment.localeData(this.getCurrentLocaleCode()).longDateFormat("LT"));
40105
40123
  };
40106
- this.getFormatHelperText = function (format) {
40124
+ this.getFormatHelperText = (format) => {
40125
+ var _a, _b;
40107
40126
  // @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6
40108
- var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
40109
- return format
40110
- .match(localFormattingTokens)
40111
- .map(function (token) {
40112
- var firstCharacter = token[0];
40127
+ const localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
40128
+ return ((_b = (_a = format
40129
+ .match(localFormattingTokens)) === null || _a === void 0 ? void 0 : _a.map((token) => {
40130
+ const firstCharacter = token[0];
40113
40131
  if (firstCharacter === "L" || firstCharacter === ";") {
40114
- return _this.moment
40115
- .localeData(_this.getCurrentLocaleCode())
40132
+ return this.moment
40133
+ .localeData(this.getCurrentLocaleCode())
40116
40134
  .longDateFormat(token);
40117
40135
  }
40118
40136
  return token;
40119
- })
40120
- .join("")
40121
- .replace(/a/gi, "(a|p)m")
40122
- .toLocaleLowerCase();
40137
+ }).join("").replace(/a/gi, "(a|p)m").toLocaleLowerCase()) !== null && _b !== void 0 ? _b : format);
40123
40138
  };
40124
- this.getCurrentLocaleCode = function () {
40125
- return _this.locale || _this.moment.locale();
40139
+ this.getCurrentLocaleCode = () => {
40140
+ return this.locale || this.moment.locale();
40126
40141
  };
40127
- this.parseISO = function (isoString) {
40128
- return _this.moment(isoString, true);
40142
+ this.parseISO = (isoString) => {
40143
+ return this.moment(isoString, true);
40129
40144
  };
40130
- this.toISO = function (value) {
40145
+ this.toISO = (value) => {
40131
40146
  return value.toISOString();
40132
40147
  };
40133
- this.parse = function (value, format) {
40148
+ this.parse = (value, format) => {
40134
40149
  if (value === "") {
40135
40150
  return null;
40136
40151
  }
40137
- if (_this.locale) {
40138
- return _this.moment(value, format, _this.locale, true);
40152
+ if (this.locale) {
40153
+ return this.moment(value, format, this.locale, true);
40139
40154
  }
40140
- return _this.moment(value, format, true);
40155
+ return this.moment(value, format, true);
40141
40156
  };
40142
- this.date = function (value) {
40157
+ this.date = (value) => {
40143
40158
  if (value === null) {
40144
40159
  return null;
40145
40160
  }
40146
- var moment = _this.moment(value);
40147
- moment.locale(_this.locale);
40161
+ const moment = this.moment(value);
40162
+ if (this.locale) {
40163
+ moment.locale(this.locale);
40164
+ }
40148
40165
  return moment;
40149
40166
  };
40150
- this.toJsDate = function (value) {
40167
+ this.toJsDate = (value) => {
40151
40168
  return value.toDate();
40152
40169
  };
40153
- this.isValid = function (value) {
40154
- return _this.moment(value).isValid();
40170
+ this.isValid = (value) => {
40171
+ return this.moment(value).isValid();
40155
40172
  };
40156
- this.isNull = function (date) {
40173
+ this.isNull = (date) => {
40157
40174
  return date === null;
40158
40175
  };
40159
- this.getDiff = function (date, comparing, unit) {
40176
+ this.getDiff = (date, comparing, unit) => {
40177
+ if (!this.moment(comparing).isValid()) {
40178
+ return 0;
40179
+ }
40160
40180
  return date.diff(comparing, unit);
40161
40181
  };
40162
- this.isAfter = function (date, value) {
40182
+ this.isAfter = (date, value) => {
40163
40183
  return date.isAfter(value);
40164
40184
  };
40165
- this.isBefore = function (date, value) {
40185
+ this.isBefore = (date, value) => {
40166
40186
  return date.isBefore(value);
40167
40187
  };
40168
- this.isAfterDay = function (date, value) {
40188
+ this.isAfterDay = (date, value) => {
40169
40189
  return date.isAfter(value, "day");
40170
40190
  };
40171
- this.isBeforeDay = function (date, value) {
40191
+ this.isBeforeDay = (date, value) => {
40172
40192
  return date.isBefore(value, "day");
40173
40193
  };
40174
- this.isBeforeYear = function (date, value) {
40194
+ this.isBeforeMonth = (date, value) => {
40195
+ return date.isBefore(value, "month");
40196
+ };
40197
+ this.isAfterMonth = (date, value) => {
40198
+ return date.isAfter(value, "month");
40199
+ };
40200
+ this.isBeforeYear = (date, value) => {
40175
40201
  return date.isBefore(value, "year");
40176
40202
  };
40177
- this.isAfterYear = function (date, value) {
40203
+ this.isAfterYear = (date, value) => {
40178
40204
  return date.isAfter(value, "year");
40179
40205
  };
40180
- this.startOfDay = function (date) {
40206
+ this.startOfDay = (date) => {
40181
40207
  return date.clone().startOf("day");
40182
40208
  };
40183
- this.endOfDay = function (date) {
40209
+ this.endOfDay = (date) => {
40184
40210
  return date.clone().endOf("day");
40185
40211
  };
40186
- this.format = function (date, formatKey) {
40187
- return _this.formatByString(date, _this.formats[formatKey]);
40212
+ this.format = (date, formatKey) => {
40213
+ return this.formatByString(date, this.formats[formatKey]);
40188
40214
  };
40189
- this.formatByString = function (date, formatString) {
40190
- var clonedDate = date.clone();
40191
- clonedDate.locale(_this.locale);
40215
+ this.formatByString = (date, formatString) => {
40216
+ const clonedDate = date.clone();
40217
+ if (this.locale) {
40218
+ clonedDate.locale(this.locale);
40219
+ }
40192
40220
  return clonedDate.format(formatString);
40193
40221
  };
40194
- this.formatNumber = function (numberToFormat) {
40222
+ this.formatNumber = (numberToFormat) => {
40195
40223
  return numberToFormat;
40196
40224
  };
40197
- this.getHours = function (date) {
40225
+ this.getHours = (date) => {
40198
40226
  return date.get("hours");
40199
40227
  };
40200
- this.addSeconds = function (date, count) {
40228
+ this.addSeconds = (date, count) => {
40201
40229
  return count < 0
40202
40230
  ? date.clone().subtract(Math.abs(count), "seconds")
40203
40231
  : date.clone().add(count, "seconds");
40204
40232
  };
40205
- this.addMinutes = function (date, count) {
40233
+ this.addMinutes = (date, count) => {
40206
40234
  return count < 0
40207
40235
  ? date.clone().subtract(Math.abs(count), "minutes")
40208
40236
  : date.clone().add(count, "minutes");
40209
40237
  };
40210
- this.addHours = function (date, count) {
40238
+ this.addHours = (date, count) => {
40211
40239
  return count < 0
40212
40240
  ? date.clone().subtract(Math.abs(count), "hours")
40213
40241
  : date.clone().add(count, "hours");
40214
40242
  };
40215
- this.addDays = function (date, count) {
40243
+ this.addDays = (date, count) => {
40216
40244
  return count < 0
40217
40245
  ? date.clone().subtract(Math.abs(count), "days")
40218
40246
  : date.clone().add(count, "days");
40219
40247
  };
40220
- this.addWeeks = function (date, count) {
40248
+ this.addWeeks = (date, count) => {
40221
40249
  return count < 0
40222
40250
  ? date.clone().subtract(Math.abs(count), "weeks")
40223
40251
  : date.clone().add(count, "weeks");
40224
40252
  };
40225
- this.addMonths = function (date, count) {
40253
+ this.addMonths = (date, count) => {
40226
40254
  return count < 0
40227
40255
  ? date.clone().subtract(Math.abs(count), "months")
40228
40256
  : date.clone().add(count, "months");
40229
40257
  };
40230
- this.addYears = function (date, count) {
40258
+ this.addYears = (date, count) => {
40231
40259
  return count < 0
40232
40260
  ? date.clone().subtract(Math.abs(count), "years")
40233
40261
  : date.clone().add(count, "years");
40234
40262
  };
40235
- this.setHours = function (date, count) {
40263
+ this.setHours = (date, count) => {
40236
40264
  return date.clone().hours(count);
40237
40265
  };
40238
- this.getMinutes = function (date) {
40266
+ this.getMinutes = (date) => {
40239
40267
  return date.get("minutes");
40240
40268
  };
40241
- this.setMinutes = function (date, count) {
40269
+ this.setMinutes = (date, count) => {
40242
40270
  return date.clone().minutes(count);
40243
40271
  };
40244
- this.getSeconds = function (date) {
40272
+ this.getSeconds = (date) => {
40245
40273
  return date.get("seconds");
40246
40274
  };
40247
- this.setSeconds = function (date, count) {
40275
+ this.setSeconds = (date, count) => {
40248
40276
  return date.clone().seconds(count);
40249
40277
  };
40250
- this.getMonth = function (date) {
40278
+ this.getMonth = (date) => {
40251
40279
  return date.get("month");
40252
40280
  };
40253
- this.getDaysInMonth = function (date) {
40281
+ this.getDaysInMonth = (date) => {
40254
40282
  return date.daysInMonth();
40255
40283
  };
40256
- this.isSameDay = function (date, comparing) {
40284
+ this.isSameDay = (date, comparing) => {
40257
40285
  return date.isSame(comparing, "day");
40258
40286
  };
40259
- this.isSameMonth = function (date, comparing) {
40287
+ this.isSameMonth = (date, comparing) => {
40260
40288
  return date.isSame(comparing, "month");
40261
40289
  };
40262
- this.isSameYear = function (date, comparing) {
40290
+ this.isSameYear = (date, comparing) => {
40263
40291
  return date.isSame(comparing, "year");
40264
40292
  };
40265
- this.isSameHour = function (date, comparing) {
40293
+ this.isSameHour = (date, comparing) => {
40266
40294
  return date.isSame(comparing, "hour");
40267
40295
  };
40268
- this.setMonth = function (date, count) {
40296
+ this.setMonth = (date, count) => {
40269
40297
  return date.clone().month(count);
40270
40298
  };
40271
- this.getMeridiemText = function (ampm) {
40272
- if (_this.is12HourCycleInCurrentLocale()) {
40299
+ this.getMeridiemText = (ampm) => {
40300
+ if (this.is12HourCycleInCurrentLocale()) {
40273
40301
  // AM/PM translation only possible in those who have 12 hour cycle in locale.
40274
- return _this.moment
40275
- .localeData(_this.getCurrentLocaleCode())
40302
+ return this.moment
40303
+ .localeData(this.getCurrentLocaleCode())
40276
40304
  .meridiem(ampm === "am" ? 0 : 13, 0, false);
40277
40305
  }
40278
40306
  return ampm === "am" ? "AM" : "PM"; // fallback for de, ru, ...etc
40279
40307
  };
40280
- this.startOfYear = function (date) {
40308
+ this.startOfYear = (date) => {
40281
40309
  return date.clone().startOf("year");
40282
40310
  };
40283
- this.endOfYear = function (date) {
40311
+ this.endOfYear = (date) => {
40284
40312
  return date.clone().endOf("year");
40285
40313
  };
40286
- this.startOfMonth = function (date) {
40314
+ this.startOfMonth = (date) => {
40287
40315
  return date.clone().startOf("month");
40288
40316
  };
40289
- this.endOfMonth = function (date) {
40317
+ this.endOfMonth = (date) => {
40290
40318
  return date.clone().endOf("month");
40291
40319
  };
40292
- this.startOfWeek = function (date) {
40320
+ this.startOfWeek = (date) => {
40293
40321
  return date.clone().startOf("week");
40294
40322
  };
40295
- this.endOfWeek = function (date) {
40323
+ this.endOfWeek = (date) => {
40296
40324
  return date.clone().endOf("week");
40297
40325
  };
40298
- this.getNextMonth = function (date) {
40326
+ this.getNextMonth = (date) => {
40299
40327
  return date.clone().add(1, "month");
40300
40328
  };
40301
- this.getPreviousMonth = function (date) {
40329
+ this.getPreviousMonth = (date) => {
40302
40330
  return date.clone().subtract(1, "month");
40303
40331
  };
40304
- this.getMonthArray = function (date) {
40305
- var firstMonth = date.clone().startOf("year");
40306
- var monthArray = [firstMonth];
40332
+ this.getMonthArray = (date) => {
40333
+ const firstMonth = date.clone().startOf("year");
40334
+ const monthArray = [firstMonth];
40307
40335
  while (monthArray.length < 12) {
40308
- var prevMonth = monthArray[monthArray.length - 1];
40309
- monthArray.push(_this.getNextMonth(prevMonth));
40336
+ const prevMonth = monthArray[monthArray.length - 1];
40337
+ monthArray.push(this.getNextMonth(prevMonth));
40310
40338
  }
40311
40339
  return monthArray;
40312
40340
  };
40313
- this.getYear = function (date) {
40341
+ this.getYear = (date) => {
40314
40342
  return date.get("year");
40315
40343
  };
40316
- this.setYear = function (date, year) {
40344
+ this.setYear = (date, year) => {
40317
40345
  return date.clone().set("year", year);
40318
40346
  };
40319
- this.getDate = function (date) {
40347
+ this.getDate = (date) => {
40320
40348
  return date.get("date");
40321
40349
  };
40322
- this.setDate = function (date, year) {
40350
+ this.setDate = (date, year) => {
40323
40351
  return date.clone().set("date", year);
40324
40352
  };
40325
- this.mergeDateAndTime = function (date, time) {
40353
+ this.mergeDateAndTime = (date, time) => {
40326
40354
  return date.hour(time.hour()).minute(time.minute()).second(time.second());
40327
40355
  };
40328
- this.getWeekdays = function () {
40329
- return _this.moment.weekdaysShort(true);
40356
+ this.getWeekdays = () => {
40357
+ return this.moment.weekdaysShort(true);
40330
40358
  };
40331
- this.isEqual = function (value, comparing) {
40359
+ this.isEqual = (value, comparing) => {
40332
40360
  if (value === null && comparing === null) {
40333
40361
  return true;
40334
40362
  }
40335
- return _this.moment(value).isSame(comparing);
40363
+ return this.moment(value).isSame(comparing);
40336
40364
  };
40337
- this.getWeekArray = function (date) {
40338
- var start = date.clone().startOf("month").startOf("week");
40339
- var end = date.clone().endOf("month").endOf("week");
40340
- var count = 0;
40341
- var current = start;
40342
- var nestedWeeks = [];
40365
+ this.getWeekArray = (date) => {
40366
+ const start = date.clone().startOf("month").startOf("week");
40367
+ const end = date.clone().endOf("month").endOf("week");
40368
+ let count = 0;
40369
+ let current = start;
40370
+ const nestedWeeks = [];
40343
40371
  while (current.isBefore(end)) {
40344
- var weekNumber = Math.floor(count / 7);
40372
+ const weekNumber = Math.floor(count / 7);
40345
40373
  nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
40346
40374
  nestedWeeks[weekNumber].push(current);
40347
40375
  current = current.clone().add(1, "day");
@@ -40349,27 +40377,25 @@ var MomentUtils = /** @class */ (function () {
40349
40377
  }
40350
40378
  return nestedWeeks;
40351
40379
  };
40352
- this.getYearRange = function (start, end) {
40353
- var startDate = _this.moment(start).startOf("year");
40354
- var endDate = _this.moment(end).endOf("year");
40355
- var years = [];
40356
- var current = startDate;
40380
+ this.getYearRange = (start, end) => {
40381
+ const startDate = this.moment(start).startOf("year");
40382
+ const endDate = this.moment(end).endOf("year");
40383
+ const years = [];
40384
+ let current = startDate;
40357
40385
  while (current.isBefore(endDate)) {
40358
40386
  years.push(current);
40359
40387
  current = current.clone().add(1, "year");
40360
40388
  }
40361
40389
  return years;
40362
40390
  };
40363
- this.isWithinRange = function (date, _a) {
40364
- var start = _a[0], end = _a[1];
40391
+ this.isWithinRange = (date, [start, end]) => {
40365
40392
  return date.isBetween(start, end, null, "[]");
40366
40393
  };
40367
40394
  this.moment = instance || defaultMoment;
40368
40395
  this.locale = locale;
40369
40396
  this.formats = Object.assign({}, defaultFormats, formats);
40370
40397
  }
40371
- return MomentUtils;
40372
- }());
40398
+ }
40373
40399
 
40374
40400
  /* eslint-disable class-methods-use-this */
40375
40401
  // From https://momentjs.com/docs/#/displaying/format/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/form-fields",
3
- "version": "6.0.3",
3
+ "version": "6.1.0",
4
4
  "description": "GeoWeb form-fields library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -14,7 +14,7 @@
14
14
  "peerDependencies": {
15
15
  "@mui/material": "5.12.0",
16
16
  "@mui/x-date-pickers": "6.2.1",
17
- "@opengeoweb/theme": "6.0.3",
17
+ "@opengeoweb/theme": "6.1.0",
18
18
  "lodash": "4.17.21",
19
19
  "moment": "2.29.4",
20
20
  "moment-timezone": "0.5.43",