1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | var _typeof = require("@babel/runtime/helpers/typeof");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports.selectProps = exports.default = exports.SelectOption = exports.SelectOptGroup = void 0;
|
11 |
|
12 | var _vue = require("vue");
|
13 |
|
14 | var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
15 |
|
16 | var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
17 |
|
18 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
19 |
|
20 | var _classNames3 = _interopRequireDefault(require("../_util/classNames"));
|
21 |
|
22 | var _vcSelect = _interopRequireWildcard(require("../vc-select"));
|
23 |
|
24 | var _iconUtil = _interopRequireDefault(require("./utils/iconUtil"));
|
25 |
|
26 | var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));
|
27 |
|
28 | var _useConfigInject2 = _interopRequireDefault(require("../_util/hooks/useConfigInject"));
|
29 |
|
30 | var _omit = _interopRequireDefault(require("../_util/omit"));
|
31 |
|
32 | var _FormItemContext = require("../form/FormItemContext");
|
33 |
|
34 | var _transition = require("../_util/transition");
|
35 |
|
36 | var _propsUtil = require("../_util/props-util");
|
37 |
|
38 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
39 |
|
40 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
41 |
|
42 | var selectProps = function selectProps() {
|
43 | return (0, _extends2.default)((0, _extends2.default)({}, (0, _omit.default)((0, _vcSelect.selectProps)(), ['inputIcon', 'mode', 'getInputElement', 'getRawInputElement', 'backfill'])), {
|
44 | value: {
|
45 | type: [Array, Object, String, Number]
|
46 | },
|
47 | defaultValue: {
|
48 | type: [Array, Object, String, Number]
|
49 | },
|
50 | notFoundContent: _vueTypes.default.any,
|
51 | suffixIcon: _vueTypes.default.any,
|
52 | itemIcon: _vueTypes.default.any,
|
53 | size: String,
|
54 | mode: String,
|
55 | bordered: {
|
56 | type: Boolean,
|
57 | default: true
|
58 | },
|
59 | transitionName: String,
|
60 | choiceTransitionName: {
|
61 | type: String,
|
62 | default: ''
|
63 | },
|
64 | 'onUpdate:value': Function
|
65 | });
|
66 | };
|
67 |
|
68 | exports.selectProps = selectProps;
|
69 | var SECRET_COMBOBOX_MODE_DO_NOT_USE = 'SECRET_COMBOBOX_MODE_DO_NOT_USE';
|
70 | var Select = (0, _vue.defineComponent)({
|
71 | name: 'ASelect',
|
72 | Option: _vcSelect.Option,
|
73 | OptGroup: _vcSelect.OptGroup,
|
74 | inheritAttrs: false,
|
75 | props: (0, _propsUtil.initDefaultProps)(selectProps(), {
|
76 | listHeight: 256,
|
77 | listItemHeight: 24
|
78 | }),
|
79 | SECRET_COMBOBOX_MODE_DO_NOT_USE: SECRET_COMBOBOX_MODE_DO_NOT_USE,
|
80 |
|
81 | slots: ['notFoundContent', 'suffixIcon', 'itemIcon', 'removeIcon', 'clearIcon', 'dropdownRender', 'option', 'placeholder', 'tagRender', 'maxTagPlaceholder', 'optionLabel'
|
82 | ],
|
83 | setup: function setup(props, _ref) {
|
84 | var attrs = _ref.attrs,
|
85 | emit = _ref.emit,
|
86 | slots = _ref.slots,
|
87 | expose = _ref.expose;
|
88 | var selectRef = (0, _vue.ref)();
|
89 | var formItemContext = (0, _FormItemContext.useInjectFormItemContext)();
|
90 |
|
91 | var focus = function focus() {
|
92 | var _a;
|
93 |
|
94 | (_a = selectRef.value) === null || _a === void 0 ? void 0 : _a.focus();
|
95 | };
|
96 |
|
97 | var blur = function blur() {
|
98 | var _a;
|
99 |
|
100 | (_a = selectRef.value) === null || _a === void 0 ? void 0 : _a.blur();
|
101 | };
|
102 |
|
103 | var scrollTo = function scrollTo(arg) {
|
104 | var _a;
|
105 |
|
106 | (_a = selectRef.value) === null || _a === void 0 ? void 0 : _a.scrollTo(arg);
|
107 | };
|
108 |
|
109 | var mode = (0, _vue.computed)(function () {
|
110 | var mode = props.mode;
|
111 |
|
112 | if (mode === 'combobox') {
|
113 | return undefined;
|
114 | }
|
115 |
|
116 | if (mode === SECRET_COMBOBOX_MODE_DO_NOT_USE) {
|
117 | return 'combobox';
|
118 | }
|
119 |
|
120 | return mode;
|
121 | });
|
122 |
|
123 | var _useConfigInject = (0, _useConfigInject2.default)('select', props),
|
124 | prefixCls = _useConfigInject.prefixCls,
|
125 | direction = _useConfigInject.direction,
|
126 | configProvider = _useConfigInject.configProvider,
|
127 | getPrefixCls = _useConfigInject.getPrefixCls;
|
128 |
|
129 | var rootPrefixCls = (0, _vue.computed)(function () {
|
130 | return getPrefixCls();
|
131 | });
|
132 | var transitionName = (0, _vue.computed)(function () {
|
133 | return (0, _transition.getTransitionName)(rootPrefixCls.value, 'slide-up', props.transitionName);
|
134 | });
|
135 | var mergedClassName = (0, _vue.computed)(function () {
|
136 | var _classNames;
|
137 |
|
138 | return (0, _classNames3.default)((_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(prefixCls.value, "-lg"), props.size === 'large'), (0, _defineProperty2.default)(_classNames, "".concat(prefixCls.value, "-sm"), props.size === 'small'), (0, _defineProperty2.default)(_classNames, "".concat(prefixCls.value, "-rtl"), direction.value === 'rtl'), (0, _defineProperty2.default)(_classNames, "".concat(prefixCls.value, "-borderless"), !props.bordered), _classNames));
|
139 | });
|
140 |
|
141 | var triggerChange = function triggerChange() {
|
142 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
143 | args[_key] = arguments[_key];
|
144 | }
|
145 |
|
146 | emit('update:value', args[0]);
|
147 | emit.apply(void 0, ['change'].concat(args));
|
148 | formItemContext.onFieldChange();
|
149 | };
|
150 |
|
151 | var handleBlur = function handleBlur(e) {
|
152 | emit('blur', e);
|
153 | formItemContext.onFieldBlur();
|
154 | };
|
155 |
|
156 | expose({
|
157 | blur: blur,
|
158 | focus: focus,
|
159 | scrollTo: scrollTo
|
160 | });
|
161 | var isMultiple = (0, _vue.computed)(function () {
|
162 | return mode.value === 'multiple' || mode.value === 'tags';
|
163 | });
|
164 | return function () {
|
165 | var _a, _b;
|
166 |
|
167 | var notFoundContent = props.notFoundContent,
|
168 | _props$listHeight = props.listHeight,
|
169 | listHeight = _props$listHeight === void 0 ? 256 : _props$listHeight,
|
170 | _props$listItemHeight = props.listItemHeight,
|
171 | listItemHeight = _props$listItemHeight === void 0 ? 24 : _props$listItemHeight,
|
172 | getPopupContainer = props.getPopupContainer,
|
173 | dropdownClassName = props.dropdownClassName,
|
174 | virtual = props.virtual,
|
175 | dropdownMatchSelectWidth = props.dropdownMatchSelectWidth,
|
176 | _props$id = props.id,
|
177 | id = _props$id === void 0 ? formItemContext.id.value : _props$id,
|
178 | _props$placeholder = props.placeholder,
|
179 | placeholder = _props$placeholder === void 0 ? (_a = slots.placeholder) === null || _a === void 0 ? void 0 : _a.call(slots) : _props$placeholder;
|
180 | var renderEmpty = configProvider.renderEmpty,
|
181 | getContextPopupContainer = configProvider.getPopupContainer;
|
182 |
|
183 | var mergedNotFound;
|
184 |
|
185 | if (notFoundContent !== undefined) {
|
186 | mergedNotFound = notFoundContent;
|
187 | } else if (slots.notFoundContent) {
|
188 | mergedNotFound = slots.notFoundContent();
|
189 | } else if (mode.value === 'combobox') {
|
190 | mergedNotFound = null;
|
191 | } else {
|
192 | mergedNotFound = renderEmpty('Select');
|
193 | }
|
194 |
|
195 |
|
196 | var _getIcons = (0, _iconUtil.default)((0, _extends2.default)((0, _extends2.default)({}, props), {
|
197 | multiple: isMultiple.value,
|
198 | prefixCls: prefixCls.value
|
199 | }), slots),
|
200 | suffixIcon = _getIcons.suffixIcon,
|
201 | itemIcon = _getIcons.itemIcon,
|
202 | removeIcon = _getIcons.removeIcon,
|
203 | clearIcon = _getIcons.clearIcon;
|
204 |
|
205 | var selectProps = (0, _omit.default)(props, ['prefixCls', 'suffixIcon', 'itemIcon', 'removeIcon', 'clearIcon', 'size', 'bordered']);
|
206 | var rcSelectRtlDropDownClassName = (0, _classNames3.default)(dropdownClassName, (0, _defineProperty2.default)({}, "".concat(prefixCls.value, "-dropdown-").concat(direction.value), direction.value === 'rtl'));
|
207 | return (0, _vue.createVNode)(_vcSelect.default, (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({
|
208 | "ref": selectRef,
|
209 | "virtual": virtual,
|
210 | "dropdownMatchSelectWidth": dropdownMatchSelectWidth
|
211 | }, selectProps), attrs), {}, {
|
212 | "placeholder": placeholder,
|
213 | "listHeight": listHeight,
|
214 | "listItemHeight": listItemHeight,
|
215 | "mode": mode.value,
|
216 | "prefixCls": prefixCls.value,
|
217 | "direction": direction.value,
|
218 | "inputIcon": suffixIcon,
|
219 | "menuItemSelectedIcon": itemIcon,
|
220 | "removeIcon": removeIcon,
|
221 | "clearIcon": clearIcon,
|
222 | "notFoundContent": mergedNotFound,
|
223 | "class": [mergedClassName.value, attrs.class],
|
224 | "getPopupContainer": getPopupContainer || getContextPopupContainer,
|
225 | "dropdownClassName": rcSelectRtlDropDownClassName,
|
226 | "onChange": triggerChange,
|
227 | "onBlur": handleBlur,
|
228 | "id": id,
|
229 | "dropdownRender": selectProps.dropdownRender || slots.dropdownRender,
|
230 | "transitionName": transitionName.value,
|
231 | "children": (_b = slots.default) === null || _b === void 0 ? void 0 : _b.call(slots),
|
232 | "tagRender": props.tagRender || slots.tagRender,
|
233 | "optionLabelRender": slots.optionLabel,
|
234 | "maxTagPlaceholder": props.maxTagPlaceholder || slots.maxTagPlaceholder
|
235 | }), {
|
236 | option: slots.option
|
237 | });
|
238 | };
|
239 | }
|
240 | });
|
241 |
|
242 |
|
243 | Select.install = function (app) {
|
244 | app.component(Select.name, Select);
|
245 | app.component(Select.Option.displayName, Select.Option);
|
246 | app.component(Select.OptGroup.displayName, Select.OptGroup);
|
247 | return app;
|
248 | };
|
249 |
|
250 | var SelectOption = Select.Option;
|
251 | exports.SelectOption = SelectOption;
|
252 | var SelectOptGroup = Select.OptGroup;
|
253 | exports.SelectOptGroup = SelectOptGroup;
|
254 | var _default = Select;
|
255 | exports.default = _default; |
\ | No newline at end of file |