UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

185 lines (181 loc) 7.83 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _slicedToArray from '@babel/runtime/helpers/slicedToArray'; import { toRefs, ref, computed, createVNode, mergeProps } from 'vue'; import isObject from 'lodash/isObject'; import { TagInput } from '../tag-input/index.js'; import { Loading } from '../loading/index.js'; import useDefaultValue from '../hooks/useDefaultValue.js'; import { usePrefixClass } from '../hooks/useConfig.js'; import { useFormDisabled } from '../form/hooks.js'; import '../tag-input/tag-input.js'; import '../_chunks/dep-fb0628ce.js'; import '../input/index.js'; import '../input/input.js'; import '../_chunks/dep-eade0dcf.js'; import '../input/props.js'; import '../hooks/tnode.js'; import 'lodash/isFunction'; import 'lodash/camelCase'; import 'lodash/kebabCase'; import '../utils/render-tnode.js'; import 'lodash/isEmpty'; import 'lodash/isString'; import '../input/useInput.js'; import '../form/const.js'; import '../config-provider/useConfig.js'; import 'lodash/cloneDeep'; import '../config-provider/context.js'; import 'lodash/mergeWith'; import 'lodash/merge'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/en_US.js'; import '../_chunks/dep-3a1cce9f.js'; import 'lodash/isArray'; import '../hooks/useVModel.js'; import '../input/useLengthLimit.js'; import '../_common/js/log/log.js'; import '../_common/js/utils/helper.js'; import '@babel/runtime/helpers/toConsumableArray'; import 'lodash/isNull'; import 'lodash/isUndefined'; import 'lodash/isNumber'; import '../input/useInputEventHandler.js'; import '../input/useInputWidth.js'; import '../input/input-group.js'; import '../input/input-group-props.js'; import '../utils/withInstall.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 '../_chunks/dep-ae5efda0.js'; import '../tag/props.js'; import '../tag/check-tag.js'; import '../tag/check-tag-props.js'; import '../tag-input/hooks/useHover.js'; import '../tag-input/hooks/useDragSorter.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/set-style.js'; import '../utils/dom.js'; import '../utils/easing.js'; import '../loading/props.js'; import '../hooks/useTeleport.js'; var _excluded = ["tips"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } var DEFAULT_KEYS = { label: "label", key: "key", children: "children" }; function useMultiple(props, context) { var _toRefs = toRefs(props), inputValue = _toRefs.inputValue; var classPrefix = usePrefixClass(); var tagInputRef = ref(); var _useDefault = useDefaultValue(inputValue, props.defaultInputValue, props.onInputChange, "inputValue"), _useDefault2 = _slicedToArray(_useDefault, 2), tInputValue = _useDefault2[0], setTInputValue = _useDefault2[1]; var disable = useFormDisabled(); var iKeys = computed(function () { return _objectSpread(_objectSpread({}, DEFAULT_KEYS), props.keys); }); var tags = computed(function () { if (!(props.value instanceof Array)) { return isObject(props.value) ? [props.value[iKeys.value.label]] : [props.value]; } return props.value.map(function (item) { return isObject(item) ? item[iKeys.value.label] : item; }); }); var tPlaceholder = computed(function () { return !tags.value || !tags.value.length ? props.placeholder : ""; }); var onTagInputChange = function onTagInputChange(val, context2) { var _props$onTagChange; if (context2.trigger === "tag-remove") { var _context2$e; (_context2$e = context2.e) === null || _context2$e === void 0 ? void 0 : _context2$e.stopPropagation(); } (_props$onTagChange = props.onTagChange) === null || _props$onTagChange === void 0 ? void 0 : _props$onTagChange.call(props, val, context2); }; var renderSelectMultiple = function renderSelectMultiple(p) { var tagInputProps = _objectSpread(_objectSpread({}, p.commonInputProps), {}, { tagProps: props.tagProps, label: props.label, autoWidth: props.autoWidth, readonly: props.readonly, placeholder: tPlaceholder.value, minCollapsedNum: props.minCollapsedNum, collapsedItems: props.collapsedItems, tag: props.tag, value: tags.value, valueDisplay: props.valueDisplay, inputValue: p.popupVisible && p.allowInput ? tInputValue.value : "", inputProps: _objectSpread({ readonly: !props.allowInput || props.readonly, inputClass: _defineProperty({}, "".concat(classPrefix.value, "-input--focused"), p.popupVisible) }, props.inputProps), suffixIcon: !disable.value && props.loading ? function () { return createVNode(Loading, { "loading": true, "size": "small" }, null); } : props.suffixIcon }, props.tagInputProps); var _context$slots = context.slots; _context$slots.tips; var slots = _objectWithoutProperties(_context$slots, _excluded); return createVNode(TagInput, mergeProps({ "ref": "tagInputRef" }, tagInputProps, { "onInputChange": function onInputChange(val, context2) { if ((context2 === null || context2 === void 0 ? void 0 : context2.trigger) === "enter" || (context2 === null || context2 === void 0 ? void 0 : context2.trigger) === "blur") return; setTInputValue(val, { trigger: context2.trigger, e: context2.e }); }, "onChange": onTagInputChange, "onClear": p.onInnerClear, "onBlur": function onBlur(val, context2) { var _props$onBlur; (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 ? void 0 : _props$onBlur.call(props, props.value, _objectSpread(_objectSpread({}, context2), {}, { tagInputValue: val })); }, "onEnter": function onEnter(val, context2) { var _props$onEnter; (_props$onEnter = props.onEnter) === null || _props$onEnter === void 0 ? void 0 : _props$onEnter.call(props, props.value, _objectSpread(_objectSpread({}, context2), {}, { inputValue: tInputValue.value })); }, "onFocus": function onFocus(val, context2) { var _props$onFocus; (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, props.value, _objectSpread(_objectSpread({}, context2), {}, { tagInputValue: val })); } }), slots); }; return { tags: tags, tPlaceholder: tPlaceholder, tagInputRef: tagInputRef, renderSelectMultiple: renderSelectMultiple }; } export { useMultiple as default }; //# sourceMappingURL=useMultiple.js.map