tdesign-vue
Version:
352 lines (348 loc) • 16.1 kB
JavaScript
/**
* tdesign v1.14.1
* (c) 2025 tdesign
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed } from '@vue/composition-api';
import { omit } from 'lodash-es';
import Panel from './components/Panel.js';
import { SelectInput } from '../select-input/index.js';
import FakeArrow from '../common-components/fake-arrow.js';
import props from './props.js';
import { useCascaderContext } from './hooks.js';
import { usePrefixClass, useCommonClassName } from '../hooks/useConfig.js';
import { handleRemoveTagEffect, closeIconClickEffect } from './core/effect.js';
import { getMultipleContent, getSingleContent, getPanels } from './core/helper.js';
import { getFakeArrowIconClass } from './core/className.js';
import { useFormDisabled } from '../hooks/useFormDisabled.js';
import { renderTNodeJSX } from '../utils/render-tnode.js';
import { useConfig } from '../config-provider/useConfig.js';
import './components/Item.js';
import '../_chunks/dep-6a4dc7bb.js';
import 'tdesign-icons-vue';
import '../checkbox/index.js';
import '../checkbox/group.js';
import '@babel/runtime/helpers/typeof';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/slicedToArray';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/constants.js';
import '../checkbox/store.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '../checkbox/hooks/useKeyboardEvent.js';
import '../_common/js/common.js';
import '../hooks/useVModel.js';
import '../hooks/useElementLazyRender.js';
import '../_common/js/utils/observe.js';
import '../checkbox/checkbox-group-props.js';
import '../hooks/slots.js';
import '../utils/withInstall.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-ba613a02.js';
import '../_chunks/dep-fdb1b253.js';
import 'dayjs';
import '../_common/js/global-config/t.js';
import '@babel/runtime/helpers/readOnlyError';
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 '../_common/js/utils/setStyle.js';
import '../_common/js/utils/helper.js';
import '../config-provider/config-receiver.js';
import '../utils/mixins.js';
import '../utils/dom.js';
import 'raf';
import '../utils/easing.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../config.js';
import '../hooks/useGlobalIcon.js';
import '../utils/ripple.js';
import '../hooks/tnode.js';
import '../hooks/render-tnode.js';
import '../select-input/select-input.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/props.js';
import '../popup/container.js';
import '../utils/event.js';
import '../popup/utils.js';
import '../utils/map-props.js';
import '../popup/plugin.js';
import '../_common/js/log/log.js';
import '../select-input/props.js';
import '../select-input/useSingle.js';
import '../input/index.js';
import '../input/input.js';
import '../input/props.js';
import '../input/input-group.js';
import '../hooks/useDefaultValue.js';
import '../select-input/useMultiple.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 '../tag/check-tag-group.js';
import '../tag/check-tag-group-props.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../select-input/useOverlayInnerStyle.js';
import '../_common/js/tree/tree-store.js';
import 'mitt';
import '../_common/js/tree/tree-node.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '../_common/js/tree/tree-node-model.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 _Cascader = defineComponent({
name: "TCascader",
props: _objectSpread({}, props),
setup: function setup(props2, _ref) {
var emit = _ref.emit;
var COMPONENT_NAME = usePrefixClass("cascader");
var classPrefix = usePrefixClass();
var _useCommonClassName = useCommonClassName(),
STATUS = _useCommonClassName.STATUS;
var overlayClassName = usePrefixClass("cascader__popup");
var _useConfig = useConfig("cascader"),
global = _useConfig.global;
var _useCascaderContext = useCascaderContext(props2),
innerValue = _useCascaderContext.innerValue,
cascaderContext = _useCascaderContext.cascaderContext,
isFilterable = _useCascaderContext.isFilterable,
getCascaderItems = _useCascaderContext.getCascaderItems;
var displayValue = computed(function () {
return props2.multiple ? getMultipleContent(cascaderContext.value) : getSingleContent(cascaderContext.value);
});
var panels = computed(function () {
return getPanels(cascaderContext.value.treeNodes);
});
var inputPlaceholder = computed(function () {
var _props2$placeholder;
if (cascaderContext.value.visible && !props2.multiple) {
var placeholder = getSingleContent(cascaderContext.value);
if (typeof placeholder === "number") placeholder = String(placeholder);
return placeholder;
}
return (_props2$placeholder = props2.placeholder) !== null && _props2$placeholder !== void 0 ? _props2$placeholder : global.value.placeholder;
});
var _useFormDisabled = useFormDisabled(),
formDisabled = _useFormDisabled.formDisabled;
var isDisabled = computed(function () {
return formDisabled.value || cascaderContext.value.disabled;
});
var valueDisplayParams = computed(function () {
var arrayValue = innerValue.value instanceof Array ? innerValue.value : [innerValue.value];
var displayValue2 = props2.multiple && props2.minCollapsedNum ? arrayValue.slice(0, props2.minCollapsedNum) : innerValue.value;
var options = getCascaderItems(arrayValue);
return {
value: innerValue.value,
selectedOptions: options,
onClose: function onClose(index) {
handleRemoveTagEffect(cascaderContext.value, index, props2.onRemove);
},
displayValue: displayValue2
};
});
var updateScrollTop = function updateScrollTop(content) {
var cascaderMenuList = content.querySelectorAll(".".concat(COMPONENT_NAME.value, "__menu"));
cascaderMenuList.forEach(function (menu) {
var firstSelectedNode = (menu === null || menu === void 0 ? void 0 : menu.querySelector(".".concat(classPrefix.value, "-is-selected"))) || (menu === null || menu === void 0 ? void 0 : menu.querySelector(".".concat(classPrefix.value, "-is-expanded")));
if (!firstSelectedNode || !menu) return;
var _getComputedStyle = getComputedStyle(firstSelectedNode),
paddingBottom = _getComputedStyle.paddingBottom;
var _getComputedStyle2 = getComputedStyle(menu),
marginBottom = _getComputedStyle2.marginBottom;
var elementBottomHeight = parseInt(paddingBottom, 10) + parseInt(marginBottom, 10);
var updateValue = firstSelectedNode.offsetTop - menu.offsetTop - (menu.clientHeight - firstSelectedNode.clientHeight) + elementBottomHeight;
menu.scrollTop = updateValue;
});
};
return {
COMPONENT_NAME: COMPONENT_NAME,
overlayClassName: overlayClassName,
panels: panels,
innerValue: innerValue,
displayValue: displayValue,
inputPlaceholder: inputPlaceholder,
isFilterable: isFilterable,
isDisabled: isDisabled,
STATUS: STATUS,
classPrefix: classPrefix,
cascaderContext: cascaderContext,
emit: emit,
valueDisplayParams: valueDisplayParams,
updateScrollTop: updateScrollTop
};
},
render: function render() {
var _this = this,
_this$popupProps;
var h = arguments[0];
var valueDisplayParams = this.valueDisplayParams,
COMPONENT_NAME = this.COMPONENT_NAME,
overlayClassName = this.overlayClassName,
panels = this.panels,
displayValue = this.displayValue,
inputPlaceholder = this.inputPlaceholder,
isFilterable = this.isFilterable,
isDisabled = this.isDisabled,
STATUS = this.STATUS,
classPrefix = this.classPrefix,
cascaderContext = this.cascaderContext,
emit = this.emit;
var renderValueDisplay = function renderValueDisplay() {
return renderTNodeJSX(_this, "valueDisplay", {
params: valueDisplayParams
});
};
var renderSuffixIcon = function renderSuffixIcon() {
var suffixIcon = renderTNodeJSX(_this, "suffixIcon");
if (suffixIcon) return suffixIcon;
var visible2 = cascaderContext.visible;
return h(FakeArrow, {
"attrs": {
"overlayClassName": getFakeArrowIconClass(classPrefix, STATUS, cascaderContext),
"isActive": visible2,
"disabled": isDisabled
}
});
};
var setVisible = cascaderContext.setVisible,
visible = cascaderContext.visible,
inputVal = cascaderContext.inputVal,
setInputVal = cascaderContext.setInputVal;
var slots = this.$scopedSlots;
return h(SelectInput, {
"class": COMPONENT_NAME,
"props": _objectSpread({}, _objectSpread({
value: displayValue,
inputValue: visible ? inputVal : "",
popupVisible: visible,
keys: this.keys,
allowInput: isFilterable,
minCollapsedNum: this.minCollapsedNum,
collapsedItems: this.collapsedItems,
label: this.label,
valueDisplay: renderValueDisplay,
suffix: this.suffix,
tag: this.tag,
readonly: this.readonly,
disabled: isDisabled,
clearable: this.clearable,
placeholder: inputPlaceholder,
multiple: this.multiple,
loading: this.loading,
status: this.status,
tips: this.tips,
updateScrollTop: this.updateScrollTop,
suffixIcon: function suffixIcon() {
return renderSuffixIcon();
},
popupProps: _objectSpread(_objectSpread({}, this.popupProps), {}, {
overlayInnerStyle: panels.length && !this.loading ? {
width: "auto"
} : "",
overlayClassName: [overlayClassName, (_this$popupProps = this.popupProps) === null || _this$popupProps === void 0 ? void 0 : _this$popupProps.overlayClassName]
}),
inputProps: _objectSpread({
size: this.size
}, this.inputProps),
tagInputProps: _objectSpread({
size: this.size
}, this.tagInputProps),
tagProps: _objectSpread({}, this.tagProps),
onInputChange: function onInputChange(value, ctx) {
var _this$selectInputProp, _this$selectInputProp2;
if (!_this.isFilterable) return;
setInputVal("".concat(value));
_this === null || _this === void 0 || (_this$selectInputProp = _this.selectInputProps) === null || _this$selectInputProp === void 0 || (_this$selectInputProp2 = _this$selectInputProp.onInputChange) === null || _this$selectInputProp2 === void 0 || _this$selectInputProp2.call(_this$selectInputProp, value, ctx);
},
onTagChange: function onTagChange(val, ctx) {
var _this$selectInputProp3, _this$selectInputProp4;
if (ctx.trigger === "enter") return;
handleRemoveTagEffect(cascaderContext, ctx.index, _this.onRemove);
(_this$selectInputProp3 = _this.selectInputProps) === null || _this$selectInputProp3 === void 0 || (_this$selectInputProp4 = _this$selectInputProp3.onTagChange) === null || _this$selectInputProp4 === void 0 || _this$selectInputProp4.call(_this$selectInputProp3, val, ctx);
},
onPopupVisibleChange: function onPopupVisibleChange(val, context) {
var _this$selectInputProp5, _this$selectInputProp6;
if (_this.disabled) return;
setVisible(val, context);
(_this$selectInputProp5 = _this.selectInputProps) === null || _this$selectInputProp5 === void 0 || (_this$selectInputProp6 = _this$selectInputProp5.onPopupVisibleChange) === null || _this$selectInputProp6 === void 0 || _this$selectInputProp6.call(_this$selectInputProp5, val, context);
},
onBlur: function onBlur(val, context) {
var _this$onBlur, _this$selectInputProp7, _this$selectInputProp8;
var ctx = {
value: cascaderContext.value,
inputValue: context.inputValue || "",
e: context.e
};
(_this$onBlur = _this.onBlur) === null || _this$onBlur === void 0 || _this$onBlur.call(_this, ctx);
emit("blur", ctx);
(_this$selectInputProp7 = _this.selectInputProps) === null || _this$selectInputProp7 === void 0 || (_this$selectInputProp8 = _this$selectInputProp7.onBlur) === null || _this$selectInputProp8 === void 0 || _this$selectInputProp8.call(_this$selectInputProp7, val, context);
},
onFocus: function onFocus(val, context) {
var _this$onFocus, _this$selectInputProp9, _this$selectInputProp0;
var ctx = {
value: cascaderContext.value,
e: context.e
};
(_this$onFocus = _this.onFocus) === null || _this$onFocus === void 0 || _this$onFocus.call(_this, ctx);
emit("focus", ctx);
(_this$selectInputProp9 = _this.selectInputProps) === null || _this$selectInputProp9 === void 0 || (_this$selectInputProp0 = _this$selectInputProp9.onFocus) === null || _this$selectInputProp0 === void 0 || _this$selectInputProp0.call(_this$selectInputProp9, val, context);
},
onClear: function onClear(context) {
var _this$selectInputProp1, _this$selectInputProp10;
closeIconClickEffect(cascaderContext);
(_this$selectInputProp1 = _this.selectInputProps) === null || _this$selectInputProp1 === void 0 || (_this$selectInputProp10 = _this$selectInputProp1.onClear) === null || _this$selectInputProp10 === void 0 || _this$selectInputProp10.call(_this$selectInputProp1, context);
}
}, omit(this.selectInputProps, ["onTagChange", "onInputChange", "onPopupVisibleChange", "onBlur", "onFocus", "onClear"]))),
"scopedSlots": {
panel: function panel() {
return h(Panel, {
"attrs": {
"option": _this.option,
"empty": _this.empty,
"trigger": _this.trigger,
"loading": _this.loading,
"loadingText": _this.loadingText,
"cascaderContext": cascaderContext
},
"scopedSlots": {
option: slots.option,
empty: slots.empty,
loadingText: slots.loadingText
}
});
},
tips: slots.tips,
tag: slots.tag,
suffix: slots.suffix,
label: slots.label,
collapsedItems: slots.collapsedItems
}
});
}
});
export { _Cascader as default };
//# sourceMappingURL=cascader.js.map