@formio/js 5.1.0-dev.6143.de7b851 → 5.1.0-dev.6145.1538310
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/dist/formio.form.js +2 -2
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.full.js +2 -2
- package/dist/formio.full.min.js +1 -1
- package/lib/cjs/components/datamap/DataMap.d.ts +1 -1
- package/lib/cjs/components/datamap/DataMap.js +4 -4
- package/lib/cjs/widgets/CalendarWidget.js +3 -1
- package/lib/mjs/components/datamap/DataMap.d.ts +1 -1
- package/lib/mjs/components/datamap/DataMap.js +1 -1
- package/lib/mjs/widgets/CalendarWidget.js +3 -1
- package/package.json +1 -1
package/dist/formio.form.js
CHANGED
@@ -5161,7 +5161,7 @@ eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5161
5161
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
5162
5162
|
|
5163
5163
|
"use strict";
|
5164
|
-
eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nconst Component_1 = __importDefault(__webpack_require__(/*! ../_classes/component/Component */ \"./lib/cjs/components/_classes/component/Component.js\"));\nconst DataGrid_1 = __importDefault(__webpack_require__(/*! ../datagrid/DataGrid */ \"./lib/cjs/components/datagrid/DataGrid.js\"));\nconst lodash_1 = __importDefault(__webpack_require__(/*! lodash */ \"./node_modules/lodash/lodash.js\"));\nconst eventemitter3_1 = __importDefault(__webpack_require__(/*! eventemitter3 */ \"./node_modules/eventemitter3/index.js\"));\nconst formUtils_1 = __webpack_require__(/*! ../../utils/formUtils */ \"./lib/cjs/utils/formUtils.js\");\nclass DataMapComponent extends DataGrid_1.default {\n static schema(...extend) {\n return Component_1.default.schema({\n label: 'Data Map',\n key: 'dataMap',\n type: 'datamap',\n clearOnHide: true,\n addAnother: 'Add Another',\n disableAddingRemovingRows: false,\n keyBeforeValue: true,\n valueComponent: {\n type: 'textfield',\n key: 'value',\n label: 'Value',\n input: true\n },\n input: true,\n validate: {\n maxLength: 0,\n minLength: 0\n }\n }, ...extend);\n }\n static get builderInfo() {\n return {\n title: 'Data Map',\n icon: 'th-list',\n group: 'data',\n documentation: '/userguide/form-building/data-components#data-map',\n showPreview: false,\n weight: 20,\n schema: DataMapComponent.schema()\n };\n }\n get schema() {\n const schema = super.schema;\n if (this.components && (this.components.length > 0)) {\n schema.valueComponent = this.components[this.components.length - 1].schema;\n }\n return lodash_1.default.omit(schema, 'components');\n }\n static savedValueTypes(schema) {\n return (0, formUtils_1.getComponentSavedTypes)(schema) || [formUtils_1.componentValueTypes.object];\n }\n constructor(component, options, data) {\n super(component, options, data);\n this.type = 'datamap';\n }\n init() {\n this.components = [];\n this.rows = [];\n this.createRows();\n this.visibleColumns = {\n key: true,\n [this.valueKey]: true\n };\n this.component.valueComponent.hideLabel = true;\n }\n get defaultSchema() {\n return DataMapComponent.schema();\n }\n get emptyValue() {\n return {};\n }\n get dataValue() {\n if (!this.key) {\n return this.emptyValue;\n }\n return lodash_1.default.get(this.data, this.key, this.emptyValue);\n }\n set dataValue(value) {\n super.dataValue = value;\n }\n get defaultValue() {\n const value = super.defaultValue;\n if (Array.isArray(value)) {\n return value[0];\n }\n return this.emptyValue;\n }\n get keySchema() {\n return {\n type: 'textfield',\n input: true,\n hideLabel: true,\n label: this.component.keyLabel || 'Key',\n key: '__key',\n disableBuilderActions: true,\n };\n }\n get valueKey() {\n return this.component.valueComponent.key;\n }\n getRowValues() {\n const dataValue = this.dataValue;\n if (this.builderMode) {\n return [dataValue];\n }\n if (lodash_1.default.isEmpty(dataValue)) {\n return [];\n }\n return Object.keys(dataValue).map(() => dataValue);\n }\n getComponentsContainer() {\n if (this.builderMode) {\n return this.getComponents().map(comp => comp.component);\n }\n return super.getComponentsContainer();\n }\n get iteratableRows() {\n return this.rows.map((row) => {\n return Object.keys(row).map(key => ({\n components: row[key],\n data: row[key].dataValue,\n }));\n });\n }\n componentContext(component) {\n return this.iteratableRows[component.row].find(comp => comp.components.key === component.key).data;\n }\n hasHeader() {\n return true;\n }\n hasRemoveButtons() {\n return !this.component.disableAddingRemovingRows &&\n !this.options.readOnly &&\n !this.disabled &&\n this.fullMode;\n }\n getColumns() {\n const keySchema = Object.assign({}, this.keySchema);\n const valueSchema = Object.assign({}, this.component.valueComponent);\n keySchema.hideLabel = false;\n valueSchema.hideLabel = false;\n return this.component.keyBeforeValue ?\n [keySchema, valueSchema] :\n [valueSchema, keySchema];\n }\n getRowKey(rowIndex) {\n const keys = Object.keys(this.dataValue);\n if (!keys[rowIndex]) {\n keys[rowIndex] = (0, formUtils_1.uniqueKey)(this.dataValue, this.defaultRowKey);\n }\n return keys[rowIndex];\n }\n get defaultRowKey() {\n return 'key';\n }\n setRowComponentsData(rowIndex, rowData) {\n lodash_1.default.each(this.rows[rowIndex], (component) => {\n if (component.key === '__key') {\n component.data = {\n '__key': Object.keys(rowData)[rowIndex],\n };\n }\n else {\n component.data = rowData;\n }\n });\n }\n getValueAsString(value, options) {\n if ((options === null || options === void 0 ? void 0 : options.email) && this.visible && !this.skipInEmail && lodash_1.default.isObject(value)) {\n let result = (`\n <table border=\"1\" style=\"width:100%\">\n <tbody>\n `);\n result = Object.keys(value).reduce((result, key) => {\n result += (`\n <tr>\n <th style=\"padding: 5px 10px;\">${key}</th>\n <td style=\"width:100%;padding:5px 10px;\">${this.getView(value[key], options)}</td>\n </tr>\n `);\n return result;\n }, result);\n result += (`\n </tbody>\n </table>\n `);\n return result;\n }\n if (lodash_1.default.isEmpty(value)) {\n return '';\n }\n if (options === null || options === void 0 ? void 0 : options.modalPreview) {\n delete options.modalPreview;\n return this.getDataValueAsTable(value, options);\n }\n return typeof value === 'object' ? '[Complex Data]' : value;\n }\n getDataValueAsTable(value, options) {\n let result = (`\n <table border=\"1\" style=\"width:100%\">\n <tbody>\n `);\n if (this.visible && lodash_1.default.isObject(value)) {\n Object.keys(value).forEach((key) => {\n result += (`\n <tr>\n <th style=\"padding: 5px 10px;\">${key}</th>\n <td style=\"width:100%;padding:5px 10px;\">${this.getView(value[key], options)}</td>\n </tr>\n `);\n });\n }\n result += (`\n </tbody>\n </table>\n `);\n return result;\n }\n createRowComponents(row, rowIndex) {\n // Use original value component API key in builder mode to be able to edit value component\n let key = this.builderMode ? this.valueKey : this.getRowKey(rowIndex);\n // Create a new event emitter since fields are isolated.\n const options = lodash_1.default.clone(this.options);\n options.events = new eventemitter3_1.default();\n options.name += `[${rowIndex}]`;\n options.row = `${rowIndex}`;\n options.rowIndex = rowIndex;\n const components = {};\n components['__key'] = this.createComponent(this.keySchema, options, { __key: this.builderMode ? this.defaultRowKey : key });\n components['__key'].on('componentChange', (event) => {\n const dataValue = this.dataValue;\n const newKey = (0, formUtils_1.uniqueKey)(dataValue, event.value);\n dataValue[newKey] = dataValue[key];\n delete dataValue[key];\n const comp = components[this.valueKey];\n comp.component.key = newKey;\n key = newKey;\n });\n const valueComponent = lodash_1.default.clone(this.component.valueComponent);\n valueComponent.key = key;\n const componentOptions = this.options;\n componentOptions.row = options.row;\n components[this.valueKey] = this.createComponent(valueComponent, componentOptions, this.dataValue);\n return components;\n }\n get canAddColumn() {\n return false;\n }\n addChildComponent(component) {\n this.component.valueComponent = component;\n }\n saveChildComponent(component) {\n // Update the Value Component, the Key Component is not allowed to edit\n if (component.key !== this.keySchema.key) {\n this.component.valueComponent = component;\n }\n }\n removeChildComponent() {\n const defaultSchema = DataMapComponent.schema();\n this.component.valueComponent = defaultSchema.valueComponent;\n }\n addRow() {\n const index = this.rows.length;\n this.rows[index] = this.createRowComponents(this.dataValue, index);\n this.redraw();\n this.triggerChange();\n }\n removeRow(index) {\n const keys = Object.keys(this.dataValue);\n if (keys[index]) {\n delete this.dataValue[keys[index]];\n }\n this.rows.splice(index, 1);\n this.redraw();\n this.triggerChange();\n }\n setValue(value, flags = {}) {\n const changed = this.hasChanged(value, this.dataValue);\n this.dataValue = value;\n this.createRows();\n this.updateOnChange(flags, changed);\n return changed;\n }\n checkColumns() {\n if (this.builderMode || (!this.dataValue || !Object.keys(this.dataValue).length)) {\n return { rebuild: false, show: true };\n }\n if (Object.keys(this.dataValue).length > (this.rows || []).length) {\n return { rebuild: true, show: true };\n }\n return { rebuild: false, show: true };\n }\n}\nexports[\"default\"] = DataMapComponent;\n\n\n//# sourceURL=webpack://Formio/./lib/cjs/components/datamap/DataMap.js?");
|
5164
|
+
eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nconst Component_1 = __importDefault(__webpack_require__(/*! ../_classes/component/Component */ \"./lib/cjs/components/_classes/component/Component.js\"));\nconst DataGrid_1 = __importDefault(__webpack_require__(/*! ../datagrid/DataGrid */ \"./lib/cjs/components/datagrid/DataGrid.js\"));\nconst lodash_1 = __importDefault(__webpack_require__(/*! lodash */ \"./node_modules/lodash/lodash.js\"));\nconst eventemitter3_1 = __importDefault(__webpack_require__(/*! eventemitter3 */ \"./node_modules/eventemitter3/index.js\"));\nconst utils_1 = __webpack_require__(/*! ../../utils/utils */ \"./lib/cjs/utils/utils.js\");\nclass DataMapComponent extends DataGrid_1.default {\n static schema(...extend) {\n return Component_1.default.schema({\n label: 'Data Map',\n key: 'dataMap',\n type: 'datamap',\n clearOnHide: true,\n addAnother: 'Add Another',\n disableAddingRemovingRows: false,\n keyBeforeValue: true,\n valueComponent: {\n type: 'textfield',\n key: 'value',\n label: 'Value',\n input: true\n },\n input: true,\n validate: {\n maxLength: 0,\n minLength: 0\n }\n }, ...extend);\n }\n static get builderInfo() {\n return {\n title: 'Data Map',\n icon: 'th-list',\n group: 'data',\n documentation: '/userguide/form-building/data-components#data-map',\n showPreview: false,\n weight: 20,\n schema: DataMapComponent.schema()\n };\n }\n get schema() {\n const schema = super.schema;\n if (this.components && (this.components.length > 0)) {\n schema.valueComponent = this.components[this.components.length - 1].schema;\n }\n return lodash_1.default.omit(schema, 'components');\n }\n static savedValueTypes(schema) {\n return (0, utils_1.getComponentSavedTypes)(schema) || [utils_1.componentValueTypes.object];\n }\n constructor(component, options, data) {\n super(component, options, data);\n this.type = 'datamap';\n }\n init() {\n this.components = [];\n this.rows = [];\n this.createRows();\n this.visibleColumns = {\n key: true,\n [this.valueKey]: true\n };\n this.component.valueComponent.hideLabel = true;\n }\n get defaultSchema() {\n return DataMapComponent.schema();\n }\n get emptyValue() {\n return {};\n }\n get dataValue() {\n if (!this.key) {\n return this.emptyValue;\n }\n return lodash_1.default.get(this.data, this.key, this.emptyValue);\n }\n set dataValue(value) {\n super.dataValue = value;\n }\n get defaultValue() {\n const value = super.defaultValue;\n if (Array.isArray(value)) {\n return value[0];\n }\n return this.emptyValue;\n }\n get keySchema() {\n return {\n type: 'textfield',\n input: true,\n hideLabel: true,\n label: this.component.keyLabel || 'Key',\n key: '__key',\n disableBuilderActions: true,\n };\n }\n get valueKey() {\n return this.component.valueComponent.key;\n }\n getRowValues() {\n const dataValue = this.dataValue;\n if (this.builderMode) {\n return [dataValue];\n }\n if (lodash_1.default.isEmpty(dataValue)) {\n return [];\n }\n return Object.keys(dataValue).map(() => dataValue);\n }\n getComponentsContainer() {\n if (this.builderMode) {\n return this.getComponents().map(comp => comp.component);\n }\n return super.getComponentsContainer();\n }\n get iteratableRows() {\n return this.rows.map((row) => {\n return Object.keys(row).map(key => ({\n components: row[key],\n data: row[key].dataValue,\n }));\n });\n }\n componentContext(component) {\n return this.iteratableRows[component.row].find(comp => comp.components.key === component.key).data;\n }\n hasHeader() {\n return true;\n }\n hasRemoveButtons() {\n return !this.component.disableAddingRemovingRows &&\n !this.options.readOnly &&\n !this.disabled &&\n this.fullMode;\n }\n getColumns() {\n const keySchema = Object.assign({}, this.keySchema);\n const valueSchema = Object.assign({}, this.component.valueComponent);\n keySchema.hideLabel = false;\n valueSchema.hideLabel = false;\n return this.component.keyBeforeValue ?\n [keySchema, valueSchema] :\n [valueSchema, keySchema];\n }\n getRowKey(rowIndex) {\n const keys = Object.keys(this.dataValue);\n if (!keys[rowIndex]) {\n keys[rowIndex] = (0, utils_1.uniqueKey)(this.dataValue, this.defaultRowKey);\n }\n return keys[rowIndex];\n }\n get defaultRowKey() {\n return 'key';\n }\n setRowComponentsData(rowIndex, rowData) {\n lodash_1.default.each(this.rows[rowIndex], (component) => {\n if (component.key === '__key') {\n component.data = {\n '__key': Object.keys(rowData)[rowIndex],\n };\n }\n else {\n component.data = rowData;\n }\n });\n }\n getValueAsString(value, options) {\n if ((options === null || options === void 0 ? void 0 : options.email) && this.visible && !this.skipInEmail && lodash_1.default.isObject(value)) {\n let result = (`\n <table border=\"1\" style=\"width:100%\">\n <tbody>\n `);\n result = Object.keys(value).reduce((result, key) => {\n result += (`\n <tr>\n <th style=\"padding: 5px 10px;\">${key}</th>\n <td style=\"width:100%;padding:5px 10px;\">${this.getView(value[key], options)}</td>\n </tr>\n `);\n return result;\n }, result);\n result += (`\n </tbody>\n </table>\n `);\n return result;\n }\n if (lodash_1.default.isEmpty(value)) {\n return '';\n }\n if (options === null || options === void 0 ? void 0 : options.modalPreview) {\n delete options.modalPreview;\n return this.getDataValueAsTable(value, options);\n }\n return typeof value === 'object' ? '[Complex Data]' : value;\n }\n getDataValueAsTable(value, options) {\n let result = (`\n <table border=\"1\" style=\"width:100%\">\n <tbody>\n `);\n if (this.visible && lodash_1.default.isObject(value)) {\n Object.keys(value).forEach((key) => {\n result += (`\n <tr>\n <th style=\"padding: 5px 10px;\">${key}</th>\n <td style=\"width:100%;padding:5px 10px;\">${this.getView(value[key], options)}</td>\n </tr>\n `);\n });\n }\n result += (`\n </tbody>\n </table>\n `);\n return result;\n }\n createRowComponents(row, rowIndex) {\n // Use original value component API key in builder mode to be able to edit value component\n let key = this.builderMode ? this.valueKey : this.getRowKey(rowIndex);\n // Create a new event emitter since fields are isolated.\n const options = lodash_1.default.clone(this.options);\n options.events = new eventemitter3_1.default();\n options.name += `[${rowIndex}]`;\n options.row = `${rowIndex}`;\n options.rowIndex = rowIndex;\n const components = {};\n components['__key'] = this.createComponent(this.keySchema, options, { __key: this.builderMode ? this.defaultRowKey : key });\n components['__key'].on('componentChange', (event) => {\n const dataValue = this.dataValue;\n const newKey = (0, utils_1.uniqueKey)(dataValue, event.value);\n dataValue[newKey] = dataValue[key];\n delete dataValue[key];\n const comp = components[this.valueKey];\n comp.component.key = newKey;\n key = newKey;\n });\n const valueComponent = lodash_1.default.clone(this.component.valueComponent);\n valueComponent.key = key;\n const componentOptions = this.options;\n componentOptions.row = options.row;\n components[this.valueKey] = this.createComponent(valueComponent, componentOptions, this.dataValue);\n return components;\n }\n get canAddColumn() {\n return false;\n }\n addChildComponent(component) {\n this.component.valueComponent = component;\n }\n saveChildComponent(component) {\n // Update the Value Component, the Key Component is not allowed to edit\n if (component.key !== this.keySchema.key) {\n this.component.valueComponent = component;\n }\n }\n removeChildComponent() {\n const defaultSchema = DataMapComponent.schema();\n this.component.valueComponent = defaultSchema.valueComponent;\n }\n addRow() {\n const index = this.rows.length;\n this.rows[index] = this.createRowComponents(this.dataValue, index);\n this.redraw();\n this.triggerChange();\n }\n removeRow(index) {\n const keys = Object.keys(this.dataValue);\n if (keys[index]) {\n delete this.dataValue[keys[index]];\n }\n this.rows.splice(index, 1);\n this.redraw();\n this.triggerChange();\n }\n setValue(value, flags = {}) {\n const changed = this.hasChanged(value, this.dataValue);\n this.dataValue = value;\n this.createRows();\n this.updateOnChange(flags, changed);\n return changed;\n }\n checkColumns() {\n if (this.builderMode || (!this.dataValue || !Object.keys(this.dataValue).length)) {\n return { rebuild: false, show: true };\n }\n if (Object.keys(this.dataValue).length > (this.rows || []).length) {\n return { rebuild: true, show: true };\n }\n return { rebuild: false, show: true };\n }\n}\nexports[\"default\"] = DataMapComponent;\n\n\n//# sourceURL=webpack://Formio/./lib/cjs/components/datamap/DataMap.js?");
|
5165
5165
|
|
5166
5166
|
/***/ }),
|
5167
5167
|
|
@@ -6107,7 +6107,7 @@ eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6107
6107
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
6108
6108
|
|
6109
6109
|
"use strict";
|
6110
|
-
eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nconst moment_1 = __importDefault(__webpack_require__(/*! moment */ \"./node_modules/moment/moment.js\"));\nconst lodash_1 = __importDefault(__webpack_require__(/*! lodash */ \"./node_modules/lodash/lodash.js\"));\nconst Formio_1 = __webpack_require__(/*! ../Formio */ \"./lib/cjs/Formio.js\");\nconst InputWidget_1 = __importDefault(__webpack_require__(/*! ./InputWidget */ \"./lib/cjs/widgets/InputWidget.js\"));\nconst utils_1 = __webpack_require__(/*! ../utils */ \"./lib/cjs/utils/index.js\");\nconst DEFAULT_FORMAT = 'yyyy-MM-dd hh:mm a';\nconst ISO_8601_FORMAT = 'yyyy-MM-ddTHH:mm:ssZ';\nconst isIEBrowser = (0, utils_1.getBrowserInfo)().ie;\nclass CalendarWidget extends InputWidget_1.default {\n /* eslint-disable camelcase */\n static get defaultSettings() {\n return {\n type: 'calendar',\n altInput: true,\n allowInput: true,\n clickOpens: true,\n enableDate: true,\n enableTime: true,\n mode: 'single',\n noCalendar: false,\n format: DEFAULT_FORMAT,\n dateFormat: ISO_8601_FORMAT,\n useLocaleSettings: false,\n language: 'us-en',\n hourIncrement: 1,\n minuteIncrement: 5,\n time_24hr: false,\n saveAs: 'date',\n displayInTimezone: '',\n timezone: '',\n disable: [],\n minDate: '',\n maxDate: ''\n };\n }\n /* eslint-enable camelcase */\n constructor(settings, component, instance, index) {\n super(settings, component, instance, index);\n // Change the format to map to the settings.\n if (this.settings.noCalendar) {\n this.settings.format = this.settings.format.replace(/yyyy-MM-dd /g, '');\n }\n if (!this.settings.enableTime) {\n this.settings.format = this.settings.format.replace(/ hh:mm a$/g, '');\n }\n else if (this.settings.time_24hr) {\n this.settings.format = this.settings.format.replace(/hh:mm a$/g, 'HH:mm');\n }\n }\n attach(input) {\n var _a;\n const superAttach = super.attach(input);\n const dateFormatInfo = (0, utils_1.getLocaleDateFormatInfo)(this.settings.language);\n this.defaultFormat = {\n date: dateFormatInfo.dayFirst ? 'd/m/Y ' : 'm/d/Y ',\n time: 'G:i K'\n };\n this.closedOn = 0;\n this.valueFormat = (this.settings.saveAs === 'date') ? ISO_8601_FORMAT : this.settings.dateFormat || ISO_8601_FORMAT;\n this.valueMomentFormat = (0, utils_1.convertFormatToDayjs)(this.valueFormat);\n const isReadOnly = this.settings.readOnly;\n this.settings.minDate = isReadOnly ? null : (0, utils_1.getDateSetting)(this.settings.minDate);\n this.settings.maxDate = isReadOnly ? null : (0, utils_1.getDateSetting)(this.settings.maxDate);\n this.settings.disable = this.disabledDates;\n this.settings.disableWeekends ? this.settings.disable.push(this.disableWeekends) : '';\n this.settings.disableWeekdays ? this.settings.disable.push(this.disableWeekdays) : '';\n this.settings.disableFunction ? this.settings.disable.push(this.disableFunction) : '';\n this.settings.manualInputValue = '';\n this.settings.isManuallyOverriddenValue = false;\n this.settings.currentValue = '';\n this.settings.altFormat = (0, utils_1.convertFormatToFlatpickr)(this.settings.format);\n this.settings.dateFormat = (0, utils_1.convertFormatToFlatpickr)(this.settings.dateFormat);\n this.settings.position = 'auto center';\n this.settings.onChange = () => {\n if (this.settings.allowInput && this.settings.enableTime) {\n this.calendar._input.value = this.settings.isManuallyOverriddenValue ? this.settings.manualInputValue : this.calendar.altInput.value;\n }\n this.emit('update');\n };\n this.settings.onOpen = () => this.hook('onCalendarOpen');\n this.settings.onClose = () => {\n this.hook('onCalendarClose');\n this.closedOn = Date.now();\n if (this.settings.allowInput && this.settings.enableTime) {\n this.calendar._input.value = this.settings.isManuallyOverriddenValue ? this.settings.manualInputValue : this.calendar.altInput.value;\n this.emit('update');\n }\n if (this.calendar) {\n this.emit('blur');\n }\n };\n Formio_1.Formio.requireLibrary('flatpickr-css', 'flatpickr', [\n { type: 'styles', src: `${Formio_1.Formio.cdn['flatpickr']}/flatpickr.min.css` }\n ], true);\n if (this.component.shortcutButtons) {\n this.component.shortcutButtons = this.component.shortcutButtons.filter((btn) => btn.label && btn.onClick);\n }\n if ((_a = this.component.shortcutButtons) === null || _a === void 0 ? void 0 : _a.length) {\n Formio_1.Formio.requireLibrary('shortcut-buttons-flatpickr-css', 'ShortcutButtonsPlugin', [\n { type: 'styles', src: `${Formio_1.Formio.cdn['shortcut-buttons-flatpickr']}/themes/light.min.css` }\n ], true);\n }\n return superAttach\n .then(() => {\n var _a;\n if ((_a = this.component.shortcutButtons) === null || _a === void 0 ? void 0 : _a.length) {\n return Formio_1.Formio.requireLibrary('shortcut-buttons-flatpickr', 'ShortcutButtonsPlugin', `${Formio_1.Formio.cdn['shortcut-buttons-flatpickr']}/shortcut-buttons-flatpickr.min.js`, true);\n }\n })\n .then((ShortcutButtonsPlugin) => {\n return Formio_1.Formio.requireLibrary('flatpickr', 'flatpickr', `${Formio_1.Formio.cdn['flatpickr']}/flatpickr.min.js`, true)\n .then((Flatpickr) => {\n var _a;\n if (((_a = this.component.shortcutButtons) === null || _a === void 0 ? void 0 : _a.length) && ShortcutButtonsPlugin) {\n this.initShortcutButtonsPlugin(ShortcutButtonsPlugin);\n }\n this.settings.formatDate = this.getFlatpickrFormatDate(Flatpickr);\n if (this._input) {\n const { locale } = this.settings;\n if (locale && locale.length >= 2 && locale !== 'en') {\n return Formio_1.Formio.requireLibrary(`flatpickr-${locale}`, `flatpickr.l10ns.${locale}`, `${Formio_1.Formio.cdn['flatpickr']}/l10n/${locale}.js`, true).then(() => this.initFlatpickr(Flatpickr));\n }\n else {\n this.initFlatpickr(Flatpickr);\n }\n }\n });\n })\n .catch((err) => {\n console.warn(err);\n });\n }\n get disableWeekends() {\n return function (date) {\n return (date.getDay() === 0 || date.getDay() === 6);\n };\n }\n get disableWeekdays() {\n return (date) => !this.disableWeekends(date);\n }\n get disableFunction() {\n return (date) => this.evaluate(`return ${this.settings.disableFunction}`, {\n date\n });\n }\n get timezone() {\n return this.componentInstance.getTimezone(this.settings);\n }\n get defaultSettings() {\n return CalendarWidget.defaultSettings;\n }\n addSuffix(suffix) {\n this.addEventListener(suffix, 'click', () => {\n setTimeout(() => {\n if (this.calendar) {\n if (!this.calendar.isOpen && ((Date.now() - this.closedOn) > 200)) {\n this.calendar.open();\n }\n else if (this.calendar.isOpen) {\n this.calendar.close();\n }\n }\n }, 0);\n });\n return suffix;\n }\n set disabled(disabled) {\n super.disabled = disabled;\n if (this.calendar) {\n if (disabled) {\n this.calendar._input.setAttribute('disabled', 'disabled');\n }\n else {\n this.calendar._input.removeAttribute('disabled');\n }\n this.calendar.close();\n this.calendar.redraw();\n }\n }\n get input() {\n return this.calendar ? this.calendar.altInput : null;\n }\n get disabledDates() {\n if (this.settings.disabledDates) {\n const disabledDates = this.settings.disabledDates.split(',');\n return disabledDates.map((item) => {\n const dateMask = /\\d{4}-\\d{2}-\\d{2}/g;\n const dates = item.match(dateMask);\n if (dates && dates.length) {\n return dates.length === 1 ? item.match(dateMask)[0] : {\n from: item.match(dateMask)[0],\n to: item.match(dateMask)[1],\n };\n }\n });\n }\n return [];\n }\n get localeFormat() {\n let format = '';\n if (this.settings.enableDate) {\n format += this.defaultFormat.date;\n }\n if (this.settings.enableTime) {\n format += this.defaultFormat.time;\n }\n return format;\n }\n get dateTimeFormat() {\n return this.settings.useLocaleSettings ? this.localeFormat : (0, utils_1.convertFormatToFlatpickr)(this.dateFormat);\n }\n get dateFormat() {\n return lodash_1.default.get(this.settings, 'format', DEFAULT_FORMAT);\n }\n /**\n * Return the date value as a string.\n * @param {string|Date} date - The date object or a date string that is momentjs compatible.\n * @param {string} format - The DateParser code format.\n * @param {boolean} [useTimezone] - If the timezone should be used.\n * @returns {string} - Returns the formatted date string.\n */\n getDateValue(date, format, useTimezone) {\n if (useTimezone) {\n return (0, utils_1.dayjsDate)(date, this.valueFormat, this.timezone).format((0, utils_1.convertFormatToDayjs)(format));\n }\n return (0, moment_1.default)(date).format((0, utils_1.convertFormatToDayjs)(format));\n }\n /**\n * Return the value of the selected date.\n * @returns {*} - The value of the selected date.\n */\n getValue() {\n // Standard output format.\n if (!this.calendar) {\n return super.getValue();\n }\n // Get the selected dates from the calendar widget.\n const dates = this.calendar.selectedDates;\n if (!dates || !dates.length) {\n return super.getValue();\n }\n if (!(dates[0] instanceof Date)) {\n return 'Invalid Date';\n }\n return this.getDateValue(dates[0], this.valueFormat, (this.settings.saveAs === 'date'));\n }\n isValueISO8601(value) {\n return value && (typeof value === 'string') && value.match(/-[0-9]{2}T[0-9]{2}:/);\n }\n /**\n * Set the selected date value.\n * @param {*} value - The value to set.\n * @returns {void}\n */\n setValue(value) {\n const saveAsText = (this.settings.saveAs === 'text');\n if (!this.calendar) {\n value = value ? (0, utils_1.formatDate)(value, (0, utils_1.convertFormatToDayjs)(this.settings.format), this.timezone, (0, utils_1.convertFormatToDayjs)(this.valueMomentFormat)) : value;\n return super.setValue(value);\n }\n // If the component is a textfield that does not have timezone information included in the string value then skip\n // the timezone offset\n this.settings.skipOffset = this.component.type === 'textfield' && !(0, utils_1.hasEncodedTimezone)(value);\n if (value) {\n if (!saveAsText && this.settings.readOnly) {\n this.calendar.setDate((0, utils_1.dayjsDate)(value, this.valueFormat, this.timezone).format(), false);\n }\n else if (this.isValueISO8601(value)) {\n this.calendar.setDate(value, false);\n }\n else {\n this.calendar.setDate((0, moment_1.default)(value, this.valueMomentFormat).toDate(), false);\n }\n }\n else {\n this.calendar.clear(false);\n }\n }\n getValueAsString(value, format) {\n const inputFormat = format || this.dateFormat;\n const valueFormat = this.calendar ? this.valueFormat : this.settings.dateFormat;\n if (this.settings.saveAs === 'text' && this.componentInstance.parent && !this.settings.readOnly) {\n return (0, moment_1.default)(value, (0, utils_1.convertFormatToDayjs)(valueFormat)).format((0, utils_1.convertFormatToDayjs)(valueFormat));\n }\n return (0, utils_1.formatDate)(value, inputFormat, this.timezone, (0, utils_1.convertFormatToDayjs)(valueFormat));\n }\n setErrorClasses(hasErrors) {\n if (!this.input) {\n return;\n }\n if (hasErrors) {\n this.addClass(this.input, 'is-invalid');\n this.input.setAttribute('aria-invalid', 'true');\n }\n else {\n this.removeClass(this.input, 'is-invalid');\n this.input.setAttribute('aria-invalid', 'false');\n }\n }\n get validationValue() {\n const value = this.dataValue;\n if (typeof value === 'string') {\n return new Date(value);\n }\n return value.map(val => new Date(val));\n }\n isCalendarElement(element) {\n var _a, _b, _c, _d, _e;\n if (!element) {\n return true;\n }\n if ((_c = (_b = (_a = this.calendar) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.appendTo) === null || _c === void 0 ? void 0 : _c.contains(element)) {\n return true;\n }\n return (_e = (_d = this.calendar) === null || _d === void 0 ? void 0 : _d.calendarContainer) === null || _e === void 0 ? void 0 : _e.contains(element);\n }\n initFlatpickr(Flatpickr) {\n // Create a new flatpickr.\n this.calendar = new Flatpickr(this._input, Object.assign(Object.assign({}, this.settings), { disableMobile: true }));\n this.addEventListener(this.calendar.altInput, 'input', (event) => {\n if (this.settings.allowInput && this.settings.currentValue !== event.target.value) {\n if (event.target.mask) {\n event.target.mask.textMaskInputElement.update();\n }\n this.settings.manualInputValue = event.target.value;\n this._input.value = this.settings.manualInputValue;\n this.settings.isManuallyOverriddenValue = true;\n this.settings.currentValue = event.target.value;\n this.emit('update');\n }\n });\n if (this.calendar.daysContainer) {\n this.calendar.daysContainer.addEventListener('click', () => {\n this.settings.isManuallyOverriddenValue = false;\n this.calendar.updateValue(false);\n });\n }\n if (this.calendar.timeContainer) {\n this.calendar.timeContainer.addEventListener('click', () => {\n this.settings.isManuallyOverriddenValue = false;\n this.calendar.updateValue(false);\n });\n }\n const excludedFromMaskFormats = ['MMMM'];\n if (!this.settings.readOnly && !lodash_1.default.some(excludedFromMaskFormats, format => lodash_1.default.includes(this.settings.format, format))) {\n // Enforce the input mask of the format.\n this.setInputMask(this.calendar._input, (0, utils_1.convertFormatToMask)(this.settings.format));\n }\n // Fixes an issue with IE11 where value is set only after the second click\n // TODO: Remove when the issue is solved in the flatpickr library\n if (isIEBrowser) {\n // Remove the original blur listener, because value will be set to empty since relatedTarget is null in IE11\n const originalBlurListener = this.calendar._handlers.find(({ event, element }) => event === 'blur' && element === this.calendar._input);\n this.calendar._input.removeEventListener('blur', originalBlurListener.handler);\n // Add the same event listener as in the original library, but with workaround for IE11 issue\n this.addEventListener(this.calendar._input, 'blur', (event) => {\n const activeElement = this.settings.shadowRoot ? this.settings.shadowRoot.activeElement : document.activeElement;\n const relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;\n const isInput = event.target === this.calendar._input;\n if (isInput && !this.isCalendarElement(relatedTarget)) {\n this.calendar.setDate(this.calendar._input.value, true, event.target === this.calendar.altInput\n ? this.calendar.config.altFormat\n : this.calendar.config.dateFormat);\n }\n });\n }\n // Make sure we commit the value after a blur event occurs.\n this.addEventListener(this.calendar._input, 'blur', (event) => {\n var _a, _b, _c, _d;\n // If we have manually overridden the value then we shouldn't call setDate because this will fill the input mask\n if (this.settings.isManuallyOverriddenValue) {\n return;\n }\n const activeElement = this.settings.shadowRoot ? this.settings.shadowRoot.activeElement : document.activeElement;\n const relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;\n if (!(isIEBrowser && !relatedTarget) && !this.isCalendarElement(relatedTarget)) {\n const inputValue = this.calendar.input.value;\n const dateValue = inputValue ? (0, moment_1.default)(this.calendar.input.value, (0, utils_1.convertFormatToDayjs)(this.valueFormat)).toDate() : inputValue;\n this.calendar.setDate(dateValue, true, this.settings.altFormat);\n }\n else if (!this.calendar.input.value && this.calendar.config.noCalendar) {\n const value = (0, moment_1.default)({ hour: (_b = (_a = this.calendar) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.defaultHour, minute: (_d = (_c = this.calendar) === null || _c === void 0 ? void 0 : _c.config) === null || _d === void 0 ? void 0 : _d.defaultMinute }).toDate();\n this.calendar.setDate(value, true, this.settings.format);\n }\n });\n // FJS-1103: When hit the enter button, the field not saving the year correctly\n this.addEventListener(this.calendar.altInput, 'keydown', (event) => {\n if (event.keyCode === 13) {\n if (this.calendar.isOpen) {\n this.calendar.close();\n event.stopPropagation();\n }\n }\n });\n // If other fields are used to calculate disabled dates, we need to redraw calendar to refresh disabled dates\n if (this.settings.disableFunction && this.componentInstance && this.componentInstance.root) {\n this.componentInstance.root.on('change', (e) => {\n if (e.changed && this.calendar) {\n this.calendar.redraw();\n }\n });\n }\n // Restore the calendar value from the component value.\n this.setValue(this.componentValue);\n }\n initShortcutButtonsPlugin(ShortcutButtonsPlugin) {\n this.settings.plugins = [\n // eslint-disable-next-line new-cap\n ShortcutButtonsPlugin({\n button: this.component.shortcutButtons.map((btn) => ({ label: btn.label, attributes: btn.attribute })),\n onClick: (index) => {\n const getValue = this.component.shortcutButtons[index].onClick;\n const date = this.evaluate(getValue, { date: new Date() }, 'date');\n this.calendar.setDate(date, true);\n }\n })\n ];\n }\n get componentValue() {\n let compValue = this.componentInstance.dataValue;\n if (Array.isArray(compValue)) {\n compValue = compValue[this.valueIndex];\n }\n return compValue;\n }\n getFlatpickrFormatDate(Flatpickr) {\n return (date, format) => {\n // Only format this if this is the altFormat and the form is readOnly.\n if (this.settings.readOnly && (format === this.settings.altFormat)) {\n if (!this.settings.enableTime || this.settings.skipOffset) {\n return Flatpickr.formatDate(date, format);\n }\n const currentValue = new Date(this.getValue());\n if (currentValue.toString() === date.toString()) {\n return (0, utils_1.formatOffset)(Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);\n }\n return (0, utils_1.formatOffset)(Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);\n }\n return Flatpickr.formatDate(date, format);\n };\n }\n destroy(all = false) {\n if (this.calendar) {\n this.calendar.destroy();\n }\n super.destroy(all);\n }\n}\nexports[\"default\"] = CalendarWidget;\n\n\n//# sourceURL=webpack://Formio/./lib/cjs/widgets/CalendarWidget.js?");
|
6110
|
+
eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nconst moment_1 = __importDefault(__webpack_require__(/*! moment */ \"./node_modules/moment/moment.js\"));\nconst lodash_1 = __importDefault(__webpack_require__(/*! lodash */ \"./node_modules/lodash/lodash.js\"));\nconst Formio_1 = __webpack_require__(/*! ../Formio */ \"./lib/cjs/Formio.js\");\nconst InputWidget_1 = __importDefault(__webpack_require__(/*! ./InputWidget */ \"./lib/cjs/widgets/InputWidget.js\"));\nconst utils_1 = __webpack_require__(/*! ../utils */ \"./lib/cjs/utils/index.js\");\nconst DEFAULT_FORMAT = 'yyyy-MM-dd hh:mm a';\nconst ISO_8601_FORMAT = 'yyyy-MM-ddTHH:mm:ssZ';\nconst isIEBrowser = (0, utils_1.getBrowserInfo)().ie;\nclass CalendarWidget extends InputWidget_1.default {\n /* eslint-disable camelcase */\n static get defaultSettings() {\n return {\n type: 'calendar',\n altInput: true,\n allowInput: true,\n clickOpens: true,\n enableDate: true,\n enableTime: true,\n mode: 'single',\n noCalendar: false,\n format: DEFAULT_FORMAT,\n dateFormat: ISO_8601_FORMAT,\n useLocaleSettings: false,\n language: 'us-en',\n hourIncrement: 1,\n minuteIncrement: 5,\n time_24hr: false,\n saveAs: 'date',\n displayInTimezone: '',\n timezone: '',\n disable: [],\n minDate: '',\n maxDate: ''\n };\n }\n /* eslint-enable camelcase */\n constructor(settings, component, instance, index) {\n super(settings, component, instance, index);\n // Change the format to map to the settings.\n if (this.settings.noCalendar) {\n this.settings.format = this.settings.format.replace(/yyyy-MM-dd /g, '');\n }\n if (!this.settings.enableTime) {\n this.settings.format = this.settings.format.replace(/ hh:mm a$/g, '');\n }\n else if (this.settings.time_24hr) {\n this.settings.format = this.settings.format.replace(/hh:mm a$/g, 'HH:mm');\n }\n }\n attach(input) {\n var _a;\n const superAttach = super.attach(input);\n const dateFormatInfo = (0, utils_1.getLocaleDateFormatInfo)(this.settings.language);\n this.defaultFormat = {\n date: dateFormatInfo.dayFirst ? 'd/m/Y ' : 'm/d/Y ',\n time: 'G:i K'\n };\n this.closedOn = 0;\n this.valueFormat = (this.settings.saveAs === 'date') ? ISO_8601_FORMAT : this.settings.dateFormat || ISO_8601_FORMAT;\n this.valueMomentFormat = (0, utils_1.convertFormatToDayjs)(this.valueFormat);\n const isReadOnly = this.settings.readOnly;\n this.settings.minDate = isReadOnly ? null : (0, utils_1.getDateSetting)(this.settings.minDate);\n this.settings.maxDate = isReadOnly ? null : (0, utils_1.getDateSetting)(this.settings.maxDate);\n this.settings.disable = this.disabledDates;\n this.settings.disableWeekends ? this.settings.disable.push(this.disableWeekends) : '';\n this.settings.disableWeekdays ? this.settings.disable.push(this.disableWeekdays) : '';\n this.settings.disableFunction ? this.settings.disable.push(this.disableFunction) : '';\n this.settings.manualInputValue = '';\n this.settings.isManuallyOverriddenValue = false;\n this.settings.currentValue = '';\n this.settings.altFormat = (0, utils_1.convertFormatToFlatpickr)(this.settings.format);\n this.settings.dateFormat = (0, utils_1.convertFormatToFlatpickr)(this.settings.dateFormat);\n this.settings.position = 'auto center';\n this.settings.onChange = () => {\n if (this.settings.allowInput && this.settings.enableTime) {\n this.calendar._input.value = this.settings.isManuallyOverriddenValue ? this.settings.manualInputValue : this.calendar.altInput.value;\n }\n this.emit('update');\n };\n this.settings.onOpen = () => this.hook('onCalendarOpen');\n this.settings.onClose = () => {\n this.hook('onCalendarClose');\n this.closedOn = Date.now();\n if (this.settings.allowInput && this.settings.enableTime) {\n this.calendar._input.value = this.settings.isManuallyOverriddenValue ? this.settings.manualInputValue : this.calendar.altInput.value;\n this.emit('update');\n }\n if (this.calendar) {\n this.emit('blur');\n }\n };\n Formio_1.Formio.requireLibrary('flatpickr-css', 'flatpickr', [\n { type: 'styles', src: `${Formio_1.Formio.cdn['flatpickr']}/flatpickr.min.css` }\n ], true);\n if (this.component.shortcutButtons) {\n this.component.shortcutButtons = this.component.shortcutButtons.filter((btn) => btn.label && btn.onClick);\n }\n if ((_a = this.component.shortcutButtons) === null || _a === void 0 ? void 0 : _a.length) {\n Formio_1.Formio.requireLibrary('shortcut-buttons-flatpickr-css', 'ShortcutButtonsPlugin', [\n { type: 'styles', src: `${Formio_1.Formio.cdn['shortcut-buttons-flatpickr']}/themes/light.min.css` }\n ], true);\n }\n return superAttach\n .then(() => {\n var _a;\n if ((_a = this.component.shortcutButtons) === null || _a === void 0 ? void 0 : _a.length) {\n return Formio_1.Formio.requireLibrary('shortcut-buttons-flatpickr', 'ShortcutButtonsPlugin', `${Formio_1.Formio.cdn['shortcut-buttons-flatpickr']}/shortcut-buttons-flatpickr.min.js`, true);\n }\n })\n .then((ShortcutButtonsPlugin) => {\n return Formio_1.Formio.requireLibrary('flatpickr', 'flatpickr', `${Formio_1.Formio.cdn['flatpickr']}/flatpickr.min.js`, true)\n .then((Flatpickr) => {\n var _a;\n if (((_a = this.component.shortcutButtons) === null || _a === void 0 ? void 0 : _a.length) && ShortcutButtonsPlugin) {\n this.initShortcutButtonsPlugin(ShortcutButtonsPlugin);\n }\n this.settings.formatDate = this.getFlatpickrFormatDate(Flatpickr);\n if (this._input) {\n const { locale } = this.settings;\n if (locale && locale.length >= 2 && locale !== 'en') {\n return Formio_1.Formio.requireLibrary(`flatpickr-${locale}`, `flatpickr.l10ns.${locale}`, `${Formio_1.Formio.cdn['flatpickr']}/l10n/${locale}.js`, true).then(() => this.initFlatpickr(Flatpickr));\n }\n else {\n this.initFlatpickr(Flatpickr);\n }\n }\n });\n })\n .catch((err) => {\n console.warn(err);\n });\n }\n get disableWeekends() {\n return function (date) {\n return (date.getDay() === 0 || date.getDay() === 6);\n };\n }\n get disableWeekdays() {\n return (date) => !this.disableWeekends(date);\n }\n get disableFunction() {\n return (date) => this.evaluate(`return ${this.settings.disableFunction}`, {\n date\n });\n }\n get timezone() {\n return this.componentInstance.getTimezone(this.settings);\n }\n get defaultSettings() {\n return CalendarWidget.defaultSettings;\n }\n addSuffix(suffix) {\n this.addEventListener(suffix, 'click', () => {\n setTimeout(() => {\n if (this.calendar) {\n if (!this.calendar.isOpen && ((Date.now() - this.closedOn) > 200)) {\n this.calendar.open();\n }\n else if (this.calendar.isOpen) {\n this.calendar.close();\n }\n }\n }, 0);\n });\n return suffix;\n }\n set disabled(disabled) {\n super.disabled = disabled;\n if (this.calendar) {\n if (disabled) {\n this.calendar._input.setAttribute('disabled', 'disabled');\n }\n else {\n this.calendar._input.removeAttribute('disabled');\n }\n this.calendar.close();\n this.calendar.redraw();\n }\n }\n get input() {\n return this.calendar ? this.calendar.altInput : null;\n }\n get disabledDates() {\n if (this.settings.disabledDates) {\n const disabledDates = this.settings.disabledDates.split(',');\n return disabledDates.map((item) => {\n const dateMask = /\\d{4}-\\d{2}-\\d{2}/g;\n const dates = item.match(dateMask);\n if (dates && dates.length) {\n return dates.length === 1 ? item.match(dateMask)[0] : {\n from: item.match(dateMask)[0],\n to: item.match(dateMask)[1],\n };\n }\n });\n }\n return [];\n }\n get localeFormat() {\n let format = '';\n if (this.settings.enableDate) {\n format += this.defaultFormat.date;\n }\n if (this.settings.enableTime) {\n format += this.defaultFormat.time;\n }\n return format;\n }\n get dateTimeFormat() {\n return this.settings.useLocaleSettings ? this.localeFormat : (0, utils_1.convertFormatToFlatpickr)(this.dateFormat);\n }\n get dateFormat() {\n return lodash_1.default.get(this.settings, 'format', DEFAULT_FORMAT);\n }\n /**\n * Return the date value as a string.\n * @param {string|Date} date - The date object or a date string that is momentjs compatible.\n * @param {string} format - The DateParser code format.\n * @param {boolean} [useTimezone] - If the timezone should be used.\n * @returns {string} - Returns the formatted date string.\n */\n getDateValue(date, format, useTimezone) {\n if (useTimezone) {\n return (0, utils_1.dayjsDate)(date, this.valueFormat, this.timezone).format((0, utils_1.convertFormatToDayjs)(format));\n }\n return (0, moment_1.default)(date).format((0, utils_1.convertFormatToDayjs)(format));\n }\n /**\n * Return the value of the selected date.\n * @returns {*} - The value of the selected date.\n */\n getValue() {\n // Standard output format.\n if (!this.calendar) {\n return super.getValue();\n }\n // Get the selected dates from the calendar widget.\n const dates = this.calendar.selectedDates;\n if (!dates || !dates.length) {\n return super.getValue();\n }\n if (!(dates[0] instanceof Date)) {\n return 'Invalid Date';\n }\n return this.getDateValue(dates[0], this.valueFormat, (this.settings.saveAs === 'date'));\n }\n isValueISO8601(value) {\n return value && (typeof value === 'string') && value.match(/-[0-9]{2}T[0-9]{2}:/);\n }\n /**\n * Set the selected date value.\n * @param {*} value - The value to set.\n * @returns {void}\n */\n setValue(value) {\n const saveAsText = (this.settings.saveAs === 'text');\n if (!this.calendar) {\n value = value ? (0, utils_1.formatDate)(value, (0, utils_1.convertFormatToDayjs)(this.settings.format), this.timezone, (0, utils_1.convertFormatToDayjs)(this.valueMomentFormat)) : value;\n return super.setValue(value);\n }\n // If the component is a textfield that does not have timezone information included in the string value then skip\n // the timezone offset\n if (this.component.type === 'textfield' && !(0, utils_1.hasEncodedTimezone)(value)) {\n this.settings.skipOffset = true;\n }\n if (value) {\n if (!saveAsText && this.settings.readOnly) {\n this.calendar.setDate((0, utils_1.dayjsDate)(value, this.valueFormat, this.timezone).format(), false);\n }\n else if (this.isValueISO8601(value)) {\n this.calendar.setDate(value, false);\n }\n else {\n this.calendar.setDate((0, moment_1.default)(value, this.valueMomentFormat).toDate(), false);\n }\n }\n else {\n this.calendar.clear(false);\n }\n }\n getValueAsString(value, format) {\n const inputFormat = format || this.dateFormat;\n const valueFormat = this.calendar ? this.valueFormat : this.settings.dateFormat;\n if (this.settings.saveAs === 'text' && this.componentInstance.parent && !this.settings.readOnly) {\n return (0, moment_1.default)(value, (0, utils_1.convertFormatToDayjs)(valueFormat)).format((0, utils_1.convertFormatToDayjs)(valueFormat));\n }\n return (0, utils_1.formatDate)(value, inputFormat, this.timezone, (0, utils_1.convertFormatToDayjs)(valueFormat));\n }\n setErrorClasses(hasErrors) {\n if (!this.input) {\n return;\n }\n if (hasErrors) {\n this.addClass(this.input, 'is-invalid');\n this.input.setAttribute('aria-invalid', 'true');\n }\n else {\n this.removeClass(this.input, 'is-invalid');\n this.input.setAttribute('aria-invalid', 'false');\n }\n }\n get validationValue() {\n const value = this.dataValue;\n if (typeof value === 'string') {\n return new Date(value);\n }\n return value.map(val => new Date(val));\n }\n isCalendarElement(element) {\n var _a, _b, _c, _d, _e;\n if (!element) {\n return true;\n }\n if ((_c = (_b = (_a = this.calendar) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.appendTo) === null || _c === void 0 ? void 0 : _c.contains(element)) {\n return true;\n }\n return (_e = (_d = this.calendar) === null || _d === void 0 ? void 0 : _d.calendarContainer) === null || _e === void 0 ? void 0 : _e.contains(element);\n }\n initFlatpickr(Flatpickr) {\n // Create a new flatpickr.\n this.calendar = new Flatpickr(this._input, Object.assign(Object.assign({}, this.settings), { disableMobile: true }));\n this.addEventListener(this.calendar.altInput, 'input', (event) => {\n if (this.settings.allowInput && this.settings.currentValue !== event.target.value) {\n if (event.target.mask) {\n event.target.mask.textMaskInputElement.update();\n }\n this.settings.manualInputValue = event.target.value;\n this._input.value = this.settings.manualInputValue;\n this.settings.isManuallyOverriddenValue = true;\n this.settings.currentValue = event.target.value;\n this.emit('update');\n }\n });\n if (this.calendar.daysContainer) {\n this.calendar.daysContainer.addEventListener('click', () => {\n this.settings.isManuallyOverriddenValue = false;\n this.calendar.updateValue(false);\n });\n }\n if (this.calendar.timeContainer) {\n this.calendar.timeContainer.addEventListener('click', () => {\n this.settings.isManuallyOverriddenValue = false;\n this.calendar.updateValue(false);\n });\n }\n const excludedFromMaskFormats = ['MMMM'];\n if (!this.settings.readOnly && !lodash_1.default.some(excludedFromMaskFormats, format => lodash_1.default.includes(this.settings.format, format))) {\n // Enforce the input mask of the format.\n this.setInputMask(this.calendar._input, (0, utils_1.convertFormatToMask)(this.settings.format));\n }\n // Fixes an issue with IE11 where value is set only after the second click\n // TODO: Remove when the issue is solved in the flatpickr library\n if (isIEBrowser) {\n // Remove the original blur listener, because value will be set to empty since relatedTarget is null in IE11\n const originalBlurListener = this.calendar._handlers.find(({ event, element }) => event === 'blur' && element === this.calendar._input);\n this.calendar._input.removeEventListener('blur', originalBlurListener.handler);\n // Add the same event listener as in the original library, but with workaround for IE11 issue\n this.addEventListener(this.calendar._input, 'blur', (event) => {\n const activeElement = this.settings.shadowRoot ? this.settings.shadowRoot.activeElement : document.activeElement;\n const relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;\n const isInput = event.target === this.calendar._input;\n if (isInput && !this.isCalendarElement(relatedTarget)) {\n this.calendar.setDate(this.calendar._input.value, true, event.target === this.calendar.altInput\n ? this.calendar.config.altFormat\n : this.calendar.config.dateFormat);\n }\n });\n }\n // Make sure we commit the value after a blur event occurs.\n this.addEventListener(this.calendar._input, 'blur', (event) => {\n var _a, _b, _c, _d;\n // If we have manually overridden the value then we shouldn't call setDate because this will fill the input mask\n if (this.settings.isManuallyOverriddenValue) {\n return;\n }\n const activeElement = this.settings.shadowRoot ? this.settings.shadowRoot.activeElement : document.activeElement;\n const relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;\n if (!(isIEBrowser && !relatedTarget) && !this.isCalendarElement(relatedTarget)) {\n const inputValue = this.calendar.input.value;\n const dateValue = inputValue ? (0, moment_1.default)(this.calendar.input.value, (0, utils_1.convertFormatToDayjs)(this.valueFormat)).toDate() : inputValue;\n this.calendar.setDate(dateValue, true, this.settings.altFormat);\n }\n else if (!this.calendar.input.value && this.calendar.config.noCalendar) {\n const value = (0, moment_1.default)({ hour: (_b = (_a = this.calendar) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.defaultHour, minute: (_d = (_c = this.calendar) === null || _c === void 0 ? void 0 : _c.config) === null || _d === void 0 ? void 0 : _d.defaultMinute }).toDate();\n this.calendar.setDate(value, true, this.settings.format);\n }\n });\n // FJS-1103: When hit the enter button, the field not saving the year correctly\n this.addEventListener(this.calendar.altInput, 'keydown', (event) => {\n if (event.keyCode === 13) {\n if (this.calendar.isOpen) {\n this.calendar.close();\n event.stopPropagation();\n }\n }\n });\n // If other fields are used to calculate disabled dates, we need to redraw calendar to refresh disabled dates\n if (this.settings.disableFunction && this.componentInstance && this.componentInstance.root) {\n this.componentInstance.root.on('change', (e) => {\n if (e.changed && this.calendar) {\n this.calendar.redraw();\n }\n });\n }\n // Restore the calendar value from the component value.\n this.setValue(this.componentValue);\n }\n initShortcutButtonsPlugin(ShortcutButtonsPlugin) {\n this.settings.plugins = [\n // eslint-disable-next-line new-cap\n ShortcutButtonsPlugin({\n button: this.component.shortcutButtons.map((btn) => ({ label: btn.label, attributes: btn.attribute })),\n onClick: (index) => {\n const getValue = this.component.shortcutButtons[index].onClick;\n const date = this.evaluate(getValue, { date: new Date() }, 'date');\n this.calendar.setDate(date, true);\n }\n })\n ];\n }\n get componentValue() {\n let compValue = this.componentInstance.dataValue;\n if (Array.isArray(compValue)) {\n compValue = compValue[this.valueIndex];\n }\n return compValue;\n }\n getFlatpickrFormatDate(Flatpickr) {\n return (date, format) => {\n // Only format this if this is the altFormat and the form is readOnly.\n if (this.settings.readOnly && (format === this.settings.altFormat)) {\n if (!this.settings.enableTime || this.settings.skipOffset) {\n return Flatpickr.formatDate(date, format);\n }\n const currentValue = new Date(this.getValue());\n if (currentValue.toString() === date.toString()) {\n return (0, utils_1.formatOffset)(Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);\n }\n return (0, utils_1.formatOffset)(Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);\n }\n return Flatpickr.formatDate(date, format);\n };\n }\n destroy(all = false) {\n if (this.calendar) {\n this.calendar.destroy();\n }\n super.destroy(all);\n }\n}\nexports[\"default\"] = CalendarWidget;\n\n\n//# sourceURL=webpack://Formio/./lib/cjs/widgets/CalendarWidget.js?");
|
6111
6111
|
|
6112
6112
|
/***/ }),
|
6113
6113
|
|