UNPKG

tdesign-vue

Version:
336 lines (328 loc) 13.5 kB
/** * tdesign v1.15.0 * (c) 2026 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-8eddb350.js'); var isFunction = require('../_chunks/dep-8d206316.js'); require('@babel/runtime/helpers/toConsumableArray'); require('@babel/runtime/helpers/objectWithoutProperties'); require('@babel/runtime/helpers/slicedToArray'); require('../_chunks/dep-721fcdf6.js'); require('../_chunks/dep-591b87f1.js'); require('../_chunks/dep-a2217d56.js'); require('../_chunks/dep-3b2292ce.js'); require('../_chunks/dep-10fcb46d.js'); require('../_chunks/dep-ba7f5924.js'); require('../_chunks/dep-268c68b1.js'); require('../_chunks/dep-9c5b91d3.js'); require('../_chunks/dep-9a74c2be.js'); require('../_chunks/dep-689d381f.js'); require('../_chunks/dep-803744d9.js'); require('../_chunks/dep-84027b7f.js'); require('../_chunks/dep-49400b00.js'); require('../_chunks/dep-f1081d8e.js'); require('@babel/runtime/helpers/readOnlyError'); require('@vue/composition-api'); require('../_chunks/dep-2c592e99.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-0c37520c.js'); require('../_chunks/dep-c13dcbfd.js'); require('dayjs'); require('../_chunks/dep-6f4e680e.js'); require('../_chunks/dep-bb0ececf.js'); require('../_chunks/dep-6eba4d23.js'); require('../_chunks/dep-010db548.js'); require('../_chunks/dep-f77d6ad5.js'); require('../_chunks/dep-9dae8101.js'); require('../_chunks/dep-7c84d9a0.js'); require('../_chunks/dep-733a2279.js'); require('../_chunks/dep-2bc87cc8.js'); require('../_chunks/dep-d844c9ed.js'); require('../_chunks/dep-c05a9033.js'); require('../_chunks/dep-efe55b82.js'); require('../_chunks/dep-7da70ee1.js'); require('../_chunks/dep-124386d4.js'); require('../_chunks/dep-f5b14344.js'); require('../_chunks/dep-36c2788b.js'); require('../_chunks/dep-fa353fbb.js'); require('../_chunks/dep-d66ab3a4.js'); require('../_chunks/dep-d4d8c513.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); if (!this.allowInputOverMax) { 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"](_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"), "".concat(this.classPrefix, "-hide-scrollbar"), this.autosize === true)]; 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