formiojs-eorion 0.1.60 → 0.1.62
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/Formio.js +1 -1
- package/components/builder.js +2 -0
- package/components/datetimeRange/DateTimeRange.form.js +42 -0
- package/components/datetimeRange/DateTimeRange.js +258 -0
- package/components/datetimeRange/editForm/DateTimeRange.edit.data.js +36 -0
- package/components/datetimeRange/editForm/DateTimeRange.edit.date.js +67 -0
- package/components/datetimeRange/editForm/DateTimeRange.edit.display.js +105 -0
- package/components/datetimeRange/editForm/DateTimeRange.edit.time.js +35 -0
- package/components/datetimeRange/editForm/DateTimeRange.edit.validation.js +89 -0
- package/components/index.js +2 -0
- package/dist/formio.contrib.js +13 -2
- package/dist/formio.contrib.min.js +1 -1
- package/dist/formio.contrib.min.js.LICENSE.txt +1 -1
- package/dist/formio.embed.min.js.LICENSE.txt +1 -1
- package/dist/formio.form.js +92 -4
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.form.min.js.LICENSE.txt +1 -1
- package/dist/formio.full.js +92 -4
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.full.min.js.LICENSE.txt +1 -1
- package/dist/formio.js +1 -1
- package/dist/formio.min.js +1 -1
- package/dist/formio.min.js.LICENSE.txt +1 -1
- package/dist/formio.utils.min.js.LICENSE.txt +1 -1
- package/package.json +1 -1
- package/widgets/CalendarRangeWidget.js +628 -0
- package/widgets/index.js +3 -1
package/package.json
CHANGED
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
require("core-js/modules/es.symbol.js");
|
|
5
|
+
require("core-js/modules/es.symbol.description.js");
|
|
6
|
+
require("core-js/modules/es.symbol.iterator.js");
|
|
7
|
+
require("core-js/modules/es.symbol.to-primitive.js");
|
|
8
|
+
require("core-js/modules/es.array.iterator.js");
|
|
9
|
+
require("core-js/modules/es.date.to-primitive.js");
|
|
10
|
+
require("core-js/modules/es.number.constructor.js");
|
|
11
|
+
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
12
|
+
require("core-js/modules/es.object.get-own-property-descriptors.js");
|
|
13
|
+
require("core-js/modules/es.object.get-prototype-of.js");
|
|
14
|
+
require("core-js/modules/es.object.keys.js");
|
|
15
|
+
require("core-js/modules/es.reflect.construct.js");
|
|
16
|
+
require("core-js/modules/es.reflect.get.js");
|
|
17
|
+
require("core-js/modules/es.reflect.set.js");
|
|
18
|
+
require("core-js/modules/es.string.iterator.js");
|
|
19
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
20
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
21
|
+
Object.defineProperty(exports, "__esModule", {
|
|
22
|
+
value: true
|
|
23
|
+
});
|
|
24
|
+
exports.default = void 0;
|
|
25
|
+
require("core-js/modules/es.array.concat.js");
|
|
26
|
+
require("core-js/modules/es.array.filter.js");
|
|
27
|
+
require("core-js/modules/es.array.find.js");
|
|
28
|
+
require("core-js/modules/es.array.find-index.js");
|
|
29
|
+
require("core-js/modules/es.array.includes.js");
|
|
30
|
+
require("core-js/modules/es.array.map.js");
|
|
31
|
+
require("core-js/modules/es.object.to-string.js");
|
|
32
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
33
|
+
require("core-js/modules/es.regexp.to-string.js");
|
|
34
|
+
require("core-js/modules/es.string.includes.js");
|
|
35
|
+
require("core-js/modules/es.string.match.js");
|
|
36
|
+
require("core-js/modules/es.string.replace.js");
|
|
37
|
+
require("core-js/modules/es.string.split.js");
|
|
38
|
+
require("core-js/modules/es.string.trim.js");
|
|
39
|
+
var _Formio = require("../Formio");
|
|
40
|
+
var _InputWidget2 = _interopRequireDefault(require("./InputWidget"));
|
|
41
|
+
var _utils = require("../utils/utils");
|
|
42
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
43
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
44
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
45
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
46
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
47
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
48
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
49
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
50
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
51
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
52
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
53
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
54
|
+
function _superPropSet(t, e, o, r, p, f) { return _set(_getPrototypeOf(f ? t.prototype : t), e, o, r, p); }
|
|
55
|
+
function set(e, r, t, o) { return set = "undefined" != typeof Reflect && Reflect.set ? Reflect.set : function (e, r, t, o) { var f, i = _superPropBase(e, r); if (i) { if ((f = Object.getOwnPropertyDescriptor(i, r)).set) return f.set.call(o, t), !0; if (!f.writable) return !1; } if (f = Object.getOwnPropertyDescriptor(o, r)) { if (!f.writable) return !1; f.value = t, Object.defineProperty(o, r, f); } else _defineProperty(o, r, t); return !0; }, set(e, r, t, o); }
|
|
56
|
+
function _set(e, r, t, o, f) { if (!set(e, r, t, o || e) && f) throw new TypeError("failed to set property"); return t; }
|
|
57
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
58
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
59
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
60
|
+
function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
61
|
+
function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); }
|
|
62
|
+
function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); return t; }
|
|
63
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
64
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
65
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
66
|
+
var DEFAULT_FORMAT = 'yyyy-MM-dd hh:mm a';
|
|
67
|
+
var ISO_8601_FORMAT = 'yyyy-MM-ddTHH:mm:ssZ';
|
|
68
|
+
var isIEBrowser = (0, _utils.getBrowserInfo)().ie;
|
|
69
|
+
var CalendarWidget = exports.default = /*#__PURE__*/function (_InputWidget) {
|
|
70
|
+
/* eslint-enable camelcase */
|
|
71
|
+
|
|
72
|
+
function CalendarWidget(settings, component, instance, index) {
|
|
73
|
+
var _this;
|
|
74
|
+
_classCallCheck(this, CalendarWidget);
|
|
75
|
+
_this = _callSuper(this, CalendarWidget, [settings, component, instance, index]);
|
|
76
|
+
// Change the format to map to the settings.
|
|
77
|
+
if (_this.settings.noCalendar) {
|
|
78
|
+
_this.settings.format = _this.settings.format.replace(/yyyy-MM-dd /g, '');
|
|
79
|
+
}
|
|
80
|
+
if (!_this.settings.enableTime) {
|
|
81
|
+
_this.settings.format = _this.settings.format.replace(/ hh:mm a$/g, '');
|
|
82
|
+
} else if (_this.settings.time_24hr) {
|
|
83
|
+
_this.settings.format = _this.settings.format.replace(/hh:mm a$/g, 'HH:mm');
|
|
84
|
+
}
|
|
85
|
+
_this.zoneLoading = false;
|
|
86
|
+
_this.timezonesUrl = "".concat(_Formio.GlobalFormio.cdn['moment-timezone'], "/data/packed/latest.json");
|
|
87
|
+
return _this;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Load the timezones.
|
|
92
|
+
*
|
|
93
|
+
* @return {boolean} TRUE if the zones are loading, FALSE otherwise.
|
|
94
|
+
*/
|
|
95
|
+
_inherits(CalendarWidget, _InputWidget);
|
|
96
|
+
return _createClass(CalendarWidget, [{
|
|
97
|
+
key: "loadZones",
|
|
98
|
+
value: function loadZones() {
|
|
99
|
+
var _this2 = this;
|
|
100
|
+
var timezone = this.timezone;
|
|
101
|
+
if (this.zoneLoading) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
if (!(0, _utils.zonesLoaded)() && (0, _utils.shouldLoadZones)(timezone)) {
|
|
105
|
+
this.zoneLoading = true;
|
|
106
|
+
(0, _utils.loadZones)(this.timezonesUrl, timezone).then(function () {
|
|
107
|
+
_this2.zoneLoading = false;
|
|
108
|
+
_this2.emit('redraw');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Return zones are loading.
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Zones are already loaded.
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}, {
|
|
119
|
+
key: "attach",
|
|
120
|
+
value: function attach(input) {
|
|
121
|
+
var _this3 = this,
|
|
122
|
+
_this$component$short;
|
|
123
|
+
var superAttach = _superPropGet(CalendarWidget, "attach", this, 3)([input]);
|
|
124
|
+
var dateFormatInfo = (0, _utils.getLocaleDateFormatInfo)(this.settings.language);
|
|
125
|
+
this.defaultFormat = {
|
|
126
|
+
date: dateFormatInfo.dayFirst ? 'd/m/Y ' : 'm/d/Y ',
|
|
127
|
+
time: 'G:i K'
|
|
128
|
+
};
|
|
129
|
+
this.closedOn = 0;
|
|
130
|
+
this.valueFormat = this.settings.saveAs === 'date' ? ISO_8601_FORMAT : this.settings.dateFormat || ISO_8601_FORMAT;
|
|
131
|
+
this.valueMomentFormat = (0, _utils.convertFormatToMoment)(this.valueFormat);
|
|
132
|
+
var isReadOnly = this.settings.readOnly;
|
|
133
|
+
this.settings.minDate = isReadOnly ? null : (0, _utils.getDateSetting)(this.settings.minDate);
|
|
134
|
+
this.settings.maxDate = isReadOnly ? null : (0, _utils.getDateSetting)(this.settings.maxDate);
|
|
135
|
+
this.settings.disable = this.disabledDates;
|
|
136
|
+
this.settings.disableWeekends ? this.settings.disable.push(this.disableWeekends) : '';
|
|
137
|
+
this.settings.disableWeekdays ? this.settings.disable.push(this.disableWeekdays) : '';
|
|
138
|
+
this.settings.disableFunction ? this.settings.disable.push(this.disableFunction) : '';
|
|
139
|
+
this.settings.wasDefaultValueChanged = false;
|
|
140
|
+
this.settings.defaultValue = '';
|
|
141
|
+
this.settings.manualInputValue = '';
|
|
142
|
+
this.settings.isManuallyOverriddenValue = false;
|
|
143
|
+
this.settings.currentValue = '';
|
|
144
|
+
this.settings.altFormat = (0, _utils.convertFormatToFlatpickr)(this.settings.format);
|
|
145
|
+
this.settings.dateFormat = (0, _utils.convertFormatToFlatpickr)(this.settings.dateFormat);
|
|
146
|
+
this.settings.position = 'auto center';
|
|
147
|
+
this.settings.onChange = function () {
|
|
148
|
+
if (_this3.settings.allowInput) {
|
|
149
|
+
if (_this3.settings.isManuallyOverriddenValue && _this3.settings.enableTime) {
|
|
150
|
+
_this3.calendar._input.value = _this3.settings.manualInputValue;
|
|
151
|
+
} else {
|
|
152
|
+
_this3.settings.manualInputValue = '';
|
|
153
|
+
}
|
|
154
|
+
_this3.settings.isManuallyOverriddenValue = false;
|
|
155
|
+
}
|
|
156
|
+
_this3.emit('update');
|
|
157
|
+
};
|
|
158
|
+
this.settings.onOpen = function () {
|
|
159
|
+
return _this3.hook('onCalendarOpen');
|
|
160
|
+
};
|
|
161
|
+
this.settings.onClose = function () {
|
|
162
|
+
_this3.hook('onCalendarClose');
|
|
163
|
+
_this3.closedOn = Date.now();
|
|
164
|
+
if (_this3.settings.allowInput && _this3.settings.enableTime) {
|
|
165
|
+
_this3.calendar._input.value = _this3.settings.manualInputValue || _this3.calendar._input.value;
|
|
166
|
+
_this3.settings.isManuallyOverriddenValue = false;
|
|
167
|
+
_this3.emit('update');
|
|
168
|
+
}
|
|
169
|
+
if (_this3.settings.wasDefaultValueChanged) {
|
|
170
|
+
_this3.calendar._input.value = _this3.settings.defaultValue;
|
|
171
|
+
_this3.settings.wasDefaultValueChanged = false;
|
|
172
|
+
}
|
|
173
|
+
if (_this3.calendar) {
|
|
174
|
+
_this3.emit('blur');
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
_Formio.GlobalFormio.requireLibrary('flatpickr-css', 'flatpickr', [{
|
|
178
|
+
type: 'styles',
|
|
179
|
+
src: "".concat(_Formio.GlobalFormio.cdn['flatpickr-formio'], "/flatpickr.min.css")
|
|
180
|
+
}], true);
|
|
181
|
+
if (this.component.shortcutButtons) {
|
|
182
|
+
this.component.shortcutButtons = this.component.shortcutButtons.filter(function (btn) {
|
|
183
|
+
return btn.label && btn.onClick;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if ((_this$component$short = this.component.shortcutButtons) !== null && _this$component$short !== void 0 && _this$component$short.length) {
|
|
187
|
+
_Formio.GlobalFormio.requireLibrary('shortcut-buttons-flatpickr-css', 'ShortcutButtonsPlugin', [{
|
|
188
|
+
type: 'styles',
|
|
189
|
+
src: "".concat(_Formio.GlobalFormio.cdn['shortcut-buttons-flatpickr'], "/themes/light.min.css")
|
|
190
|
+
}], true);
|
|
191
|
+
}
|
|
192
|
+
return superAttach.then(function () {
|
|
193
|
+
var _this3$component$shor;
|
|
194
|
+
if ((_this3$component$shor = _this3.component.shortcutButtons) !== null && _this3$component$shor !== void 0 && _this3$component$shor.length) {
|
|
195
|
+
return _Formio.GlobalFormio.requireLibrary('shortcut-buttons-flatpickr', 'ShortcutButtonsPlugin', "".concat(_Formio.GlobalFormio.cdn['shortcut-buttons-flatpickr'], "/shortcut-buttons-flatpickr.min.js"), true);
|
|
196
|
+
}
|
|
197
|
+
}).then(function (ShortcutButtonsPlugin) {
|
|
198
|
+
return _Formio.GlobalFormio.requireLibrary('flatpickr', 'flatpickr', "".concat(_Formio.GlobalFormio.cdn['flatpickr-formio'], "/flatpickr.min.js"), true).then(function (Flatpickr) {
|
|
199
|
+
var _this3$component$shor2;
|
|
200
|
+
if ((_this3$component$shor2 = _this3.component.shortcutButtons) !== null && _this3$component$shor2 !== void 0 && _this3$component$shor2.length && ShortcutButtonsPlugin) {
|
|
201
|
+
_this3.initShortcutButtonsPlugin(ShortcutButtonsPlugin);
|
|
202
|
+
}
|
|
203
|
+
_this3.settings.formatDate = _this3.getFlatpickrFormatDate(Flatpickr);
|
|
204
|
+
if (_this3._input) {
|
|
205
|
+
var locale = _this3.settings.locale;
|
|
206
|
+
if (locale && locale.length >= 2 && locale !== 'en') {
|
|
207
|
+
_Formio.GlobalFormio.requireLibrary("flatpickr-".concat(locale), "flatpickr-".concat(locale), "".concat(_Formio.GlobalFormio.cdn['flatpickr-formio'], "/l10n/flatpickr-").concat(locale, ".js"), true);
|
|
208
|
+
_Formio.GlobalFormio.libraryReady("flatpickr-".concat(locale)).then(function () {
|
|
209
|
+
return _this3.initFlatpickr(Flatpickr);
|
|
210
|
+
});
|
|
211
|
+
} else {
|
|
212
|
+
_this3.initFlatpickr(Flatpickr);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}).catch(function (err) {
|
|
217
|
+
console.warn(err);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}, {
|
|
221
|
+
key: "disableWeekends",
|
|
222
|
+
get: function get() {
|
|
223
|
+
return function (date) {
|
|
224
|
+
return date.getDay() === 0 || date.getDay() === 6;
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}, {
|
|
228
|
+
key: "disableWeekdays",
|
|
229
|
+
get: function get() {
|
|
230
|
+
var _this4 = this;
|
|
231
|
+
return function (date) {
|
|
232
|
+
return !_this4.disableWeekends(date);
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}, {
|
|
236
|
+
key: "disableFunction",
|
|
237
|
+
get: function get() {
|
|
238
|
+
var _this5 = this;
|
|
239
|
+
return function (date) {
|
|
240
|
+
return _this5.evaluate("return ".concat(_this5.settings.disableFunction), {
|
|
241
|
+
date: date
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}, {
|
|
246
|
+
key: "timezone",
|
|
247
|
+
get: function get() {
|
|
248
|
+
return this.componentInstance.getTimezone(this.settings);
|
|
249
|
+
}
|
|
250
|
+
}, {
|
|
251
|
+
key: "defaultSettings",
|
|
252
|
+
get: function get() {
|
|
253
|
+
return CalendarWidget.defaultSettings;
|
|
254
|
+
}
|
|
255
|
+
}, {
|
|
256
|
+
key: "addSuffix",
|
|
257
|
+
value: function addSuffix(suffix) {
|
|
258
|
+
var _this6 = this;
|
|
259
|
+
this.addEventListener(suffix, 'click', function () {
|
|
260
|
+
setTimeout(function () {
|
|
261
|
+
if (_this6.calendar) {
|
|
262
|
+
if (!_this6.calendar.isOpen && Date.now() - _this6.closedOn > 200) {
|
|
263
|
+
_this6.calendar.open();
|
|
264
|
+
} else if (_this6.calendar.isOpen) {
|
|
265
|
+
_this6.calendar.close();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}, 0);
|
|
269
|
+
});
|
|
270
|
+
return suffix;
|
|
271
|
+
}
|
|
272
|
+
}, {
|
|
273
|
+
key: "disabled",
|
|
274
|
+
set: function set(disabled) {
|
|
275
|
+
_superPropSet(CalendarWidget, "disabled", disabled, this, 1, 1);
|
|
276
|
+
if (this.calendar) {
|
|
277
|
+
if (disabled) {
|
|
278
|
+
this.calendar._input.setAttribute('disabled', 'disabled');
|
|
279
|
+
} else {
|
|
280
|
+
this.calendar._input.removeAttribute('disabled');
|
|
281
|
+
}
|
|
282
|
+
this.calendar.close();
|
|
283
|
+
this.calendar.redraw();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}, {
|
|
287
|
+
key: "input",
|
|
288
|
+
get: function get() {
|
|
289
|
+
return this.calendar ? this.calendar.altInput : null;
|
|
290
|
+
}
|
|
291
|
+
}, {
|
|
292
|
+
key: "disabledDates",
|
|
293
|
+
get: function get() {
|
|
294
|
+
if (this.settings.disabledDates) {
|
|
295
|
+
var disabledDates = this.settings.disabledDates.split(',');
|
|
296
|
+
return disabledDates.map(function (item) {
|
|
297
|
+
var dateMask = /\d{4}-\d{2}-\d{2}/g;
|
|
298
|
+
var dates = item.match(dateMask);
|
|
299
|
+
if (dates && dates.length) {
|
|
300
|
+
return dates.length === 1 ? item.match(dateMask)[0] : {
|
|
301
|
+
from: item.match(dateMask)[0],
|
|
302
|
+
to: item.match(dateMask)[1]
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
}, {
|
|
310
|
+
key: "localeFormat",
|
|
311
|
+
get: function get() {
|
|
312
|
+
var format = '';
|
|
313
|
+
if (this.settings.enableDate) {
|
|
314
|
+
format += this.defaultFormat.date;
|
|
315
|
+
}
|
|
316
|
+
if (this.settings.enableTime) {
|
|
317
|
+
format += this.defaultFormat.time;
|
|
318
|
+
}
|
|
319
|
+
return format;
|
|
320
|
+
}
|
|
321
|
+
}, {
|
|
322
|
+
key: "dateTimeFormat",
|
|
323
|
+
get: function get() {
|
|
324
|
+
return this.settings.useLocaleSettings ? this.localeFormat : (0, _utils.convertFormatToFlatpickr)(this.dateFormat);
|
|
325
|
+
}
|
|
326
|
+
}, {
|
|
327
|
+
key: "dateFormat",
|
|
328
|
+
get: function get() {
|
|
329
|
+
return _lodash.default.get(this.settings, 'format', DEFAULT_FORMAT);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Return the date value.
|
|
334
|
+
*
|
|
335
|
+
* @param date
|
|
336
|
+
* @param format
|
|
337
|
+
* @return {string}
|
|
338
|
+
*/
|
|
339
|
+
}, {
|
|
340
|
+
key: "getDateValue",
|
|
341
|
+
value: function getDateValue(date, format, useTimezone) {
|
|
342
|
+
if (useTimezone) {
|
|
343
|
+
return (0, _utils.momentDate)(date, this.valueFormat, this.timezone).format((0, _utils.convertFormatToMoment)(format));
|
|
344
|
+
}
|
|
345
|
+
return (0, _moment.default)(date).format((0, _utils.convertFormatToMoment)(format));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Return the value of the selected date.
|
|
350
|
+
*
|
|
351
|
+
* @return {*}
|
|
352
|
+
*/
|
|
353
|
+
}, {
|
|
354
|
+
key: "getValue",
|
|
355
|
+
value: function getValue() {
|
|
356
|
+
var _this7 = this;
|
|
357
|
+
// Standard output format.
|
|
358
|
+
if (!this.calendar) {
|
|
359
|
+
return _superPropGet(CalendarWidget, "getValue", this, 3)([]);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Get the selected dates from the calendar widget.
|
|
363
|
+
var dates = this.calendar.selectedDates;
|
|
364
|
+
if (!dates || !dates.length) {
|
|
365
|
+
return _superPropGet(CalendarWidget, "getValue", this, 3)([]);
|
|
366
|
+
}
|
|
367
|
+
if (dates.findIndex(function (date) {
|
|
368
|
+
return !(date instanceof Date);
|
|
369
|
+
}) > -1) {
|
|
370
|
+
return 'Invalid Date';
|
|
371
|
+
}
|
|
372
|
+
return dates.map(function (date) {
|
|
373
|
+
return _this7.getDateValue(date, _this7.valueFormat, _this7.settings.saveAs === 'date');
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}, {
|
|
377
|
+
key: "isValueISO8601",
|
|
378
|
+
value: function isValueISO8601(value) {
|
|
379
|
+
return value && typeof value === 'string' && value.match(/-[0-9]{2}T[0-9]{2}:/);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Set the selected date value.
|
|
384
|
+
*
|
|
385
|
+
* @param value
|
|
386
|
+
*/
|
|
387
|
+
}, {
|
|
388
|
+
key: "setValue",
|
|
389
|
+
value: function setValue(value) {
|
|
390
|
+
var _this8 = this;
|
|
391
|
+
var saveAsText = this.settings.saveAs === 'text';
|
|
392
|
+
if (!this.calendar) {
|
|
393
|
+
value = value ? (0, _utils.formatDate)(this.timezonesUrl, value, (0, _utils.convertFormatToMoment)(this.settings.format), this.timezone, (0, _utils.convertFormatToMoment)(this.valueMomentFormat)) : value;
|
|
394
|
+
return _superPropGet(CalendarWidget, "setValue", this, 3)([value]);
|
|
395
|
+
}
|
|
396
|
+
var zonesLoading = this.loadZones();
|
|
397
|
+
if (value && value.length > 0) {
|
|
398
|
+
if (!saveAsText && this.settings.readOnly && !zonesLoading) {
|
|
399
|
+
this.calendar.setDate(value.map(function (date) {
|
|
400
|
+
return (0, _utils.momentDate)(date, _this8.valueFormat, _this8.timezone).format();
|
|
401
|
+
}), false);
|
|
402
|
+
} else if (this.isValueISO8601(value[0])) {
|
|
403
|
+
this.calendar.setDate(value, false);
|
|
404
|
+
} else {
|
|
405
|
+
this.calendar.setDate(value.map(function (date) {
|
|
406
|
+
return (0, _moment.default)(date, _this8.valueMomentFormat).toDate();
|
|
407
|
+
}), false);
|
|
408
|
+
}
|
|
409
|
+
} else {
|
|
410
|
+
this.calendar.clear(false);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}, {
|
|
414
|
+
key: "getValueAsString",
|
|
415
|
+
value: function getValueAsString(value, format) {
|
|
416
|
+
var inputFormat = format || this.dateFormat;
|
|
417
|
+
var valueFormat = this.calendar ? this.valueFormat : this.settings.dateFormat;
|
|
418
|
+
if (this.settings.saveAs === 'text' && this.componentInstance.parent && !this.settings.readOnly) {
|
|
419
|
+
return (0, _moment.default)(value, (0, _utils.convertFormatToMoment)(valueFormat)).format((0, _utils.convertFormatToMoment)(valueFormat));
|
|
420
|
+
}
|
|
421
|
+
return (0, _utils.formatDate)(this.timezonesUrl, value, inputFormat, this.timezone, (0, _utils.convertFormatToMoment)(valueFormat));
|
|
422
|
+
}
|
|
423
|
+
}, {
|
|
424
|
+
key: "setErrorClasses",
|
|
425
|
+
value: function setErrorClasses(hasErrors) {
|
|
426
|
+
if (!this.input) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (hasErrors) {
|
|
430
|
+
this.addClass(this.input, 'is-invalid');
|
|
431
|
+
this.input.setAttribute('aria-invalid', 'true');
|
|
432
|
+
} else {
|
|
433
|
+
this.removeClass(this.input, 'is-invalid');
|
|
434
|
+
this.input.setAttribute('aria-invalid', 'false');
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}, {
|
|
438
|
+
key: "validationValue",
|
|
439
|
+
value: function validationValue(value) {
|
|
440
|
+
if (typeof value === 'string') {
|
|
441
|
+
return new Date(value);
|
|
442
|
+
}
|
|
443
|
+
return value.map(function (val) {
|
|
444
|
+
return new Date(val);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}, {
|
|
448
|
+
key: "isCalendarElement",
|
|
449
|
+
value: function isCalendarElement(element) {
|
|
450
|
+
var _this$calendar, _this$calendar$config, _this$calendar$config2, _this$calendar2, _this$calendar2$calen;
|
|
451
|
+
if (!element) {
|
|
452
|
+
return true;
|
|
453
|
+
}
|
|
454
|
+
if ((_this$calendar = this.calendar) !== null && _this$calendar !== void 0 && (_this$calendar$config = _this$calendar.config) !== null && _this$calendar$config !== void 0 && (_this$calendar$config2 = _this$calendar$config.appendTo) !== null && _this$calendar$config2 !== void 0 && _this$calendar$config2.contains(element)) {
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
return (_this$calendar2 = this.calendar) === null || _this$calendar2 === void 0 ? void 0 : (_this$calendar2$calen = _this$calendar2.calendarContainer) === null || _this$calendar2$calen === void 0 ? void 0 : _this$calendar2$calen.contains(element);
|
|
458
|
+
}
|
|
459
|
+
}, {
|
|
460
|
+
key: "initFlatpickr",
|
|
461
|
+
value: function initFlatpickr(Flatpickr) {
|
|
462
|
+
var _this9 = this;
|
|
463
|
+
// Create a new flatpickr.
|
|
464
|
+
this.calendar = new Flatpickr(this._input, _objectSpread(_objectSpread({}, this.settings), {}, {
|
|
465
|
+
disableMobile: true
|
|
466
|
+
}));
|
|
467
|
+
this.calendar.altInput.addEventListener('input', function (event) {
|
|
468
|
+
if (_this9.settings.allowInput && _this9.settings.currentValue !== event.target.value) {
|
|
469
|
+
_this9.settings.manualInputValue = event.target.value;
|
|
470
|
+
_this9.settings.isManuallyOverriddenValue = true;
|
|
471
|
+
_this9.settings.currentValue = event.target.value;
|
|
472
|
+
}
|
|
473
|
+
if (event.target.value === '' && _this9.calendar.selectedDates.length > 0) {
|
|
474
|
+
_this9.settings.wasDefaultValueChanged = true;
|
|
475
|
+
_this9.settings.defaultValue = event.target.value;
|
|
476
|
+
_this9.calendar.clear();
|
|
477
|
+
} else {
|
|
478
|
+
_this9.settings.wasDefaultValueChanged = false;
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
var excludedFromMaskFormats = ['MMMM'];
|
|
482
|
+
if (!this.settings.readOnly && !_lodash.default.some(excludedFromMaskFormats, function (format) {
|
|
483
|
+
return _lodash.default.includes(_this9.settings.format, format);
|
|
484
|
+
})) {
|
|
485
|
+
// Enforce the input mask of the format.
|
|
486
|
+
this.setInputMask(this.calendar._input, (0, _utils.convertFormatToMask)(this.settings.format));
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// Fixes an issue with IE11 where value is set only after the second click
|
|
490
|
+
// TODO: Remove when the issue is solved in the flatpickr library
|
|
491
|
+
if (isIEBrowser) {
|
|
492
|
+
// Remove the original blur listener, because value will be set to empty since relatedTarget is null in IE11
|
|
493
|
+
var originalBlurListener = this.calendar._handlers.find(function (_ref) {
|
|
494
|
+
var event = _ref.event,
|
|
495
|
+
element = _ref.element;
|
|
496
|
+
return event === 'blur' && element === _this9.calendar._input;
|
|
497
|
+
});
|
|
498
|
+
this.calendar._input.removeEventListener('blur', originalBlurListener.handler);
|
|
499
|
+
// Add the same event listener as in the original library, but with workaround for IE11 issue
|
|
500
|
+
this.addEventListener(this.calendar._input, 'blur', function (event) {
|
|
501
|
+
var activeElement = _this9.settings.shadowRoot ? _this9.settings.shadowRoot.activeElement : document.activeElement;
|
|
502
|
+
var relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;
|
|
503
|
+
var isInput = event.target === _this9.calendar._input;
|
|
504
|
+
if (isInput && !_this9.isCalendarElement(relatedTarget)) {
|
|
505
|
+
_this9.calendar.setDate(_this9.calendar._input.value, true, event.target === _this9.calendar.altInput ? _this9.calendar.config.altFormat : _this9.calendar.config.dateFormat);
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
// Make sure we commit the value after a blur event occurs.
|
|
510
|
+
this.addEventListener(this.calendar._input, 'blur', function (event) {
|
|
511
|
+
var activeElement = _this9.settings.shadowRoot ? _this9.settings.shadowRoot.activeElement : document.activeElement;
|
|
512
|
+
var relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;
|
|
513
|
+
if (!(isIEBrowser && !relatedTarget) && !_this9.isCalendarElement(relatedTarget)) {
|
|
514
|
+
var _this9$calendar$l10n$;
|
|
515
|
+
var inputValue = _this9.calendar.input.value;
|
|
516
|
+
// 范围分割字符
|
|
517
|
+
var rangeSeparator = (_this9$calendar$l10n$ = _this9.calendar.l10n.rangeSeparator) !== null && _this9$calendar$l10n$ !== void 0 ? _this9$calendar$l10n$ : ' to ';
|
|
518
|
+
var dateValue = inputValue ? inputValue.split(rangeSeparator).map(function (value) {
|
|
519
|
+
return (0, _moment.default)(value.trim(), (0, _utils.convertFormatToMoment)(_this9.valueFormat)).toDate();
|
|
520
|
+
}) : [];
|
|
521
|
+
_this9.calendar.setDate(dateValue, true, _this9.settings.altFormat);
|
|
522
|
+
} else if (!_this9.calendar.input.value && _this9.calendar.config.noCalendar) {
|
|
523
|
+
var _this9$calendar, _this9$calendar$confi, _this9$calendar2, _this9$calendar2$conf;
|
|
524
|
+
var value = (0, _moment.default)({
|
|
525
|
+
hour: (_this9$calendar = _this9.calendar) === null || _this9$calendar === void 0 ? void 0 : (_this9$calendar$confi = _this9$calendar.config) === null || _this9$calendar$confi === void 0 ? void 0 : _this9$calendar$confi.defaultHour,
|
|
526
|
+
minute: (_this9$calendar2 = _this9.calendar) === null || _this9$calendar2 === void 0 ? void 0 : (_this9$calendar2$conf = _this9$calendar2.config) === null || _this9$calendar2$conf === void 0 ? void 0 : _this9$calendar2$conf.defaultMinute
|
|
527
|
+
}).toDate();
|
|
528
|
+
_this9.calendar.setDate([value], true, _this9.settings.format);
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
// FJS-1103: When hit the enter button, the field not saving the year correctly
|
|
533
|
+
this.addEventListener(this.calendar.altInput, 'keydown', function (event) {
|
|
534
|
+
if (event.keyCode === 13) {
|
|
535
|
+
if (_this9.calendar.isOpen) {
|
|
536
|
+
_this9.calendar.close();
|
|
537
|
+
event.stopPropagation();
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// Restore the calendar value from the component value.
|
|
543
|
+
this.setValue(this.componentValue);
|
|
544
|
+
}
|
|
545
|
+
}, {
|
|
546
|
+
key: "initShortcutButtonsPlugin",
|
|
547
|
+
value: function initShortcutButtonsPlugin(ShortcutButtonsPlugin) {
|
|
548
|
+
var _this10 = this;
|
|
549
|
+
this.settings.plugins = [
|
|
550
|
+
// eslint-disable-next-line new-cap
|
|
551
|
+
ShortcutButtonsPlugin({
|
|
552
|
+
button: this.component.shortcutButtons.map(function (btn) {
|
|
553
|
+
return {
|
|
554
|
+
label: btn.label,
|
|
555
|
+
attributes: btn.attribute
|
|
556
|
+
};
|
|
557
|
+
}),
|
|
558
|
+
onClick: function onClick(index) {
|
|
559
|
+
var getValue = _this10.component.shortcutButtons[index].onClick;
|
|
560
|
+
var date = _this10.evaluate(getValue, {
|
|
561
|
+
date: new Date()
|
|
562
|
+
}, 'date');
|
|
563
|
+
_this10.calendar.setDate(date, true);
|
|
564
|
+
}
|
|
565
|
+
})];
|
|
566
|
+
}
|
|
567
|
+
}, {
|
|
568
|
+
key: "componentValue",
|
|
569
|
+
get: function get() {
|
|
570
|
+
return this.componentInstance.dataValue;
|
|
571
|
+
}
|
|
572
|
+
}, {
|
|
573
|
+
key: "getFlatpickrFormatDate",
|
|
574
|
+
value: function getFlatpickrFormatDate(Flatpickr) {
|
|
575
|
+
var _this11 = this;
|
|
576
|
+
return function (date, format) {
|
|
577
|
+
// Only format this if this is the altFormat and the form is readOnly.
|
|
578
|
+
if (_this11.settings.readOnly && format === _this11.settings.altFormat) {
|
|
579
|
+
if (_this11.loadZones()) {
|
|
580
|
+
return Flatpickr.formatDate(date, format);
|
|
581
|
+
}
|
|
582
|
+
var currentValue = new Date(_this11.getValue());
|
|
583
|
+
if (currentValue.toString() === date.toString()) {
|
|
584
|
+
return (0, _utils.formatOffset)(_this11.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), new Date(_this11.componentValue), format, _this11.timezone);
|
|
585
|
+
}
|
|
586
|
+
return (0, _utils.formatOffset)(_this11.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), date, format, _this11.timezone);
|
|
587
|
+
}
|
|
588
|
+
return Flatpickr.formatDate(date, format);
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
}, {
|
|
592
|
+
key: "destroy",
|
|
593
|
+
value: function destroy() {
|
|
594
|
+
_superPropGet(CalendarWidget, "destroy", this, 3)([]);
|
|
595
|
+
if (this.calendar) {
|
|
596
|
+
this.calendar.destroy();
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}], [{
|
|
600
|
+
key: "defaultSettings",
|
|
601
|
+
get: /* eslint-disable camelcase */
|
|
602
|
+
function get() {
|
|
603
|
+
return {
|
|
604
|
+
type: 'calendarRange',
|
|
605
|
+
altInput: true,
|
|
606
|
+
allowInput: true,
|
|
607
|
+
clickOpens: true,
|
|
608
|
+
enableDate: true,
|
|
609
|
+
enableTime: true,
|
|
610
|
+
mode: 'range',
|
|
611
|
+
noCalendar: false,
|
|
612
|
+
format: DEFAULT_FORMAT,
|
|
613
|
+
dateFormat: ISO_8601_FORMAT,
|
|
614
|
+
useLocaleSettings: false,
|
|
615
|
+
language: 'us-en',
|
|
616
|
+
hourIncrement: 1,
|
|
617
|
+
minuteIncrement: 5,
|
|
618
|
+
time_24hr: false,
|
|
619
|
+
saveAs: 'date',
|
|
620
|
+
displayInTimezone: '',
|
|
621
|
+
timezone: '',
|
|
622
|
+
disable: [],
|
|
623
|
+
minDate: '',
|
|
624
|
+
maxDate: ''
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
}]);
|
|
628
|
+
}(_InputWidget2.default);
|
package/widgets/index.js
CHANGED
|
@@ -6,8 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _InputWidget = _interopRequireDefault(require("./InputWidget"));
|
|
8
8
|
var _CalendarWidget = _interopRequireDefault(require("./CalendarWidget"));
|
|
9
|
+
var _CalendarRangeWidget = _interopRequireDefault(require("./CalendarRangeWidget"));
|
|
9
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
11
|
var _default = exports.default = {
|
|
11
12
|
input: _InputWidget.default,
|
|
12
|
-
calendar: _CalendarWidget.default
|
|
13
|
+
calendar: _CalendarWidget.default,
|
|
14
|
+
calendarRange: _CalendarRangeWidget.default
|
|
13
15
|
};
|