tdesign-vue
Version:
347 lines (343 loc) • 14.8 kB
JavaScript
/**
* tdesign v1.11.2
* (c) 2025 tdesign
* @license MIT
*/
import { h as helper } from '../_chunks/dep-8db32566.js';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, ref, computed, nextTick, watch } from '@vue/composition-api';
import { CloseCircleFilledIcon } from 'tdesign-icons-vue';
import { Input } from '../input/index.js';
import props from './props.js';
import { renderTNodeJSX } from '../utils/render-tnode.js';
import useTagScroll from './hooks/useTagScroll.js';
import useTagList from './useTagList.js';
import useHover from './hooks/useHover.js';
import useDefaultValue from '../hooks/useDefaultValue.js';
import useDragSorter from './hooks/useDragSorter.js';
import { useGlobalIcon } from '../hooks/useGlobalIcon.js';
import { usePrefixClass } from '../config-provider/useConfig.js';
import '../input/input.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/typeof';
import 'lodash-es';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../utils/helper.js';
import '../config-provider/config-receiver.js';
import 'vue';
import '../config-provider/context.js';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-a883488c.js';
import '../_chunks/dep-90ffe67f.js';
import 'dayjs';
import '../_chunks/dep-9d1c0d31.js';
import '../config-provider/type.js';
import '../utils/mixins.js';
import '../utils/event.js';
import '../input/props.js';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '@babel/runtime/helpers/readOnlyError';
import '../input/input-group.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import './style/css.js';
import '../input/type.js';
import '../tag/index.js';
import '../tag/tag.js';
import 'tinycolor2';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../hooks/useConfig.js';
import '../hooks/useVModel.js';
import '../_common/js/common.js';
import '../hooks/index.js';
import '../hooks/slots.js';
import '../hooks/useCommonClassName.js';
import '../hooks/useDestroyOnClose.js';
import '../hooks/useElementLazyRender.js';
import '../_common/js/utils/observe.js';
import '../hooks/useFormDisabled.js';
import '../hooks/useLazyLoad.js';
import '../hooks/useResizeObserver.js';
import '../hooks/useVirtualScrollNew.js';
import '../hooks/useImagePreviewUrl.js';
import '../_common/js/upload/utils.js';
import '../tag/check-tag-group.js';
import '../tag/check-tag-group-props.js';
import '../tag/type.js';
import '../hooks/tnode.js';
import '../hooks/render-tnode.js';
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(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 _TagInput = defineComponent({
name: "TTagInput",
props: _objectSpread({}, props),
setup: function setup(props2, context) {
var _toRefs = toRefs(props2),
inputValue = _toRefs.inputValue,
inputProps = _toRefs.inputProps;
var isComposition = ref(false);
var COMPONENT_NAME = usePrefixClass("tag-input");
var classPrefix = usePrefixClass();
var _useDefaultValue = useDefaultValue(inputValue, props2.defaultInputValue, props2.onInputChange, "inputValue", "input-change"),
_useDefaultValue2 = _slicedToArray(_useDefaultValue, 2),
tInputValue = _useDefaultValue2[0],
setTInputValue = _useDefaultValue2[1];
var _toRefs2 = toRefs(props2),
excessTagsDisplayType = _toRefs2.excessTagsDisplayType,
readonly = _toRefs2.readonly,
disabled = _toRefs2.disabled,
clearable = _toRefs2.clearable,
placeholder = _toRefs2.placeholder;
var _useHover = useHover({
readonly: readonly,
disabled: disabled,
onMouseenter: props2.onMouseenter,
onMouseleave: props2.onMouseleave
}, context),
isHover = _useHover.isHover,
addHover = _useHover.addHover,
cancelHover = _useHover.cancelHover;
var _useDragSorter = useDragSorter(_objectSpread(_objectSpread({}, props2), {}, {
sortOnDraggable: props2.dragSort,
onDragOverCheck: {
x: true,
targetClassNameRegExp: new RegExp("^".concat(classPrefix.value, "-tag"))
}
}), context),
getDragProps = _useDragSorter.getDragProps;
var _useTagScroll = useTagScroll(props2),
scrollToRight = _useTagScroll.scrollToRight,
onWheel = _useTagScroll.onWheel,
scrollToRightOnEnter = _useTagScroll.scrollToRightOnEnter,
scrollToLeftOnLeave = _useTagScroll.scrollToLeftOnLeave,
tagInputRef = _useTagScroll.tagInputRef,
isScrollable = _useTagScroll.isScrollable;
var _useTagList = useTagList(props2, context, getDragProps),
tagValue = _useTagList.tagValue,
onInnerEnter = _useTagList.onInnerEnter,
onInputBackspaceKeyUp = _useTagList.onInputBackspaceKeyUp,
onInputBackspaceKeyDown = _useTagList.onInputBackspaceKeyDown,
clearAll = _useTagList.clearAll,
renderLabel = _useTagList.renderLabel,
onClose = _useTagList.onClose;
var _useGlobalIcon = useGlobalIcon({
CloseCircleFilledIcon: CloseCircleFilledIcon
}),
CloseCircleFilledIcon$1 = _useGlobalIcon.CloseCircleFilledIcon;
var classes = computed(function () {
var isEmpty = !(Array.isArray(tagValue.value) && tagValue.value.length);
return [COMPONENT_NAME.value, _defineProperty(_defineProperty(_defineProperty({}, "".concat(COMPONENT_NAME.value, "--break-line"), excessTagsDisplayType.value === "break-line"), "".concat(classPrefix.value, "-is-empty"), isEmpty), "".concat(classPrefix.value, "-tag-input--with-tag"), !isEmpty)];
});
var tagInputPlaceholder = computed(function () {
var _tagValue$value;
return !((_tagValue$value = tagValue.value) !== null && _tagValue$value !== void 0 && _tagValue$value.length) ? placeholder.value : "";
});
var showClearIcon = computed(function () {
var _tagValue$value2;
return Boolean(!readonly.value && !disabled.value && clearable.value && isHover.value && (((_tagValue$value2 = tagValue.value) === null || _tagValue$value2 === void 0 ? void 0 : _tagValue$value2.length) || tInputValue.value));
});
var onInputCompositionstart = function onInputCompositionstart(value, context2) {
var _inputProps$value, _inputProps$value$onC;
isComposition.value = true;
(_inputProps$value = inputProps.value) === null || _inputProps$value === void 0 || (_inputProps$value$onC = _inputProps$value.onCompositionstart) === null || _inputProps$value$onC === void 0 || _inputProps$value$onC.call(_inputProps$value, value, context2);
};
var onInputCompositionend = function onInputCompositionend(value, context2) {
var _inputProps$value2, _inputProps$value2$on;
isComposition.value = false;
(_inputProps$value2 = inputProps.value) === null || _inputProps$value2 === void 0 || (_inputProps$value2$on = _inputProps$value2.onCompositionend) === null || _inputProps$value2$on === void 0 || _inputProps$value2$on.call(_inputProps$value2, value, context2);
};
var onInputEnter = function onInputEnter(value, context2) {
var _context2$e;
(_context2$e = context2.e) === null || _context2$e === void 0 || _context2$e.preventDefault();
setTInputValue("", {
e: context2.e,
trigger: "enter"
});
!isComposition.value && onInnerEnter(value, context2);
nextTick(function () {
scrollToRight();
isComposition.value = false;
});
};
var onInnerClick = function onInnerClick(params) {
var _props2$onClick;
(_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 || _props2$onClick.call(props2, params);
context.emit("click", params);
};
var onClearClick = function onClearClick(ctx) {
var _props2$onClear;
clearAll(ctx);
setTInputValue("", {
e: ctx.e,
trigger: "clear"
});
(_props2$onClear = props2.onClear) === null || _props2$onClear === void 0 || _props2$onClear.call(props2, ctx);
context.emit("clear", ctx);
};
watch(function () {
return isScrollable.value;
}, function (v) {
if (props2.excessTagsDisplayType !== "scroll") return;
var scrollElementClass = "".concat(classPrefix.value, "-input__prefix");
var scrollElement = tagInputRef.value.$el.querySelector(".".concat(scrollElementClass));
if (v) scrollElement.classList.add("".concat(scrollElementClass, "--scrollable"));else scrollElement.classList.remove("".concat(scrollElementClass, "--scrollable"));
});
return {
tagValue: tagValue,
tInputValue: tInputValue,
isHover: isHover,
tagInputPlaceholder: tagInputPlaceholder,
showClearIcon: showClearIcon,
tagInputRef: tagInputRef,
classPrefix: classPrefix,
classes: classes,
componentName: COMPONENT_NAME,
setTInputValue: setTInputValue,
addHover: addHover,
cancelHover: cancelHover,
onInputEnter: onInputEnter,
onInnerEnter: onInnerEnter,
onInputBackspaceKeyUp: onInputBackspaceKeyUp,
onInputBackspaceKeyDown: onInputBackspaceKeyDown,
renderLabel: renderLabel,
onWheel: onWheel,
scrollToRightOnEnter: scrollToRightOnEnter,
scrollToLeftOnLeave: scrollToLeftOnLeave,
onClearClick: onClearClick,
onInnerClick: onInnerClick,
onClose: onClose,
onInputCompositionstart: onInputCompositionstart,
onInputCompositionend: onInputCompositionend,
CloseCircleFilledIcon: CloseCircleFilledIcon$1
};
},
render: function render(h) {
var _this = this,
_this$inputProps,
_this$inputProps2,
_this$tagValue;
var CloseCircleFilledIcon = this.CloseCircleFilledIcon;
var suffixIconNode = this.showClearIcon ? h(CloseCircleFilledIcon, {
"class": "".concat(this.componentName, "__suffix-clear"),
"on": {
"click": this.onClearClick
}
}) : renderTNodeJSX(this, "suffixIcon");
var suffixClass = "".concat(this.classPrefix, "-tag-input__with-suffix-icon");
if (suffixIconNode && !this.classes.includes(suffixClass)) {
this.classes.push(suffixClass);
}
var prefixIconNode = renderTNodeJSX(this, "prefixIcon");
var displayNode = renderTNodeJSX(this, "valueDisplay", {
params: {
value: this.tagValue,
onClose: function onClose(index) {
return _this.onClose({
index: index
});
}
}
});
var _label = renderTNodeJSX(this, "label", {
silent: true
});
var readonly = this.readonly || ((_this$inputProps = this.inputProps) === null || _this$inputProps === void 0 ? void 0 : _this$inputProps.readonly);
return h(Input, helper([{
"ref": "tagInputRef",
"attrs": {
"borderless": this.borderless,
"readonly": readonly,
"inputClass": (_this$inputProps2 = this.inputProps) === null || _this$inputProps2 === void 0 ? void 0 : _this$inputProps2.inputClass,
"value": this.tInputValue,
"showInput": !readonly || !this.tagValue || !((_this$tagValue = this.tagValue) !== null && _this$tagValue !== void 0 && _this$tagValue.length),
"keepWrapperWidth": !this.autoWidth,
"autoWidth": true,
"size": this.size,
"disabled": this.disabled,
"label": function label() {
return _this.renderLabel({
displayNode: displayNode,
label: _label
}, h);
},
"tips": this.tips,
"status": this.status,
"placeholder": this.tagInputPlaceholder,
"suffix": this.suffix,
"suffixIcon": function suffixIcon() {
return suffixIconNode;
},
"prefixIcon": function prefixIcon() {
return prefixIconNode;
}
},
"class": this.classes
}, {
"props": this.inputProps
}, {
"scopedSlots": this.$scopedSlots
}, {
"on": {
change: function change(val, context) {
_this.setTInputValue(val, _objectSpread(_objectSpread({}, context), {}, {
trigger: "input"
}));
},
enter: this.onInputEnter,
keyup: this.onInputBackspaceKeyUp,
keydown: this.onInputBackspaceKeyDown,
mouseenter: function mouseenter(context) {
_this.addHover(context);
_this.scrollToRightOnEnter();
},
mouseleave: function mouseleave(context) {
_this.cancelHover(context);
_this.scrollToLeftOnLeave();
},
focus: function focus(inputValue, context) {
var _this$onFocus;
(_this$onFocus = _this.onFocus) === null || _this$onFocus === void 0 || _this$onFocus.call(_this, _this.tagValue, {
e: context.e,
inputValue: inputValue
});
_this.$emit("focus", _this.tagValue, {
e: context.e,
inputValue: inputValue
});
},
blur: function blur(inputValue, context) {
var _this$onBlur;
_this.setTInputValue("", {
e: context.e,
trigger: "blur"
});
(_this$onBlur = _this.onBlur) === null || _this$onBlur === void 0 || _this$onBlur.call(_this, _this.tagValue, {
e: context.e,
inputValue: ""
});
_this.$emit("blur", _this.tagValue, {
e: context.e,
inputValue: ""
});
},
paste: function paste(context) {
var _this$onPaste;
(_this$onPaste = _this.onPaste) === null || _this$onPaste === void 0 || _this$onPaste.call(_this, context);
_this.$emit("paste", context);
},
click: this.onInnerClick,
compositionstart: this.onInputCompositionstart,
compositionend: this.onInputCompositionend,
mousewheel: this.onWheel
}
}]));
}
});
export { _TagInput as default };
//# sourceMappingURL=tag-input.js.map