tdesign-vue
Version:
333 lines (325 loc) • 13.3 kB
JavaScript
/**
* tdesign v1.12.1
* (c) 2025 tdesign
* @license MIT
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _typeof = require('@babel/runtime/helpers/typeof');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var _common_js_utils_helper = require('../_common/js/utils/helper.js');
var utils_helper = require('../utils/helper.js');
var textarea_calcTextareaHeight = require('./calcTextareaHeight.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../utils/mixins.js');
var _common_js_utils_setStyle = require('../_common/js/utils/setStyle.js');
var textarea_props = require('./props.js');
var configProvider_context = require('../_chunks/dep-6247fdbf.js');
var isFunction = require('../_chunks/dep-411a10dd.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../_chunks/dep-5a0b1276.js');
require('../_chunks/dep-2d34b118.js');
require('../_chunks/dep-6b60413b.js');
require('../_chunks/dep-5ea2b00f.js');
require('../_chunks/dep-9b72cbc5.js');
require('../_chunks/dep-d7270eaf.js');
require('../_chunks/dep-2edcfe51.js');
require('../_chunks/dep-bf70543d.js');
require('../_chunks/dep-f895c884.js');
require('../_chunks/dep-e1cc6f64.js');
require('../_chunks/dep-7b78e8c3.js');
require('../_chunks/dep-68f48b50.js');
require('../_chunks/dep-051ce30d.js');
require('../_chunks/dep-4b30bfe2.js');
require('@babel/runtime/helpers/readOnlyError');
require('@vue/composition-api');
require('../_chunks/dep-727a349e.js');
require('../_common/js/global-config/t.js');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-3ed0c42e.js');
require('../_chunks/dep-53935099.js');
require('dayjs');
require('../_chunks/dep-403352a7.js');
require('../_chunks/dep-cca66fee.js');
require('../_chunks/dep-4361b357.js');
require('../_chunks/dep-887c649b.js');
require('../_chunks/dep-51fe98f1.js');
require('../_chunks/dep-3d682642.js');
require('../_chunks/dep-dea23841.js');
require('../_chunks/dep-4aa08166.js');
require('../_chunks/dep-ddc1429e.js');
require('../_chunks/dep-65896ff9.js');
require('../_chunks/dep-b65b2f55.js');
require('../_chunks/dep-6e7b8cda.js');
require('../_chunks/dep-98f48ff2.js');
require('../_chunks/dep-80e3757f.js');
require('../_chunks/dep-08d7842c.js');
require('../_chunks/dep-1ca3138c.js');
require('../_chunks/dep-e6ed4b1f.js');
require('../_chunks/dep-c44b2462.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
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; }
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__default["default"](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; }
var classPrefixMixins = configProvider_configReceiver.getClassPrefixMixins("textarea");
function getValidAttrs(obj) {
var newObj = {};
Object.keys(obj).forEach(function (key) {
if (typeof obj[key] !== "undefined") {
newObj[key] = obj[key];
}
});
return newObj;
}
var _Textarea = utils_mixins["default"](Vue__default["default"], classPrefixMixins).extend({
name: "TTextarea",
props: _objectSpread({}, textarea_props["default"]),
inject: {
tFormItem: {
"default": void 0
}
},
data: function data() {
return {
formDisabled: void 0,
focused: false,
mouseHover: false,
textareaStyle: {},
isComposing: false
};
},
computed: {
tDisabled: function tDisabled() {
return this.formDisabled || this.disabled;
},
textareaClasses: function textareaClasses() {
return [this.componentName, _defineProperty__default["default"](_defineProperty__default["default"]({}, "".concat(this.classPrefix, "-is-disabled"), this.tDisabled), "".concat(this.classPrefix, "-is-readonly"), this.readonly)];
},
limitClasses: function limitClasses() {
return ["".concat(this.componentName, "__limit"), _defineProperty__default["default"]({}, "".concat(this.classPrefix, "-is-disabled"), this.tDisabled)];
},
inputAttrs: function inputAttrs() {
return getValidAttrs({
autofocus: this.autofocus,
disabled: this.tDisabled,
readonly: this.readonly,
placeholder: this.placeholder,
name: this.name || void 0,
unselectable: this.readonly ? "on" : "off"
});
},
characterNumber: function characterNumber() {
var characterInfo = utils_helper.getCharacterLength(String(this.value || ""));
if (_typeof__default["default"](characterInfo) === "object") {
return characterInfo.length;
}
return characterInfo;
}
},
mounted: function mounted() {
var textareaElem = this.$refs.refTextareaElem;
if (textareaElem) {
textareaElem.addEventListener("transitionend", this.adjustTextareaHeightAfterReady);
} else {
this.adjustTextareaHeightAfterReady();
}
},
beforeDestroy: function beforeDestroy() {
var textareaElem = this.$refs.refTextareaElem;
if (textareaElem) {
textareaElem.removeEventListener("transitionend", this.adjustTextareaHeightAfterReady);
}
},
watch: {
autofocus: {
handler: function handler(val) {
var _this = this;
if (val === true) {
this.$nextTick(function () {
var textArea = _this.$refs.refTextareaElem;
textArea === null || textArea === void 0 || textArea.focus();
});
}
},
immediate: true
},
value: {
handler: function handler() {
var _this2 = this;
this.$nextTick(function () {
return _this2.adjustTextareaHeight();
});
},
immediate: true
},
textareaStyle: {
handler: function handler(val) {
var style = this.$attrs.style;
_common_js_utils_setStyle["default"](this.$refs.refTextareaElem, configProvider_context.merge(style, val));
},
immediate: true
}
},
methods: {
adjustTextareaHeight: function adjustTextareaHeight() {
var _this3 = this;
this.$nextTick(function () {
if (!_this3.$refs.refTextareaElem) return;
if (_this3.autosize === true) {
_this3.textareaStyle = textarea_calcTextareaHeight["default"](_this3.$refs.refTextareaElem);
} else if (_this3.autosize && _typeof__default["default"](_this3.autosize) === "object") {
var _this3$autosize, _this3$autosize2;
_this3.textareaStyle = textarea_calcTextareaHeight["default"](_this3.$refs.refTextareaElem, (_this3$autosize = _this3.autosize) === null || _this3$autosize === void 0 ? void 0 : _this3$autosize.minRows, (_this3$autosize2 = _this3.autosize) === null || _this3$autosize2 === void 0 ? void 0 : _this3$autosize2.maxRows);
} else if (_this3.$attrs.rows) {
_this3.textareaStyle = {
height: "auto",
minHeight: "auto"
};
}
});
},
adjustTextareaHeightAfterReady: function adjustTextareaHeightAfterReady() {
var _this4 = this;
this.$nextTick(function () {
return _this4.adjustTextareaHeight();
});
},
emitEvent: function emitEvent(name, value, context) {
this.$emit(name, value, context);
var handleName = utils_helper.getPropsApiByEvent(name);
isFunction.isFunction(this[handleName]) && this[handleName](value, context);
},
focus: function focus() {
var textArea = this.$refs.refTextareaElem;
textArea === null || textArea === void 0 || textArea.focus();
},
blur: function blur() {
var textArea = this.$refs.refTextareaElem;
textArea === null || textArea === void 0 || textArea.blur();
},
handleInput: function handleInput(e) {
this.inputValueChangeHandle(e);
},
onCompositionstart: function onCompositionstart() {
this.isComposing = true;
},
onCompositionend: function onCompositionend(e) {
this.isComposing = false;
this.inputValueChangeHandle(e);
},
inputValueChangeHandle: function inputValueChangeHandle(e) {
var _this5 = this;
var target = e.target;
var val = target.value;
if (!this.isComposing) {
if (this.maxlength) {
val = _common_js_utils_helper.limitUnicodeMaxLength(val, Number(this.maxlength));
}
if (this.maxcharacter && this.maxcharacter >= 0) {
var stringInfo = utils_helper.getCharacterLength(val, this.maxcharacter);
val = _typeof__default["default"](stringInfo) === "object" && stringInfo.characters;
}
}
this.$emit("input", val);
if (!this.isComposing) {
this.emitEvent("change", val, {
e: e
});
}
this.$nextTick(function () {
return _this5.setInputValue(val);
});
this.adjustTextareaHeight();
},
setInputValue: function setInputValue() {
var v = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
var textareaElem = this.$refs.refTextareaElem;
var sV = String(v);
if (!textareaElem) {
return;
}
if (textareaElem.value !== sV) {
textareaElem.value = sV;
}
},
emitKeyDown: function emitKeyDown(e) {
if (this.tDisabled) return;
this.emitEvent("keydown", this.value, {
e: e
});
},
emitKeyUp: function emitKeyUp(e) {
if (this.tDisabled) return;
this.emitEvent("keyup", this.value, {
e: e
});
},
emitKeypress: function emitKeypress(e) {
if (this.tDisabled) return;
this.emitEvent("keypress", this.value, {
e: e
});
},
emitFocus: function emitFocus(e) {
if (this.tDisabled) return;
this.focused = true;
this.emitEvent("focus", this.value, {
e: e
});
},
emitBlur: function emitBlur(e) {
var _this$tFormItem;
this.focused = false;
(_this$tFormItem = this.tFormItem) === null || _this$tFormItem === void 0 || _this$tFormItem.validate("blur");
this.emitEvent("blur", this.value, {
e: e
});
}
},
render: function render() {
var h = arguments[0];
var inputEvents = getValidAttrs({
focus: this.emitFocus,
blur: this.emitBlur,
keydown: this.emitKeyDown,
keyup: this.emitKeyUp,
keypress: this.emitKeypress
});
var classes = ["".concat(this.componentName, "__inner"), _defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"]({}, "".concat(this.classPrefix, "-is-").concat(this.status), this.status), this.commonStatusClassName.disabled, this.tDisabled), this.commonStatusClassName.focused, this.focused), "".concat(this.classPrefix, "-resize-none"), _typeof__default["default"](this.autosize) === "object")];
var tips = utils_renderTnode.renderTNodeJSX(this, "tips");
var textTips = tips && h("div", {
"class": ["".concat(this.componentName, "__tips"), "".concat(this.componentName, "__tips--").concat(this.status || "normal")]
}, [tips]);
var limitText = this.maxcharacter && h("span", {
"class": this.limitClasses
}, ["".concat(this.characterNumber, "/").concat(this.maxcharacter)]) || !this.maxcharacter && this.maxlength && h("span", {
"class": this.limitClasses
}, ["".concat(this.value ? _common_js_utils_helper.getUnicodeLength(String(this.value)) : 0, "/").concat(this.maxlength)]);
return h("div", {
"class": this.textareaClasses
}, [h("textarea", {
"on": _objectSpread({
"input": this.handleInput,
"compositionstart": this.onCompositionstart,
"compositionend": this.onCompositionend
}, inputEvents),
"attrs": _objectSpread({}, _objectSpread(_objectSpread({}, this.$attrs), this.inputAttrs)),
"domProps": {
"value": this.value
},
"class": classes,
"ref": "refTextareaElem"
}), textTips || limitText ? h("div", {
"class": ["".concat(this.componentName, "__info_wrapper"), _defineProperty__default["default"]({}, "".concat(this.componentName, "__info_wrapper_align"), !textTips)]
}, [textTips, limitText]) : null]);
}
});
exports["default"] = _Textarea;
//# sourceMappingURL=textarea.js.map