| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- /**
- * DevExtreme (ui/text_box/ui.text_editor.mask.strategy.base.js)
- * Version: 19.1.16
- * Build date: Tue Oct 18 2022
- *
- * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
- * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
- */
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _events_engine = require("../../events/core/events_engine");
- var _events_engine2 = _interopRequireDefault(_events_engine);
- var _utils = require("../../events/utils");
- var _browser = require("../../core/utils/browser");
- var _browser2 = _interopRequireDefault(_browser);
- var _array = require("../../core/utils/array");
- var _dom = require("../../core/utils/dom");
- function _interopRequireDefault(obj) {
- return obj && obj.__esModule ? obj : {
- "default": obj
- }
- }
- function _classCallCheck(instance, Constructor) {
- if (!(instance instanceof Constructor)) {
- throw new TypeError("Cannot call a class as a function")
- }
- }
- function _defineProperties(target, props) {
- for (var i = 0; i < props.length; i++) {
- var descriptor = props[i];
- descriptor.enumerable = descriptor.enumerable || false;
- descriptor.configurable = true;
- if ("value" in descriptor) {
- descriptor.writable = true
- }
- Object.defineProperty(target, descriptor.key, descriptor)
- }
- }
- function _createClass(Constructor, protoProps, staticProps) {
- if (protoProps) {
- _defineProperties(Constructor.prototype, protoProps)
- }
- if (staticProps) {
- _defineProperties(Constructor, staticProps)
- }
- Object.defineProperty(Constructor, "prototype", {
- writable: false
- });
- return Constructor
- }
- var MASK_EVENT_NAMESPACE = "dxMask";
- var BLUR_EVENT = "blur beforedeactivate";
- var EMPTY_CHAR = " ";
- var BaseMaskStrategy = function() {
- function BaseMaskStrategy(editor) {
- _classCallCheck(this, BaseMaskStrategy);
- this.editor = editor;
- this.DIRECTION = {
- FORWARD: "forward",
- BACKWARD: "backward"
- };
- this.NAME = this._getStrategyName()
- }
- _createClass(BaseMaskStrategy, [{
- key: "_getStrategyName",
- value: function() {
- return "base"
- }
- }, {
- key: "editorOption",
- value: function() {
- var _this$editor;
- return (_this$editor = this.editor).option.apply(_this$editor, arguments)
- }
- }, {
- key: "editorInput",
- value: function() {
- return this.editor._input()
- }
- }, {
- key: "editorCaret",
- value: function(newCaret) {
- if (!newCaret) {
- return this.editor._caret()
- }
- this.editor._caret(newCaret)
- }
- }, {
- key: "getHandler",
- value: function(handlerName) {
- var handler = this["_".concat(handlerName, "Handler")] || function() {};
- return handler.bind(this)
- }
- }, {
- key: "attachEvents",
- value: function() {
- var _this = this;
- var $input = this.editorInput();
- this.getHandleEventNames().forEach(function(eventName) {
- var subscriptionName = (0, _utils.addNamespace)(eventName.toLowerCase(), MASK_EVENT_NAMESPACE);
- _events_engine2.default.on($input, subscriptionName, _this.getEventHandler(eventName))
- });
- this._attachChangeEventHandlers()
- }
- }, {
- key: "getHandleEventNames",
- value: function() {
- return ["focusIn", "focusOut", "keyDown", "input", "paste", "cut", "drop"]
- }
- }, {
- key: "getEventHandler",
- value: function(eventName) {
- return this["_".concat(eventName, "Handler")].bind(this)
- }
- }, {
- key: "detachEvents",
- value: function() {
- _events_engine2.default.off(this.editorInput(), ".".concat(MASK_EVENT_NAMESPACE))
- }
- }, {
- key: "_attachChangeEventHandlers",
- value: function() {
- if ((0, _array.inArray)("change", this.editorOption("valueChangeEvent").split(" ")) === -1) {
- return
- }
- _events_engine2.default.on(this.editorInput(), (0, _utils.addNamespace)(BLUR_EVENT, MASK_EVENT_NAMESPACE), function(e) {
- this._suppressCaretChanging(this._changeHandler, [e]);
- this._changeHandler(e)
- }.bind(this.editor))
- }
- }, {
- key: "_focusInHandler",
- value: function() {
- this.editor._showMaskPlaceholder();
- this.editor._direction(this.DIRECTION.FORWARD);
- if (!this.editor._isValueEmpty() && this.editorOption("isValid")) {
- this.editor._adjustCaret()
- } else {
- var caret = this.editor._maskRulesChain.first();
- this._caretTimeout = setTimeout(function() {
- this._caret({
- start: caret,
- end: caret
- })
- }.bind(this.editor), 0)
- }
- }
- }, {
- key: "_focusOutHandler",
- value: function(event) {
- this.editor._changeHandler(event);
- if ("onFocus" === this.editorOption("showMaskMode") && this.editor._isValueEmpty()) {
- this.editorOption("text", "");
- this.editor._renderDisplayText("")
- }
- }
- }, {
- key: "_cutHandler",
- value: function(event) {
- var caret = this.editorCaret();
- var selectedText = this.editorInput().val().substring(caret.start, caret.end);
- this.editor._maskKeyHandler(event, function() {
- return (0, _dom.clipboardText)(event, selectedText)
- })
- }
- }, {
- key: "_dropHandler",
- value: function() {
- this._clearDragTimer();
- this._dragTimer = setTimeout(function() {
- this.option("value", this._convertToValue(this._input().val()))
- }.bind(this.editor))
- }
- }, {
- key: "_clearDragTimer",
- value: function() {
- clearTimeout(this._dragTimer)
- }
- }, {
- key: "_keyDownHandler",
- value: function() {
- this._keyPressHandled = false
- }
- }, {
- key: "_pasteHandler",
- value: function(event) {
- var editor = this.editor;
- this._keyPressHandled = true;
- var caret = this.editorCaret();
- editor._maskKeyHandler(event, function() {
- var pastedText = (0, _dom.clipboardText)(event);
- var restText = editor._maskRulesChain.text().substring(caret.end);
- var accepted = editor._handleChain({
- text: pastedText,
- start: caret.start,
- length: pastedText.length
- });
- var newCaret = caret.start + accepted;
- editor._handleChain({
- text: restText,
- start: newCaret,
- length: restText.length
- });
- editor._caret({
- start: newCaret,
- end: newCaret
- })
- })
- }
- }, {
- key: "_autoFillHandler",
- value: function(event) {
- var _this2 = this;
- var editor = this.editor;
- var inputVal = this.editorInput().val();
- this._inputHandlerTimer = setTimeout(function() {
- _this2._keyPressHandled = true;
- if (_this2._isAutoFill()) {
- _this2._keyPressHandled = true;
- editor._maskKeyHandler(event, function() {
- editor._handleChain({
- text: inputVal,
- start: 0,
- length: inputVal.length
- })
- });
- editor._validateMask()
- }
- })
- }
- }, {
- key: "_isAutoFill",
- value: function() {
- var $input = this.editor._input();
- var result = false;
- if (_browser2.default.msie && _browser2.default.version > 11) {
- result = $input.hasClass("edge-autofilled")
- } else {
- if (_browser2.default.webkit) {
- var input = $input.get(0);
- result = input && input.matches(":-webkit-autofill")
- }
- }
- return result
- }
- }, {
- key: "runWithoutEventProcessing",
- value: function(action) {
- var keyPressHandled = this._keyPressHandled;
- this._keyPressHandled = true;
- action();
- this._keyPressHandled = keyPressHandled
- }
- }, {
- key: "_backspaceHandler",
- value: function() {}
- }, {
- key: "_delHandler",
- value: function(event) {
- var editor = this.editor;
- this._keyPressHandled = true;
- editor._maskKeyHandler(event, function() {
- return !editor._hasSelection() && editor._handleKey(EMPTY_CHAR)
- })
- }
- }, {
- key: "clean",
- value: function() {
- this._clearDragTimer();
- clearTimeout(this._backspaceHandlerTimeout);
- clearTimeout(this._caretTimeout);
- clearTimeout(this._inputHandlerTimer)
- }
- }]);
- return BaseMaskStrategy
- }();
- exports.default = BaseMaskStrategy;
|