handsontable
Version:
Handsontable is a JavaScript Data Grid available for React, Angular and Vue.
76 lines (69 loc) • 2.04 kB
JavaScript
;
exports.__esModule = true;
var _textEditor = require("../textEditor");
var _dateTime = require("../../helpers/dateTime");
var _console = require("../../helpers/console");
var _templateLiteralTag = require("../../helpers/templateLiteralTag");
var _mixed = require("../../helpers/mixed");
const EDITOR_TYPE = exports.EDITOR_TYPE = 'intl-date';
/**
* @private
* @class IntlDateEditor
*/
class IntlDateEditor extends _textEditor.TextEditor {
static get EDITOR_TYPE() {
return EDITOR_TYPE;
}
init() {
super.init();
this.hot.addHook('afterSetTheme', (themeName, firstRun) => {
if (!firstRun) {
this.close();
}
});
}
/**
* Create data picker instance.
*/
createElements() {
super.createElements('input');
this.TEXTAREA.setAttribute('type', 'date');
}
/**
* Set the value of the editor.
*
* @param {*} value The value to set.
*/
setValue(value) {
if ((0, _mixed.isEmpty)(value)) {
value = this.cellProperties.defaultDate;
}
if (!(0, _dateTime.isValidISODate)(value)) {
(0, _console.warn)((0, _templateLiteralTag.toSingleLine)`IntlDateEditor: value must be in ISO date format ("YYYY-MM-DD")\x20
required by the native date input. Received:`, value);
return;
}
super.setValue(value);
}
/**
* Sets focus state on the select element.
*/
focus() {
// For IME editor textarea element must be focused using ".select" method.
// Using ".focus" browser automatically scroll into the focused element which
// is undesired effect.
this.TEXTAREA.select();
}
/**
* Open editor.
*/
open() {
super.open();
// Prevents "Failed to execute 'showPicker' on 'HTMLInputElement': HTMLInputElement::showPicker() requires a user gesture." errors
// when running tests or calling the method directly out of the event-loop cycle.
try {
this.TEXTAREA.showPicker();
} catch {} // eslint-disable-line no-empty
}
}
exports.IntlDateEditor = IntlDateEditor;