150 lines
3.3 KiB
JavaScript
150 lines
3.3 KiB
JavaScript
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass } from '../_rollupPluginBabelHelpers-a0b34764.js';
|
|
import MaskElement from './mask-element.js';
|
|
import IMask from '../core/holder.js';
|
|
|
|
/** Bridge between HTMLElement and {@link Masked} */
|
|
|
|
var HTMLMaskElement = /*#__PURE__*/function (_MaskElement) {
|
|
_inherits(HTMLMaskElement, _MaskElement);
|
|
|
|
var _super = _createSuper(HTMLMaskElement);
|
|
|
|
/** Mapping between HTMLElement events and mask internal events */
|
|
|
|
/** HTMLElement to use mask on */
|
|
|
|
/**
|
|
@param {HTMLInputElement|HTMLTextAreaElement} input
|
|
*/
|
|
function HTMLMaskElement(input) {
|
|
var _this;
|
|
|
|
_classCallCheck(this, HTMLMaskElement);
|
|
|
|
_this = _super.call(this);
|
|
_this.input = input;
|
|
_this._handlers = {};
|
|
return _this;
|
|
}
|
|
/** */
|
|
// $FlowFixMe https://github.com/facebook/flow/issues/2839
|
|
|
|
|
|
_createClass(HTMLMaskElement, [{
|
|
key: "rootElement",
|
|
get: function get() {
|
|
return this.input.getRootNode ? this.input.getRootNode() : document;
|
|
}
|
|
/**
|
|
Is element in focus
|
|
@readonly
|
|
*/
|
|
|
|
}, {
|
|
key: "isActive",
|
|
get: function get() {
|
|
//$FlowFixMe
|
|
return this.input === this.rootElement.activeElement;
|
|
}
|
|
/**
|
|
Returns HTMLElement selection start
|
|
@override
|
|
*/
|
|
|
|
}, {
|
|
key: "_unsafeSelectionStart",
|
|
get: function get() {
|
|
return this.input.selectionStart;
|
|
}
|
|
/**
|
|
Returns HTMLElement selection end
|
|
@override
|
|
*/
|
|
|
|
}, {
|
|
key: "_unsafeSelectionEnd",
|
|
get: function get() {
|
|
return this.input.selectionEnd;
|
|
}
|
|
/**
|
|
Sets HTMLElement selection
|
|
@override
|
|
*/
|
|
|
|
}, {
|
|
key: "_unsafeSelect",
|
|
value: function _unsafeSelect(start, end) {
|
|
this.input.setSelectionRange(start, end);
|
|
}
|
|
/**
|
|
HTMLElement value
|
|
@override
|
|
*/
|
|
|
|
}, {
|
|
key: "value",
|
|
get: function get() {
|
|
return this.input.value;
|
|
},
|
|
set: function set(value) {
|
|
this.input.value = value;
|
|
}
|
|
/**
|
|
Binds HTMLElement events to mask internal events
|
|
@override
|
|
*/
|
|
|
|
}, {
|
|
key: "bindEvents",
|
|
value: function bindEvents(handlers) {
|
|
var _this2 = this;
|
|
|
|
Object.keys(handlers).forEach(function (event) {
|
|
return _this2._toggleEventHandler(HTMLMaskElement.EVENTS_MAP[event], handlers[event]);
|
|
});
|
|
}
|
|
/**
|
|
Unbinds HTMLElement events to mask internal events
|
|
@override
|
|
*/
|
|
|
|
}, {
|
|
key: "unbindEvents",
|
|
value: function unbindEvents() {
|
|
var _this3 = this;
|
|
|
|
Object.keys(this._handlers).forEach(function (event) {
|
|
return _this3._toggleEventHandler(event);
|
|
});
|
|
}
|
|
/** */
|
|
|
|
}, {
|
|
key: "_toggleEventHandler",
|
|
value: function _toggleEventHandler(event, handler) {
|
|
if (this._handlers[event]) {
|
|
this.input.removeEventListener(event, this._handlers[event]);
|
|
delete this._handlers[event];
|
|
}
|
|
|
|
if (handler) {
|
|
this.input.addEventListener(event, handler);
|
|
this._handlers[event] = handler;
|
|
}
|
|
}
|
|
}]);
|
|
|
|
return HTMLMaskElement;
|
|
}(MaskElement);
|
|
HTMLMaskElement.EVENTS_MAP = {
|
|
selectionChange: 'keydown',
|
|
input: 'input',
|
|
drop: 'drop',
|
|
click: 'click',
|
|
focus: 'focus',
|
|
commit: 'blur'
|
|
};
|
|
IMask.HTMLMaskElement = HTMLMaskElement;
|
|
|
|
export { HTMLMaskElement as default };
|