tdesign-vue
Version:
250 lines (246 loc) • 10.7 kB
JavaScript
/**
* tdesign v1.12.1
* (c) 2025 tdesign
* @license MIT
*/
import { h as helper } from '../_chunks/dep-323b993c.js';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, toRefs, computed, watch, onMounted, onBeforeUnmount } from '@vue/composition-api';
import { Popup } from '../popup/index.js';
import props from './props.js';
import useSingle from './useSingle.js';
import useMultiple from './useMultiple.js';
import useOverlayInnerStyle from './useOverlayInnerStyle.js';
import { useConfig } from '../config-provider/useConfig.js';
import { renderTNodeJSX } from '../utils/render-tnode.js';
import '../popup/popup.js';
import '@babel/runtime/helpers/typeof';
import '@popperjs/core';
import 'lodash-es';
import '../utils/dom.js';
import 'vue';
import 'raf';
import '../utils/easing.js';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../_common/js/utils/setStyle.js';
import '../popup/props.js';
import '../popup/container.js';
import '../config-provider/config-receiver.js';
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-c44a474d.js';
import '../_chunks/dep-d639fbd7.js';
import 'dayjs';
import '../_chunks/dep-3c66615e.js';
import '../config-provider/type.js';
import '../_common/js/global-config/t.js';
import '../utils/mixins.js';
import '../utils/event.js';
import '../popup/utils.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import './style/css.js';
import '../popup/type.js';
import '../popup/plugin.js';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '@babel/runtime/helpers/readOnlyError';
import '../input/index.js';
import '../input/input.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'tdesign-icons-vue';
import '../_common/js/utils/helper.js';
import '../input/props.js';
import '../input/input-group.js';
import '../input/type.js';
import '../loading/index.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../config.js';
import '../loading/type.js';
import '../hooks/tnode.js';
import '../hooks/render-tnode.js';
import '../hooks/useConfig.js';
import '../hooks/useDefaultValue.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../tag-input/props.js';
import '../tag-input/hooks/useTagScroll.js';
import '../tag-input/useTagList.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/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/useGlobalIcon.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 '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../tag-input/type.js';
import '../tag-input/interface.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 _SelectInput = defineComponent({
name: "TSelectInput",
props: _objectSpread(_objectSpread({}, props), {}, {
updateScrollTop: {
type: Function
}
}),
setup: function setup(props2, context) {
var selectInputRef = ref();
var _useConfig = useConfig("classPrefix"),
classPrefix = _useConfig.classPrefix;
var _toRefs = toRefs(props2),
multiple = _toRefs.multiple,
value = _toRefs.value,
popupVisible = _toRefs.popupVisible,
borderless = _toRefs.borderless;
var _useSingle = useSingle(props2, context),
isSingleFocus = _useSingle.isSingleFocus,
commonInputProps = _useSingle.commonInputProps,
singleInputValue = _useSingle.singleInputValue,
onInnerClear = _useSingle.onInnerClear,
renderSelectSingle = _useSingle.renderSelectSingle;
var _useMultiple = useMultiple(props2, context),
multipleInputValue = _useMultiple.multipleInputValue,
isMultipleFocus = _useMultiple.isMultipleFocus,
renderSelectMultiple = _useMultiple.renderSelectMultiple;
var _useOverlayInnerStyle = useOverlayInnerStyle(props2, {
afterHidePopup: onInnerBlur
}),
tOverlayInnerStyle = _useOverlayInnerStyle.tOverlayInnerStyle,
innerPopupVisible = _useOverlayInnerStyle.innerPopupVisible,
onInnerPopupVisibleChange = _useOverlayInnerStyle.onInnerPopupVisibleChange;
var isFocus = computed(function () {
return props2.multiple ? isMultipleFocus.value : isSingleFocus.value;
});
function onInnerBlur(ctx) {
var _props2$onBlur;
var inputValue = props2.multiple ? multipleInputValue.value : singleInputValue.value;
var params = {
e: ctx.e,
inputValue: inputValue
};
(_props2$onBlur = props2.onBlur) === null || _props2$onBlur === void 0 || _props2$onBlur.call(props2, props2.value, params);
context.emit("blur", props2.value, params);
isSingleFocus.value = false;
isMultipleFocus.value = false;
}
var classes = computed(function () {
var _popupVisible$value;
return ["".concat(classPrefix.value, "-select-input"), _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(classPrefix.value, "-select-input--borderless"), borderless.value), "".concat(classPrefix.value, "-select-input--multiple"), multiple.value), "".concat(classPrefix.value, "-select-input--popup-visible"), (_popupVisible$value = popupVisible.value) !== null && _popupVisible$value !== void 0 ? _popupVisible$value : innerPopupVisible.value), "".concat(classPrefix.value, "-select-input--empty"), value.value instanceof Array ? !value.value.length : !value.value)];
});
var addKeyboardEventListener = function addKeyboardEventListener(e) {
if (/(ArrowDown|ArrowUp)/.test(e.code || e.key)) {
var _props2$onPopupVisibl;
var ctx = _objectSpread(_objectSpread({}, context), {}, {
trigger: "trigger-element-focus"
});
(_props2$onPopupVisibl = props2.onPopupVisibleChange) === null || _props2$onPopupVisibl === void 0 || _props2$onPopupVisibl.call(props2, true, ctx);
context.emit("popup-visible-change", true, ctx);
}
};
watch([isFocus], function (_ref2) {
var _ref3 = _slicedToArray(_ref2, 1),
isFocus2 = _ref3[0];
if (popupVisible.value) return;
if (isFocus2) {
selectInputRef.value.addEventListener("keydown", addKeyboardEventListener);
} else {
selectInputRef.value.removeEventListener("keydown", addKeyboardEventListener);
}
});
onMounted(function () {
if (!popupVisible.value && isFocus) {
selectInputRef.value.addEventListener("keydown", addKeyboardEventListener);
}
});
onBeforeUnmount(function () {
selectInputRef.value.removeEventListener("keydown", addKeyboardEventListener);
});
return {
selectInputRef: selectInputRef,
innerPopupVisible: innerPopupVisible,
commonInputProps: commonInputProps,
tOverlayInnerStyle: tOverlayInnerStyle,
classes: classes,
onInnerClear: onInnerClear,
renderSelectSingle: renderSelectSingle,
renderSelectMultiple: renderSelectMultiple,
onInnerPopupVisibleChange: onInnerPopupVisibleChange,
classPrefix: classPrefix
};
},
render: function render(h) {
var _this$popupVisible, _this$popupProps, _this$popupVisible2;
var visibleProps = {
visible: (_this$popupVisible = this.popupVisible) !== null && _this$popupVisible !== void 0 ? _this$popupVisible : this.innerPopupVisible
};
var mainContent = h(Popup, helper([{
"ref": "selectInputPopupRef",
"attrs": {
"trigger": ((_this$popupProps = this.popupProps) === null || _this$popupProps === void 0 ? void 0 : _this$popupProps.trigger) || "click",
"placement": "bottom-left",
"visible": (_this$popupVisible2 = this.popupVisible) !== null && _this$popupVisible2 !== void 0 ? _this$popupVisible2 : this.innerPopupVisible,
"content": this.panel,
"hideEmptyPopup": true,
"disabled": this.disabled || this.readonly
},
"scopedSlots": _objectSpread(_objectSpread({}, this.$scopedSlots), {}, {
content: this.$scopedSlots.panel
}),
"key": this.multiple ? "multiple" : "single"
}, {
"on": {
"visible-change": this.onInnerPopupVisibleChange
}
}, {}, {
"props": _objectSpread(_objectSpread({}, this.popupProps), {}, {
overlayInnerStyle: this.tOverlayInnerStyle
})
}, {
"attrs": {
"updateScrollTop": this.updateScrollTop
}
}]), [this.multiple ? this.renderSelectMultiple({
commonInputProps: this.commonInputProps,
onInnerClear: this.onInnerClear,
popupVisible: visibleProps.visible
}, h) : this.renderSelectSingle(h, visibleProps.visible)]);
var tipsNode = renderTNodeJSX(this, "tips");
return h("div", {
"ref": "selectInputRef",
"class": this.classes
}, [mainContent, tipsNode && h("div", {
"class": "".concat(this.classPrefix, "-input__tips ").concat(this.classPrefix, "-input__tips--").concat(this.status || "normal")
}, [tipsNode])]);
}
});
export { _SelectInput as default };
//# sourceMappingURL=select-input.js.map