@opentiny/vue-renderless 3.16.1 → 3.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/action-sheet/index.js +0 -1
  2. package/base-select/index.js +1510 -0
  3. package/base-select/vue.js +555 -0
  4. package/breadcrumb-item/vue.js +4 -2
  5. package/card/index.js +15 -0
  6. package/card/vue.js +6 -3
  7. package/carousel/index.js +89 -17
  8. package/carousel/vue.js +29 -24
  9. package/carousel-item/index.js +24 -9
  10. package/carousel-item/vue.js +10 -9
  11. package/cascader/vue.js +2 -1
  12. package/cascader-panel/index.js +8 -1
  13. package/cascader-panel/vue.js +1 -1
  14. package/cascader-select/column-index.js +11 -6
  15. package/cascader-select/column.js +8 -5
  16. package/cascader-select/usePicker.js +3 -2
  17. package/checkbox/index.js +0 -17
  18. package/checkbox/vue.js +4 -10
  19. package/collapse-item/vue.js +4 -2
  20. package/common/deps/clickoutside.js +15 -8
  21. package/common/deps/popper.js +15 -1
  22. package/common/deps/throttle.js +7 -0
  23. package/common/deps/touch-emulator.js +1 -1
  24. package/common/deps/tree-model/node.js +1 -0
  25. package/common/deps/tree-model/tree-store.js +4 -1
  26. package/common/deps/useEventListener.js +9 -2
  27. package/common/deps/useInstanceSlots.js +22 -0
  28. package/common/deps/useRelation.js +72 -0
  29. package/common/deps/vue-popper.js +1 -0
  30. package/common/function.js +28 -0
  31. package/common/index.js +1 -1
  32. package/common/runtime.js +1 -1
  33. package/common/type.js +2 -0
  34. package/dialog-box/index.js +0 -22
  35. package/dialog-box/vue.js +1 -4
  36. package/drawer/index.js +27 -29
  37. package/drawer/vue.js +6 -10
  38. package/file-upload/index.js +1 -1
  39. package/fluent-editor/index.js +679 -0
  40. package/fluent-editor/options.js +234 -0
  41. package/fluent-editor/vue.js +192 -0
  42. package/form/index.js +5 -1
  43. package/grid/utils/column.js +4 -2
  44. package/grid/utils/common.js +18 -29
  45. package/grid/utils/event.js +14 -9
  46. package/guide/index.js +6 -5
  47. package/guide/vue.js +2 -2
  48. package/input/index.js +32 -2
  49. package/input/vue.js +21 -2
  50. package/nav-menu/index.js +1 -1
  51. package/numeric/index.js +4 -1
  52. package/option/vue.js +6 -6
  53. package/package.json +1 -1
  54. package/picker/mb.js +6 -1
  55. package/picker/vue.js +2 -1
  56. package/select/index.js +65 -40
  57. package/select/vue.js +1 -1
  58. package/split/index.js +16 -9
  59. package/split/vue.js +7 -2
  60. package/statistic/index.js +7 -0
  61. package/tabs-mf/index.js +116 -13
  62. package/tabs-mf/vue-bar.js +6 -0
  63. package/tabs-mf/vue-nav-item.js +1 -1
  64. package/tabs-mf/vue.js +42 -7
  65. package/tag-group/vue.js +7 -1
  66. package/time/index.js +1 -1
  67. package/time-line/index.js +2 -2
  68. package/time-line/vue.js +4 -13
  69. package/timeline-item/index.js +5 -5
  70. package/timeline-item/vue.js +13 -6
  71. package/tree/index.js +29 -2
  72. package/tree/vue.js +5 -2
  73. package/tree-node/vue.js +2 -1
  74. package/types/cascader-menu.type.d.ts +1 -1
  75. package/types/cascader-node.type.d.ts +1 -1
  76. package/types/{cascader-panel.type-2bd03be3.d.ts → cascader-panel.type-8f58e628.d.ts} +1 -1
  77. package/types/cascader-panel.type.d.ts +1 -1
  78. package/types/cascader.type.d.ts +1 -1
  79. package/types/collapse-item.type.d.ts +3 -0
  80. package/types/dialog-box.type.d.ts +2 -6
  81. package/types/drawer.type.d.ts +28 -30
  82. package/types/form-item.type.d.ts +1 -1
  83. package/types/{form.type-8e30b25c.d.ts → form.type-33aa784a.d.ts} +4 -0
  84. package/types/form.type.d.ts +1 -1
  85. package/types/input.type.d.ts +4 -0
  86. package/types/ip-address.type.d.ts +1 -6
  87. package/types/numeric.type.d.ts +1 -0
  88. package/types/search.type.d.ts +1 -3
  89. package/types/{time-line.type-1b501c41.d.ts → time-line.type-9fb16096.d.ts} +7 -5
  90. package/types/time-line.type.d.ts +1 -1
  91. package/types/timeline-item.type.d.ts +1 -1
  92. package/user/index.js +10 -4
  93. package/year-table/index.js +5 -3
  94. package/year-table/vue.js +1 -1
  95. package/common/deps/letter-only.js +0 -19
  96. package/common/deps/number-only.js +0 -20
@@ -0,0 +1,1510 @@
1
+ import {
2
+ __spreadProps,
3
+ __spreadValues
4
+ } from "../chunk-G2ADBYYC.js";
5
+ import { find } from "../common/array";
6
+ import { getObj, isEqual } from "../common/object";
7
+ import { isKorean } from "../common/string";
8
+ import scrollIntoView from "../common/deps/scroll-into-view";
9
+ import PopupManager from "../common/deps/popup-manager";
10
+ import debounce from "../common/deps/debounce";
11
+ import { getDataset } from "../common/dataset";
12
+ import Memorize from "../common/deps/memorize";
13
+ import { isEmptyObject } from "../common/type";
14
+ import { addResizeListener, removeResizeListener } from "../common/deps/resize-event";
15
+ import { extend } from "../common/object";
16
+ import { BROWSER_NAME } from "../common";
17
+ import browserInfo from "../common/browser";
18
+ import { isNull } from "../common/type";
19
+ import { fastdom } from "../common/deps/fastdom";
20
+ import { deepClone } from "../picker-column";
21
+ import { escapeRegexpString } from "../option";
22
+ const handleComposition = ({ api, nextTick, state }) => (event) => {
23
+ const text = event.target.value;
24
+ if (event.type === "compositionend") {
25
+ state.isOnComposition = false;
26
+ const isChange = false;
27
+ const isInput = true;
28
+ nextTick(() => api.handleQueryChange(text, isChange, isInput));
29
+ } else {
30
+ const lastCharacter = text[text.length - 1] || "";
31
+ state.isOnComposition = !isKorean(lastCharacter);
32
+ }
33
+ };
34
+ const showTip = ({ props, state, vm }) => (show) => {
35
+ if (!props.showOverflowTooltip) {
36
+ return;
37
+ }
38
+ let overflow;
39
+ if (!show) {
40
+ clearTimeout(state.tipTimer);
41
+ state.tipTimer = setTimeout(() => {
42
+ state.showTip = state.tipHover;
43
+ }, vm.$refs.popover.closeDelay);
44
+ } else {
45
+ if (!props.multiple) {
46
+ const reference = vm.$refs.reference.$el;
47
+ overflow = reference.querySelector("input").scrollWidth > reference.scrollWidth;
48
+ } else {
49
+ overflow = vm.$refs.tags.scrollHeight > vm.$refs.tags.getBoundingClientRect().height;
50
+ }
51
+ state.showTip = show && overflow && !!state.tips && !state.visible;
52
+ }
53
+ };
54
+ const gridOnQueryChange = ({ props, vm, constants, state }) => (value) => {
55
+ const { multiple, valueField, filterMethod, filterable, remote, remoteMethod } = props;
56
+ if (filterable && typeof filterMethod === "function") {
57
+ const table = vm.$refs.selectGrid.$refs.tinyTable;
58
+ const fullData = table.afterFullData;
59
+ vm.$refs.selectGrid.scrollTo(null, 0);
60
+ table.afterFullData = filterMethod(value, fullData) || [];
61
+ vm.$refs.selectGrid.handleTableData(!value).then(() => state.selectEmitter.emit(constants.EVENT_NAME.updatePopper));
62
+ state.previousQuery = value;
63
+ } else if (remote && typeof remoteMethod === "function") {
64
+ state.previousQuery = value;
65
+ remoteMethod(value, props.extraQueryParams).then((data) => {
66
+ if (multiple) {
67
+ const selectedIds = state.selected.map((sel) => sel[valueField]);
68
+ vm.$refs.selectGrid.clearSelection();
69
+ vm.$refs.selectGrid.setSelection(
70
+ data.filter((row) => ~selectedIds.indexOf(row[valueField])),
71
+ true
72
+ );
73
+ state.remoteData = data.filter((row) => !~selectedIds.indexOf(row[valueField])).concat(state.selected);
74
+ } else {
75
+ vm.$refs.selectGrid.clearRadioRow();
76
+ vm.$refs.selectGrid.setRadioRow(find(data, (item) => props.modelValue === item[props.valueField]));
77
+ state.remoteData = data;
78
+ }
79
+ vm.$refs.selectGrid.$refs.tinyTable.lastScrollTop = 0;
80
+ vm.$refs.selectGrid.loadData(data);
81
+ vm.$refs.selectGrid.handleTableData(!value).then(() => state.selectEmitter.emit(constants.EVENT_NAME.updatePopper));
82
+ });
83
+ }
84
+ };
85
+ const defaultOnQueryChange = ({ props, state, constants, api, nextTick }) => (value, isInput) => {
86
+ if (props.remote && (typeof props.remoteMethod === "function" || typeof props.initQuery === "function")) {
87
+ state.hoverIndex = -1;
88
+ props.remoteMethod && props.remoteMethod(value, props.extraQueryParams);
89
+ } else if (typeof props.filterMethod === "function") {
90
+ props.filterMethod(value);
91
+ state.selectEmitter.emit(constants.COMPONENT_NAME.OptionGroup, constants.EVENT_NAME.queryChange);
92
+ } else {
93
+ api.queryChange(value, isInput);
94
+ }
95
+ setFilteredSelectCls(nextTick, state, props);
96
+ api.getOptionIndexArr();
97
+ state.magicKey = state.magicKey > 0 ? -1 : 1;
98
+ };
99
+ const queryChange = ({ props, state, constants }) => (value, isInput) => {
100
+ if (props.optimization && isInput) {
101
+ const filterDatas = state.initDatas.filter((item) => new RegExp(escapeRegexpString(value), "i").test(item.label));
102
+ state.datas = filterDatas;
103
+ } else {
104
+ state.selectEmitter.emit(constants.EVENT_NAME.queryChange, value);
105
+ }
106
+ };
107
+ const setFilteredSelectCls = (nextTick, state, props) => {
108
+ nextTick(() => {
109
+ if (props.multiple && props.showAlloption && props.filterable && state.query && !props.remote) {
110
+ const filterSelectedVal = state.options.filter((item) => item.state.visible && item.state.itemSelected).map((opt) => opt.value);
111
+ const visibleOptions = state.options.filter((item) => item.state.visible);
112
+ if (filterSelectedVal.length === visibleOptions.length) {
113
+ state.filteredSelectCls = "checked-sur";
114
+ } else if (filterSelectedVal.length === 0) {
115
+ state.filteredSelectCls = "check";
116
+ } else {
117
+ state.filteredSelectCls = "halfselect";
118
+ }
119
+ }
120
+ });
121
+ };
122
+ const handleQueryChange = ({ api, constants, nextTick, props, vm, state }) => (value, isChange = false, isInput = false) => {
123
+ if (state.previousQuery === value && !isChange || state.isOnComposition) {
124
+ return;
125
+ }
126
+ if (state.previousQuery === null && !isChange && (typeof props.filterMethod === "function" || typeof props.remoteMethod === "function" || typeof props.initQuery === "function")) {
127
+ state.previousQuery = value;
128
+ return;
129
+ }
130
+ state.query = value;
131
+ state.previousQuery = value;
132
+ window.requestAnimationFrame(() => {
133
+ if (state.visible) {
134
+ state.selectEmitter.emit(constants.EVENT_NAME.updatePopper);
135
+ state.showWarper = true;
136
+ }
137
+ });
138
+ state.hoverIndex = -1;
139
+ if (props.multiple && props.filterable && !props.shape) {
140
+ nextTick(() => {
141
+ const length = vm.$refs.input.value.length * 15 + 20;
142
+ state.inputLength = state.collapseTags ? Math.min(50, length) : length;
143
+ api.managePlaceholder();
144
+ api.resetInputHeight();
145
+ });
146
+ }
147
+ state.triggerSearch = true;
148
+ api.defaultOnQueryChange(value, isInput);
149
+ };
150
+ const scrollToOption = ({ vm, constants }) => (option) => {
151
+ const target = Array.isArray(option) && option[0] && option[0].state ? option[0].state.el : option.state ? option.state.el : "";
152
+ if (vm.$refs.popper && target) {
153
+ const menu = vm.$refs.popper.$el.querySelector(constants.CLASS.SelectDropdownWrap);
154
+ setTimeout(() => scrollIntoView(menu, target));
155
+ }
156
+ vm.$refs.scrollbar && vm.$refs.scrollbar.handleScroll();
157
+ };
158
+ const handleMenuEnter = ({ api, nextTick, state, props }) => () => {
159
+ if (!props.optimization) {
160
+ nextTick(() => api.scrollToOption(state.selected));
161
+ }
162
+ };
163
+ const emitChange = ({ emit, props, state, constants }) => (value, changed) => {
164
+ if (state.device === "mb" && props.multiple && !changed)
165
+ return;
166
+ if (!isEqual(props.modelValue, state.compareValue)) {
167
+ emit("change", value);
168
+ }
169
+ };
170
+ const directEmitChange = ({ emit, props, state }) => (value, key) => {
171
+ if (state.device === "mb" && props.multiple)
172
+ return;
173
+ emit("change", value, key);
174
+ };
175
+ const getOption = ({ props, state, api }) => (value) => {
176
+ let option;
177
+ const isObject = Object.prototype.toString.call(value).toLowerCase() === "[object object]";
178
+ const isNull2 = Object.prototype.toString.call(value).toLowerCase() === "[object null]";
179
+ const isUndefined = Object.prototype.toString.call(value).toLowerCase() === "[object undefined]";
180
+ if (state.cachedOptions.length !== 0) {
181
+ for (let i = state.cachedOptions.length - 1; i >= 0; i--) {
182
+ const cachedOption = state.cachedOptions[i];
183
+ const isEqual2 = isObject ? getObj(cachedOption.value, props.valueKey) === getObj(value, props.valueKey) : cachedOption.value === value;
184
+ if (isEqual2) {
185
+ option = cachedOption;
186
+ break;
187
+ }
188
+ }
189
+ if (option) {
190
+ return option;
191
+ }
192
+ } else if (!isEmptyObject(state.selected)) {
193
+ return state.selected;
194
+ }
195
+ if (props.optimization) {
196
+ option = api.getSelectedOption(value);
197
+ if (option) {
198
+ return { value: option.value, currentLabel: option.label || option.currentLabel };
199
+ }
200
+ option = state.datas.find((v) => getObj(v, props.valueKey) === value);
201
+ if (option) {
202
+ return { value: option.value, currentLabel: option.label || option.currentLabel };
203
+ }
204
+ }
205
+ const label = !isObject && !isNull2 && !isUndefined && !props.clearNoMatchValue ? value : "";
206
+ let newOption = { value, currentLabel: label };
207
+ if (props.multiple) {
208
+ newOption.hitState = false;
209
+ }
210
+ return newOption;
211
+ };
212
+ const getSelectedOption = ({ props, state }) => (value) => {
213
+ let option;
214
+ if (props.multiple) {
215
+ option = state.selected.find((v) => getObj(v, props.valueKey) === value);
216
+ } else {
217
+ if (!isEmptyObject(state.selected) && getObj(state.selected, props.valueKey) === value) {
218
+ option = state.selected;
219
+ }
220
+ }
221
+ return option;
222
+ };
223
+ const getOptionOfSetSelected = ({ api, props }) => {
224
+ const option = api.getOption(props.modelValue) || {};
225
+ if (!option.state) {
226
+ option.state = {};
227
+ }
228
+ if (option.created) {
229
+ option.createdLabel = option.state.currentLabel;
230
+ option.createdSelected = true;
231
+ } else {
232
+ option.createdSelected = false;
233
+ }
234
+ if (!option.currentLabel) {
235
+ api.clearNoMatchValue("");
236
+ }
237
+ return option;
238
+ };
239
+ const getResultOfSetSelected = ({ state, api, props }) => {
240
+ let result = [];
241
+ const newModelValue = [];
242
+ if (Array.isArray(state.modelValue)) {
243
+ state.modelValue.forEach((value) => {
244
+ const option = api.getOption(value);
245
+ if (!props.clearNoMatchValue || props.clearNoMatchValue && option.label) {
246
+ result.push(option);
247
+ newModelValue.push(value);
248
+ }
249
+ });
250
+ }
251
+ api.clearNoMatchValue(newModelValue);
252
+ return result;
253
+ };
254
+ const setSelected = ({ api, nextTick, props, vm, state }) => () => {
255
+ if (!props.multiple) {
256
+ const option = getOptionOfSetSelected({ api, props });
257
+ state.selected = option;
258
+ state.selectedLabel = option.state.currentLabel || option.currentLabel;
259
+ props.filterable && !props.shape && (state.query = state.selectedLabel);
260
+ } else {
261
+ const result = getResultOfSetSelected({ state, props, api });
262
+ state.selectCls = result.length ? result.length === state.options.length ? "checked-sur" : "halfselect" : "check";
263
+ if (state.selected.length === 0 || !state.selected[0].currentLabel) {
264
+ state.selected = result;
265
+ }
266
+ vm.$refs.selectTree && vm.$refs.selectTree.setCheckedNodes && vm.$refs.selectTree.setCheckedNodes(state.selected);
267
+ state.tips = state.selected.map((item) => item.state ? item.state.currentLabel : item.currentLabel).join(",");
268
+ setFilteredSelectCls(nextTick, state, props);
269
+ nextTick(api.resetInputHeight);
270
+ }
271
+ };
272
+ const getPluginOption = ({ props, state }) => (value) => {
273
+ const isRemote = props.filterable && props.remote && (typeof props.remoteMethod === "function" || typeof props.initQuery === "function");
274
+ const { textField, valueField } = props;
275
+ const sourceData = isRemote ? state.remoteData : state.gridData;
276
+ const selNode = find(sourceData, (item) => item[valueField] === value);
277
+ const items = [];
278
+ if (selNode) {
279
+ selNode.currentLabel = selNode[textField];
280
+ items.push(selNode);
281
+ }
282
+ return items;
283
+ };
284
+ const toggleCheckAll = ({ api, state }) => (filtered) => {
285
+ let value = [];
286
+ const enabledValues = state.options.filter((op) => !op.state.disabled && !op.state.groupDisabled && !op.required && op.state.visible).map((op) => op.value);
287
+ if (filtered) {
288
+ if (state.filteredSelectCls === "check" || state.filteredSelectCls === "halfselect") {
289
+ value = [.../* @__PURE__ */ new Set([...state.modelValue, ...enabledValues])];
290
+ } else {
291
+ value = state.modelValue.filter((val) => !enabledValues.includes(val));
292
+ }
293
+ } else {
294
+ if (state.selectCls === "check") {
295
+ value = enabledValues;
296
+ } else if (state.selectCls === "halfselect") {
297
+ const unchecked = state.options.filter((item) => !item.state.disabled && item.state.selectCls === "check");
298
+ unchecked.length ? value = enabledValues : value = [];
299
+ } else if (state.selectCls === "checked-sur") {
300
+ value = [];
301
+ }
302
+ }
303
+ const requiredValue = state.options.filter((op) => op.required).map((op) => op.value);
304
+ const disabledSelectedValues = state.options.filter((op) => (op.state.disabled || op.state.groupDisabled) && op.state.selectCls === "checked-sur").map((op) => op.value);
305
+ value = [...value, ...requiredValue, ...disabledSelectedValues];
306
+ api.setSoftFocus();
307
+ state.isSilentBlur = true;
308
+ api.updateModelValue(value);
309
+ api.directEmitChange(value);
310
+ };
311
+ const handleFocus = ({ emit, props, state }) => (event) => {
312
+ if (!state.softFocus) {
313
+ if (props.automaticDropdown || props.filterable) {
314
+ state.visible = true;
315
+ state.softFocus = true;
316
+ }
317
+ emit("focus", event);
318
+ } else {
319
+ if (state.searchSingleCopy && state.selectedLabel) {
320
+ emit("focus", event);
321
+ }
322
+ state.softFocus = false;
323
+ }
324
+ };
325
+ const focus = ({ vm, state }) => () => {
326
+ if (!state.softFocus) {
327
+ vm.$refs.reference.focus();
328
+ }
329
+ };
330
+ const blur = ({ vm, state }) => () => {
331
+ state.visible = false;
332
+ vm.$refs.reference.blur();
333
+ };
334
+ const handleBlur = ({ constants, dispatch, emit, state, designConfig }) => (event) => {
335
+ var _a;
336
+ clearTimeout(state.timer);
337
+ state.timer = setTimeout(() => {
338
+ var _a2;
339
+ if (state.isSilentBlur) {
340
+ state.isSilentBlur = false;
341
+ } else {
342
+ emit("blur", event);
343
+ }
344
+ if ((_a2 = designConfig == null ? void 0 : designConfig.state) == null ? void 0 : _a2.delayBlur) {
345
+ dispatch(constants.COMPONENT_NAME.FormItem, constants.EVENT_NAME.formBlur, event.target.value);
346
+ }
347
+ }, 200);
348
+ if (!((_a = designConfig == null ? void 0 : designConfig.state) == null ? void 0 : _a.delayBlur)) {
349
+ dispatch(constants.COMPONENT_NAME.FormItem, constants.EVENT_NAME.formBlur, event.target.value);
350
+ }
351
+ state.softFocus = false;
352
+ };
353
+ const handleClearClick = (api) => (event) => {
354
+ api.deleteSelected(event);
355
+ };
356
+ const doDestroy = (vm) => () => {
357
+ var _a;
358
+ if ((_a = vm == null ? void 0 : vm.$refs) == null ? void 0 : _a.popper) {
359
+ vm.$refs.popper.doDestroy();
360
+ }
361
+ };
362
+ const handleClose = (state) => () => {
363
+ state.visible = false;
364
+ };
365
+ const toggleLastOptionHitState = ({ state }) => (hit) => {
366
+ if (!Array.isArray(state.selected)) {
367
+ return;
368
+ }
369
+ const option = state.selected[state.selected.length - 1];
370
+ if (!option) {
371
+ return;
372
+ }
373
+ if (option.required) {
374
+ return true;
375
+ }
376
+ const hitTarget = option.state || option;
377
+ if (hit === true || hit === false) {
378
+ hitTarget.hitState = hit;
379
+ return hit;
380
+ }
381
+ hitTarget.hitState = !hitTarget.hitState;
382
+ return hitTarget.hitState;
383
+ };
384
+ const deletePrevTag = ({ api, state }) => (event) => {
385
+ if (event.target.value.length <= 0 && !api.toggleLastOptionHitState()) {
386
+ const value = state.modelValue.slice();
387
+ value.pop();
388
+ state.compareValue = deepClone(value);
389
+ api.updateModelValue(value);
390
+ api.emitChange(value);
391
+ }
392
+ };
393
+ const managePlaceholder = ({ vm, state }) => () => {
394
+ if (state.currentPlaceholder !== "") {
395
+ state.currentPlaceholder = vm.$refs.input.value ? "" : state.cachedPlaceHolder;
396
+ }
397
+ };
398
+ const resetInputState = ({ api, vm, state }) => (event) => {
399
+ if (event.keyCode !== 8) {
400
+ api.toggleLastOptionHitState(false);
401
+ }
402
+ state.inputLength = vm.$refs.input.value.length * 15 + 20;
403
+ api.resetInputHeight();
404
+ };
405
+ const resetInputHeight = ({ constants, nextTick, props, vm, state, api, designConfig }) => () => {
406
+ if (state.collapseTags && !props.filterable) {
407
+ return;
408
+ }
409
+ nextTick(() => {
410
+ var _a;
411
+ if (!vm.$refs.reference) {
412
+ return;
413
+ }
414
+ let input = vm.$refs.reference.type === "text" && vm.$refs.reference.$el.querySelector("input");
415
+ const tags = vm.$refs.tags;
416
+ const limitText = vm.$refs.reference.$el.querySelector("span.tiny-select__limit-txt");
417
+ if (!input) {
418
+ return;
419
+ }
420
+ if (!state.isDisplayOnly && (props.hoverExpand || props.clickExpand) && !props.disabled) {
421
+ api.calcCollapseTags();
422
+ }
423
+ const sizeInMap = (designConfig == null ? void 0 : designConfig.state.initialInputHeight) || state.initialInputHeight || (state.isSaaSTheme ? 28 : 30);
424
+ const noSelected = state.selected.length === 0;
425
+ const spacingHeight = designConfig ? (_a = designConfig.state) == null ? void 0 : _a.spacingHeight : constants.SPACING_HEIGHT;
426
+ if (!state.isDisplayOnly) {
427
+ if (!noSelected && tags) {
428
+ fastdom.measure(() => {
429
+ const tagsClientHeight = tags.clientHeight;
430
+ fastdom.mutate(() => {
431
+ input.style.height = Math.max(tagsClientHeight + spacingHeight, sizeInMap) + "px";
432
+ });
433
+ });
434
+ } else {
435
+ input.style.height = noSelected ? sizeInMap + "px" : Math.max(0, sizeInMap) + "px";
436
+ }
437
+ } else {
438
+ input.style.height = "auto";
439
+ }
440
+ if (limitText && props.multipleLimit) {
441
+ const { width, marginLeft, marginRight } = getComputedStyle(limitText);
442
+ vm.$refs.tags.style.paddingRight = `${Math.ceil(
443
+ parseFloat(width) + parseFloat(marginLeft) + parseFloat(marginRight)
444
+ )}px`;
445
+ }
446
+ if (state.visible && state.emptyText !== false) {
447
+ state.selectEmitter.emit(constants.EVENT_NAME.updatePopper, true);
448
+ }
449
+ });
450
+ };
451
+ const resetHoverIndex = ({ props, state }) => () => {
452
+ if (!props.showOverflowTooltip) {
453
+ state.hoverIndex = -1;
454
+ } else if (!props.multiple) {
455
+ state.hoverIndex = state.options.indexOf(state.selected);
456
+ } else {
457
+ if (state.selected.length > 0) {
458
+ state.hoverIndex = Math.min.apply(
459
+ null,
460
+ state.selected.map((item) => state.options.indexOf(item))
461
+ );
462
+ } else {
463
+ state.hoverIndex = -1;
464
+ }
465
+ }
466
+ };
467
+ const resetDatas = ({ props, state }) => () => {
468
+ if (props.optimization && !props.remote && !props.filterMethod) {
469
+ state.datas = state.initDatas;
470
+ }
471
+ };
472
+ const handleOptionSelect = ({ api, nextTick, props, vm, state }) => (option, byClick) => {
473
+ state.memorize && state.memorize.updateByKey(option[state.memorize._dataKey] || option.value);
474
+ if (props.multiple) {
475
+ const value = (state.modelValue || []).slice();
476
+ const optionIndex = api.getValueIndex(value, option.value);
477
+ if (optionIndex > -1) {
478
+ value.splice(optionIndex, 1);
479
+ } else if (state.multipleLimit <= 0 || value.length < state.multipleLimit) {
480
+ value.push(option.value);
481
+ }
482
+ state.compareValue = deepClone(value);
483
+ api.updateModelValue(value);
484
+ api.emitChange(value);
485
+ if (option.created) {
486
+ const isChange = false;
487
+ const isInput = true;
488
+ state.query = "";
489
+ api.handleQueryChange("", isChange, isInput);
490
+ state.inputLength = 20;
491
+ }
492
+ if (props.filterable) {
493
+ vm.$refs.input.focus();
494
+ }
495
+ if (props.autoClose) {
496
+ state.visible = false;
497
+ }
498
+ } else {
499
+ state.compareValue = deepClone(option.value);
500
+ api.updateModelValue(option.value);
501
+ api.emitChange(option.value);
502
+ if (option.created) {
503
+ state.createdSelected = true;
504
+ state.createdLabel = option.value;
505
+ }
506
+ state.visible = false;
507
+ }
508
+ state.isSilentBlur = byClick;
509
+ api.setSoftFocus();
510
+ if (state.visible) {
511
+ return;
512
+ }
513
+ nextTick(() => {
514
+ api.scrollToOption(option);
515
+ });
516
+ };
517
+ const initValue = ({ state }) => (vm) => {
518
+ const isExist = state.initValue.find((val) => val === vm.value);
519
+ !isExist && state.initValue.push(vm.value);
520
+ };
521
+ const setSoftFocus = ({ vm, state }) => () => {
522
+ state.softFocus = true;
523
+ const input = vm.$refs.input || vm.$refs.reference;
524
+ if (input) {
525
+ input.focus();
526
+ }
527
+ state.softFocus = false;
528
+ };
529
+ const getValueIndex = (props) => (arr = [], value = null) => {
530
+ const isObject = Object.prototype.toString.call(value).toLowerCase() === "[object object]";
531
+ if (!isObject) {
532
+ return arr.indexOf(value);
533
+ } else {
534
+ const valueKey = props.valueKey;
535
+ let index = -1;
536
+ arr.some((item, i) => {
537
+ if (getObj(item, valueKey) === getObj(value, valueKey)) {
538
+ index = i;
539
+ return true;
540
+ }
541
+ return false;
542
+ });
543
+ return index;
544
+ }
545
+ };
546
+ const toggleMenu = ({ vm, state, props, api }) => (e) => {
547
+ if (props.keepFocus && state.visible && props.filterable) {
548
+ return;
549
+ }
550
+ const event = e || window.event;
551
+ const enterCode = 13;
552
+ const nodeName = event.target && event.target.nodeName;
553
+ const toggleVisible = props.ignoreEnter ? event.keyCode !== enterCode && nodeName === "INPUT" : true;
554
+ if (!props.displayOnly) {
555
+ event.stopPropagation();
556
+ }
557
+ if (!state.selectDisabled) {
558
+ toggleVisible && !state.softFocus && (state.visible = !state.visible);
559
+ state.softFocus = false;
560
+ if (state.visible) {
561
+ if (!(props.filterable && props.shape)) {
562
+ const dom = vm.$refs.input || vm.$refs.reference;
563
+ (dom == null ? void 0 : dom.focus) && dom.focus();
564
+ api.setOptionHighlight();
565
+ }
566
+ }
567
+ }
568
+ };
569
+ const selectOption = ({ api, state, props }) => (e) => {
570
+ if (!state.visible || props.hideDrop) {
571
+ api.toggleMenu(e);
572
+ } else {
573
+ let option = "";
574
+ if (state.query || props.remote) {
575
+ option = state.options.find((item) => item.state.index === state.hoverValue);
576
+ } else {
577
+ option = state.options[state.hoverIndex];
578
+ }
579
+ option && api.handleOptionSelect(option);
580
+ }
581
+ };
582
+ const deleteSelected = ({ api, emit, props, state }) => (event) => {
583
+ event && event.stopPropagation();
584
+ let selectedValue = [];
585
+ if (props.multiple) {
586
+ const requireOptions = state.options.filter((opt) => opt.required && opt.value);
587
+ selectedValue = state.modelValue.slice().filter((v) => requireOptions.find((opt) => opt.value === v));
588
+ }
589
+ const value = props.multiple ? selectedValue : "";
590
+ state.showTip = false;
591
+ state.compareValue = deepClone(value);
592
+ api.updateModelValue(value, true);
593
+ api.emitChange(value, true);
594
+ state.visible = false;
595
+ emit("clear");
596
+ };
597
+ const deleteTag = ({ api, constants, emit, props, state, nextTick, vm }) => (event, tag) => {
598
+ if (tag.required)
599
+ return;
600
+ const index = state.selected.indexOf(tag);
601
+ if (index > -1 && !state.selectDisabled) {
602
+ const value = state.modelValue.slice();
603
+ value.splice(index, 1);
604
+ state.compareValue = deepClone(value);
605
+ api.updateModelValue(value);
606
+ api.emitChange(value);
607
+ emit(constants.EVENT_NAME.removeTag, tag[props.valueField]);
608
+ nextTick(() => state.key++);
609
+ }
610
+ event && event.stopPropagation();
611
+ };
612
+ const onInputChange = ({ api, props, state, constants, nextTick }) => () => {
613
+ if (!props.delay) {
614
+ if (props.filterable && state.query !== state.selectedLabel) {
615
+ const isChange = false;
616
+ const isInput = true;
617
+ state.query = state.selectedLabel;
618
+ api.handleQueryChange(state.query, isChange, isInput);
619
+ nextTick(() => {
620
+ state.selectEmitter.emit(constants.EVENT_NAME.updatePopper);
621
+ });
622
+ }
623
+ } else {
624
+ api.debouncRquest();
625
+ }
626
+ nextTick(() => {
627
+ state.selectEmitter.emit(constants.EVENT_NAME.updatePopper);
628
+ });
629
+ };
630
+ const onOptionDestroy = (state) => (index) => {
631
+ if (index > -1) {
632
+ state.optionsCount--;
633
+ state.filteredOptionsCount--;
634
+ state.options.splice(index, 1);
635
+ }
636
+ };
637
+ const resetInputWidth = ({ vm, state }) => () => {
638
+ if (vm.$refs.reference && vm.$refs.reference.$el) {
639
+ state.inputWidth = vm.$refs.reference.$el.getBoundingClientRect().width;
640
+ }
641
+ };
642
+ const handleResize = ({ api, props, state }) => () => {
643
+ api.resetInputWidth();
644
+ if (props.multiple && !state.isDisplayOnly) {
645
+ api.resetInputHeight();
646
+ }
647
+ };
648
+ const setOptionHighlight = (state) => () => {
649
+ for (let i = 0; i < state.options.length; ++i) {
650
+ const option = state.options[i];
651
+ if (!option.disabled && !option.groupDisabled && !option.state.created && option.state.visible && option.state.itemSelected) {
652
+ state.hoverIndex = i;
653
+ break;
654
+ }
655
+ }
656
+ };
657
+ const checkDefaultFirstOption = (state) => () => {
658
+ state.hoverIndex = -1;
659
+ let hasCreated = false;
660
+ const visibleOptions = state.options.filter((item) => item.visible && item.state.visible);
661
+ for (let i = visibleOptions.length - 1; i >= 0; i--) {
662
+ if (visibleOptions[i].created) {
663
+ hasCreated = true;
664
+ state.hoverIndex = i;
665
+ state.hoverValue = state.optionIndexArr[i];
666
+ break;
667
+ }
668
+ }
669
+ if (hasCreated) {
670
+ return;
671
+ }
672
+ for (let i = 0; i < visibleOptions.length; i++) {
673
+ const option = visibleOptions[i];
674
+ if (state.query) {
675
+ if (!option.disabled && !option.groupDisabled && option.state.visible && option.visible) {
676
+ state.hoverIndex = i;
677
+ state.hoverValue = state.optionIndexArr[i];
678
+ break;
679
+ }
680
+ } else {
681
+ if (option.itemSelected) {
682
+ state.hoverIndex = i;
683
+ state.hoverValue = state.optionIndexArr[i];
684
+ break;
685
+ }
686
+ }
687
+ }
688
+ };
689
+ const getValueKey = (props) => (item) => {
690
+ if (!item)
691
+ return;
692
+ if (Object.prototype.toString.call(item.value).toLowerCase() !== "[object object]") {
693
+ return item.value || item[props.valueField];
694
+ }
695
+ return getObj(item.value, props.valueKey);
696
+ };
697
+ const navigateOptions = ({ api, state, props, nextTick }) => (direction) => {
698
+ const { optimization } = props;
699
+ if (optimization) {
700
+ return;
701
+ }
702
+ const len = state.options.filter((item) => item.visible && item.state.visible).length;
703
+ if (!state.visible) {
704
+ state.visible = true;
705
+ return;
706
+ }
707
+ if (len === 0 || state.filteredOptionsCount === 0) {
708
+ return;
709
+ }
710
+ state.disabledOptionHover = true;
711
+ setTimeout(() => {
712
+ state.disabledOptionHover = false;
713
+ }, 100);
714
+ if (state.hoverIndex < -1 || state.hoverIndex >= len) {
715
+ state.hoverIndex = 0;
716
+ }
717
+ if (!state.optionsAllDisabled) {
718
+ if (direction === "next") {
719
+ state.hoverIndex++;
720
+ if (state.hoverIndex === len) {
721
+ state.hoverIndex = 0;
722
+ }
723
+ } else if (direction === "prev") {
724
+ state.hoverIndex--;
725
+ if (state.hoverIndex < 0) {
726
+ state.hoverIndex = len - 1;
727
+ }
728
+ }
729
+ let option = {};
730
+ state.hoverValue = state.optionIndexArr[state.hoverIndex];
731
+ if (state.query || props.remote) {
732
+ option = state.options.find((item) => item.state.index === state.hoverValue);
733
+ } else {
734
+ option = state.options[state.hoverIndex];
735
+ }
736
+ if (option.disabled === true || option.groupDisabled === true || !option.state.visible || option.state.limitReached) {
737
+ api.navigateOptions(direction);
738
+ }
739
+ nextTick(() => api.scrollToOption(state.hoverIndex === -9 ? {} : option || {}));
740
+ }
741
+ };
742
+ const emptyFlag = ({ props, state }) => () => {
743
+ if (props.optimization) {
744
+ if (props.allowCreate) {
745
+ return state.query === "" && state.datas.length === 0;
746
+ } else {
747
+ return state.datas.length === 0;
748
+ }
749
+ } else {
750
+ return state.options.length === 0;
751
+ }
752
+ };
753
+ const recycleScrollerHeight = ({ state, props, recycle }) => () => {
754
+ const { ITEM_HEIGHT, SAFE_MARGIN, SAAS_HEIGHT, AURORA_HEIGHT } = recycle;
755
+ let length = state.datas.length;
756
+ if (state.showNewOption) {
757
+ length += 1;
758
+ }
759
+ if (length === 0 || props.loading) {
760
+ return 0;
761
+ } else if (length < 6) {
762
+ return length * ITEM_HEIGHT + (state.isSaaSTheme ? SAFE_MARGIN * 2 : 0);
763
+ } else {
764
+ return state.isSaaSTheme ? SAAS_HEIGHT : AURORA_HEIGHT;
765
+ }
766
+ };
767
+ const emptyText = ({ I18N, props, state, t, isMobileFirstMode }) => () => {
768
+ if (props.loading) {
769
+ return props.loadingText || t(I18N.loading);
770
+ }
771
+ if (props.remote && state.query === "" && props.renderType) {
772
+ return remoteEmptyText(props, state);
773
+ }
774
+ if (props.remote && state.query === "" && state.emptyFlag && !state.triggerSearch) {
775
+ return props.shape === "filter" || isMobileFirstMode ? "" : false;
776
+ }
777
+ if (props.filterable && state.query && (props.remote && state.emptyFlag || !state.options.some((option) => option.visible && option.state.visible))) {
778
+ return props.noMatchText || t(I18N.noMatch);
779
+ }
780
+ if (state.emptyFlag) {
781
+ return props.noDataText || t(I18N.noData);
782
+ }
783
+ return null;
784
+ };
785
+ const remoteEmptyText = function(props, state) {
786
+ if (props.multiple) {
787
+ return state.selected.length > 0 || state.remoteData.length >= 0;
788
+ }
789
+ return state.selected[props.valueField] || state.remoteData.length >= 0;
790
+ };
791
+ const watchValue = ({ api, constants, dispatch, props, vm, state }) => (value, oldValue) => {
792
+ if (props.multiple) {
793
+ api.resetInputHeight();
794
+ if (value && value.length > 0 || vm.$refs.input && state.query !== "") {
795
+ state.currentPlaceholder = "";
796
+ } else {
797
+ state.currentPlaceholder = state.cachedPlaceHolder;
798
+ }
799
+ if (props.filterable && !props.reserveKeyword) {
800
+ !props.searchable && (state.query = "");
801
+ }
802
+ }
803
+ api.setSelected();
804
+ !state.isClickChoose && api.initQuery({ init: true }).then(() => api.setSelected());
805
+ state.isClickChoose = false;
806
+ if (props.filterable && !props.multiple) {
807
+ state.inputLength = 20;
808
+ }
809
+ if (state.completed && !isEqual(value, oldValue)) {
810
+ dispatch(constants.COMPONENT_NAME.FormItem, constants.EVENT_NAME.formChange, value);
811
+ }
812
+ props.optimization && optmzApis.setValueIndex({ props, state });
813
+ };
814
+ const calcOverFlow = ({ vm, props, state }) => (height) => {
815
+ if (props.multiple && props.showOverflowTooltip) {
816
+ state.overflow = false;
817
+ const tagDom = vm.$refs.tags;
818
+ const tags = tagDom.querySelectorAll('[data-tag="tiny-tag"]');
819
+ if (tags.length) {
820
+ tagDom.scrollTo && tagDom.scrollTo({ top: 0 });
821
+ let { x, width } = tags[0].getBoundingClientRect();
822
+ if (width >= tagDom.getBoundingClientRect().width) {
823
+ state.overflow = 0;
824
+ } else {
825
+ for (let i = 1; i < tags.length; i++) {
826
+ let tx = tags[i].getBoundingClientRect().x;
827
+ if (tx === x) {
828
+ state.overflow = i - 1;
829
+ break;
830
+ }
831
+ }
832
+ }
833
+ }
834
+ vm.$refs.select.style.height = vm.$refs.select.style.height || height;
835
+ vm.$refs.reference.$el.style.position = "absolute";
836
+ const inputWidth = vm.$refs.select.getBoundingClientRect().width;
837
+ const position = state.visible ? "absolute" : "";
838
+ state.selectFiexd = {
839
+ height,
840
+ position,
841
+ width: inputWidth + "px",
842
+ zIndex: PopupManager.nextZIndex()
843
+ };
844
+ state.inputWidth = inputWidth;
845
+ }
846
+ };
847
+ const postOperOfToVisible = ({ props, state, constants }) => {
848
+ if (props.multiple) {
849
+ return;
850
+ }
851
+ if (state.selected) {
852
+ if (props.filterable && props.allowCreate && state.createdSelected && state.createdLabel) {
853
+ state.selectedLabel = state.createdLabel;
854
+ } else {
855
+ state.selectedLabel = state.selected.state.currentLabel || state.selected.currentLabel;
856
+ }
857
+ if (props.filterable) {
858
+ state.query = state.selectedLabel;
859
+ }
860
+ if (props.filterable) {
861
+ state.currentPlaceholder = state.cachedPlaceHolder;
862
+ }
863
+ }
864
+ };
865
+ const toVisible = ({ constants, state, props, vm, api, nextTick }) => () => {
866
+ state.selectEmitter.emit(constants.EVENT_NAME.destroyPopper);
867
+ props.remote && props.dropOnlySearch && (state.showWarper = false);
868
+ if (vm.$refs.input) {
869
+ vm.$refs.input.blur();
870
+ }
871
+ state.query = "";
872
+ state.selectedLabel = "";
873
+ state.inputLength = 20;
874
+ state.previousQuery !== state.query && api.initQuery().then(() => api.setSelected());
875
+ state.previousQuery = null;
876
+ api.resetHoverIndex();
877
+ api.resetDatas();
878
+ nextTick(() => {
879
+ if (vm.$refs.input && vm.$refs.input.value === "" && state.selected.length === 0) {
880
+ state.currentPlaceholder = state.cachedPlaceHolder;
881
+ }
882
+ if (vm.$refs.selectGrid) {
883
+ vm.$refs.selectGrid.clearScroll();
884
+ }
885
+ });
886
+ postOperOfToVisible({ props, state, constants });
887
+ };
888
+ const toHide = ({ constants, state, props, vm, api }) => () => {
889
+ const { filterable, remote, remoteConfig, shape, multiple, valueField } = props;
890
+ state.selectEmitter.emit(constants.COMPONENT_NAME.SelectDropdown, constants.EVENT_NAME.updatePopper);
891
+ if (filterable) {
892
+ state.query = remote || shape ? "" : state.selectedLabel;
893
+ const isChange = remote && remoteConfig.autoSearch && (state.firstAutoSearch || remoteConfig.clearData);
894
+ state.firstAutoSearch = false;
895
+ api.handleQueryChange(state.query, isChange);
896
+ if (multiple) {
897
+ vm.$refs.input.focus();
898
+ } else {
899
+ if (!remote) {
900
+ state.selectEmitter.emit(constants.EVENT_NAME.queryChange, "");
901
+ state.selectEmitter.emit(constants.COMPONENT_NAME.OptionGroup, constants.EVENT_NAME.queryChange);
902
+ }
903
+ if (state.selectedLabel && !shape) {
904
+ state.currentPlaceholder = state.selectedLabel;
905
+ state.selectedLabel = "";
906
+ }
907
+ }
908
+ }
909
+ if (vm.$refs.selectGrid) {
910
+ let { fullData } = vm.$refs.selectGrid.getTableData();
911
+ if (multiple) {
912
+ const selectedIds = state.selected.map((sel) => sel[valueField]);
913
+ vm.$refs.selectGrid.clearSelection();
914
+ vm.$refs.selectGrid.setSelection(
915
+ fullData.filter((row) => ~selectedIds.indexOf(row[valueField])),
916
+ true
917
+ );
918
+ } else {
919
+ vm.$refs.selectGrid.clearRadioRow();
920
+ vm.$refs.selectGrid.setRadioRow(find(fullData, (item) => props.modelValue === item[valueField]));
921
+ }
922
+ if (filterable && typeof props.filterMethod === "function") {
923
+ vm.$refs.selectGrid.handleTableData(true);
924
+ } else if (filterable && remote && (typeof props.remoteMethod === "function" || typeof props.initQuery === "function")) {
925
+ vm.$refs.selectGrid.handleTableData();
926
+ }
927
+ }
928
+ };
929
+ const watchVisible = ({ api, constants, emit, state, vm, props }) => (value) => {
930
+ if ((props.filterable || props.remote) && !value) {
931
+ vm.$refs.reference.blur();
932
+ }
933
+ if (api.onCopying()) {
934
+ return;
935
+ }
936
+ if (value && props.multiple && state.device === "mb") {
937
+ state.selectedCopy = state.selected.slice();
938
+ }
939
+ setTimeout(() => {
940
+ if (!value && !state.selectedLabel) {
941
+ state.cachedOptions.forEach((item) => {
942
+ item.state.visible = true;
943
+ });
944
+ }
945
+ }, 200);
946
+ value ? api.toHide() : api.toVisible();
947
+ emit(constants.EVENT_NAME.visibleChange, value);
948
+ setTimeout(() => {
949
+ state.selectEmitter.emit(constants.EVENT_NAME.updatePopper);
950
+ if (value && vm.$refs.scrollbar) {
951
+ if (props.optimization) {
952
+ optmzApis.setScrollTop({ refs: vm.$refs, state });
953
+ vm.$refs.scrollbar.updateVisibleItems(true, true);
954
+ } else {
955
+ vm.$refs.scrollbar.handleScroll();
956
+ }
957
+ }
958
+ }, props.updateDelay);
959
+ if (!value && props.shape === "filter") {
960
+ state.softFocus = false;
961
+ }
962
+ };
963
+ const watchOptions = ({ api, constants, nextTick, parent, props, state }) => () => {
964
+ if (typeof window === "undefined") {
965
+ return;
966
+ }
967
+ nextTick(() => {
968
+ state.selectEmitter.emit(constants.EVENT_NAME.updatePopper);
969
+ });
970
+ if (props.multiple) {
971
+ api.resetInputHeight();
972
+ }
973
+ nextTick(() => {
974
+ if (parent.$el.querySelector("input") !== document.activeElement) {
975
+ api.setSelected();
976
+ }
977
+ });
978
+ api.getOptionIndexArr();
979
+ };
980
+ const getOptionIndexArr = ({ props, state, api }) => () => {
981
+ setTimeout(() => {
982
+ state.optionIndexArr = api.queryVisibleOptions().map((item) => Number(item.getAttribute("data-index")));
983
+ if (props.defaultFirstOption && (props.filterable || props.remote) && state.filteredOptionsCount) {
984
+ if (props.optimization) {
985
+ optmzApis.checkDefaultFirstOption({ state });
986
+ } else {
987
+ api.checkDefaultFirstOption();
988
+ }
989
+ }
990
+ });
991
+ };
992
+ const queryVisibleOptions = ({ props, vm, isMobileFirstMode }) => () => {
993
+ if (props.optimization) {
994
+ return optmzApis.queryVisibleOptions(vm, isMobileFirstMode);
995
+ } else {
996
+ return vm.$refs.scrollbar ? Array.from(vm.$refs.scrollbar.$el.querySelectorAll('[data-index]:not([style*="display: none"])')) : [];
997
+ }
998
+ };
999
+ const handleCopyClick = ({ parent, props, state }) => () => {
1000
+ const input = document.createElement("input");
1001
+ input.style.height = 0;
1002
+ input.style.border = "none";
1003
+ input.style.position = "absolute";
1004
+ parent.$el.appendChild(input);
1005
+ input.value = state.selected.map((item) => item.state ? item.state.currentLabel : item.currentLabel).join(props.textSplit);
1006
+ input.select();
1007
+ document.execCommand("copy");
1008
+ parent.$el.removeChild(input);
1009
+ };
1010
+ const getcheckedData = ({ props, state }) => () => {
1011
+ const checkedKey = [];
1012
+ if (!Array.isArray(state.selected)) {
1013
+ return props.modelValue ? [props.modelValue] : [state.selected[props.valueField]];
1014
+ } else {
1015
+ state.selected.length > 0 && state.selected.forEach((item) => {
1016
+ checkedKey.push(item[props.valueField]);
1017
+ });
1018
+ return checkedKey;
1019
+ }
1020
+ };
1021
+ const debouncRquest = ({ api, state, props }) => debounce(props.delay, () => {
1022
+ if (props.filterable && state.query !== state.selectedLabel) {
1023
+ const isChange = false;
1024
+ const isInput = true;
1025
+ state.query = state.selectedLabel;
1026
+ api.handleQueryChange(state.query, isChange, isInput);
1027
+ }
1028
+ });
1029
+ const getChildValue = () => (data, key) => {
1030
+ const ids = [];
1031
+ const getChild = (nodes) => {
1032
+ nodes.forEach((node) => {
1033
+ ids.push(node.data[key]);
1034
+ if (node.childNodes.length > 0) {
1035
+ getChild(node.childNodes);
1036
+ }
1037
+ });
1038
+ };
1039
+ getChild(data);
1040
+ return ids;
1041
+ };
1042
+ const watchPropsOption = ({ constants, parent, props, state }) => () => {
1043
+ const dataset = {
1044
+ dataset: props.options || props.dataset,
1045
+ service: parent.$service
1046
+ };
1047
+ getDataset(dataset).then((data) => {
1048
+ let sortData = data.slice();
1049
+ if (props.multiple) {
1050
+ const requiredData = [];
1051
+ sortData = sortData.filter((item) => {
1052
+ if (item.required) {
1053
+ requiredData.push(item);
1054
+ return false;
1055
+ }
1056
+ return true;
1057
+ });
1058
+ sortData = requiredData.concat(sortData);
1059
+ }
1060
+ if (props.cacheOp && props.cacheOp.key) {
1061
+ state.memorize = new Memorize(props.cacheOp);
1062
+ state.datas = state.memorize.assemble(sortData.slice());
1063
+ } else {
1064
+ state.datas = sortData;
1065
+ state.initDatas = sortData;
1066
+ }
1067
+ });
1068
+ };
1069
+ const onMouseenterNative = ({ state }) => () => {
1070
+ state.inputHovering = true;
1071
+ if (state.searchSingleCopy && state.selectedLabel) {
1072
+ state.softFocus = true;
1073
+ }
1074
+ };
1075
+ const onMouseleaveNative = ({ state }) => (e) => {
1076
+ if (e.target === e.currentTarget)
1077
+ return;
1078
+ state.inputHovering = false;
1079
+ if (state.searchSingleCopy && state.selectedLabel) {
1080
+ state.softFocus = false;
1081
+ }
1082
+ };
1083
+ const onCopying = ({ state, vm }) => () => {
1084
+ return state.searchSingleCopy && state.selectedLabel && vm.$refs.reference && vm.$refs.reference.hasSelection && vm.$refs.reference.hasSelection();
1085
+ };
1086
+ const watchHoverIndex = ({ state }) => (value) => {
1087
+ if (value === -1 || value === -9) {
1088
+ state.hoverValue = -1;
1089
+ } else {
1090
+ state.hoverValue = state.optionIndexArr[value];
1091
+ }
1092
+ };
1093
+ const handleDropdownClick = ({ vm, state, props, emit }) => ($event) => {
1094
+ if (props.allowCopy && vm.$refs.reference) {
1095
+ vm.$refs.reference.$el.querySelector("input").selectionEnd = 0;
1096
+ }
1097
+ state.softFocus = false;
1098
+ emit("dropdown-click", $event);
1099
+ };
1100
+ const handleEnterTag = ({ state }) => ($event, key) => {
1101
+ const target = $event.target;
1102
+ if (target && target.scrollWidth > target.offsetWidth) {
1103
+ state.tooltipContent = __spreadProps(__spreadValues({}, state.tooltipContent), { [key]: target.innerText });
1104
+ }
1105
+ };
1106
+ const calcCollapseTags = ({ state, vm, props }) => () => {
1107
+ if (state.inputHovering && !props.clickExpand) {
1108
+ return state.isHidden = true;
1109
+ }
1110
+ const tags = vm.$refs.tags;
1111
+ const collapseTag = tags && tags.querySelector('[data-tag="tags-collapse"]');
1112
+ if (!collapseTag || !tags) {
1113
+ return;
1114
+ }
1115
+ const { width: tagsContentWidth, paddingLeft, paddingRight } = window.getComputedStyle(tags);
1116
+ const tagsWidth = parseFloat(tagsContentWidth) - parseFloat(paddingLeft) - parseFloat(paddingRight);
1117
+ const { width: collapseTagContentWidth, marginRight } = collapseTag && window.getComputedStyle(collapseTag);
1118
+ const collapseTagWidth = collapseTag && parseFloat(collapseTagContentWidth) + parseFloat(marginRight);
1119
+ const tagList = Array.from(tags.querySelectorAll('[data-tag="tiny-tag"]'));
1120
+ let [dom, idx, currentRowWidth, currentTagIndex] = [null, 0, 0, 0];
1121
+ for (let rowNum = 0; rowNum < props.maxVisibleRows; rowNum++) {
1122
+ currentRowWidth = 0;
1123
+ let currentTagWidth = 0;
1124
+ for (currentTagIndex; currentTagIndex < tagList.length; currentTagIndex++) {
1125
+ const tag = tagList[currentTagIndex];
1126
+ if (tag !== collapseTag) {
1127
+ const { width: tagContentWidth, marginRight: marginRight2, marginLeft } = tag && window.getComputedStyle(tag);
1128
+ currentTagWidth = parseFloat(tagContentWidth) + parseFloat(marginRight2) + parseFloat(marginLeft);
1129
+ currentRowWidth += currentTagWidth;
1130
+ }
1131
+ if (tag !== collapseTag && currentRowWidth > tagsWidth) {
1132
+ if (!dom && rowNum === props.maxVisibleRows - 1) {
1133
+ if (currentRowWidth - currentTagWidth + collapseTagWidth < tagsWidth) {
1134
+ dom = tag;
1135
+ idx = currentTagIndex;
1136
+ } else {
1137
+ dom = tagList[currentTagIndex - 1];
1138
+ idx = currentTagIndex - 1;
1139
+ }
1140
+ }
1141
+ break;
1142
+ }
1143
+ }
1144
+ if (currentTagIndex === tagList.length - 1) {
1145
+ break;
1146
+ }
1147
+ }
1148
+ if (idx === 0) {
1149
+ state.exceedMaxVisibleRow = false;
1150
+ state.showCollapseTag = false;
1151
+ return state.isHidden = true;
1152
+ }
1153
+ if (dom) {
1154
+ dom.before(collapseTag);
1155
+ state.isHidden = false;
1156
+ } else {
1157
+ state.isHidden = true;
1158
+ }
1159
+ state.collapseTagsLength = tagList.length - idx;
1160
+ state.exceedMaxVisibleRow = true;
1161
+ state.toHideIndex = idx;
1162
+ };
1163
+ const watchInputHover = ({ vm }) => (newVal) => {
1164
+ const [inputHovering, visible] = newVal;
1165
+ if (!inputHovering && !visible) {
1166
+ const tags = vm.$refs.tags;
1167
+ const content = vm.$refs["tags-content"];
1168
+ tags && content && tags.scrollTo({ top: content });
1169
+ }
1170
+ };
1171
+ const initQuery = ({ props, state, constants, vm }) => ({ init } = {}) => {
1172
+ const isRemote = props.filterable && props.remote && (typeof props.remoteMethod === "function" || typeof props.initQuery === "function");
1173
+ let selected;
1174
+ if (isRemote && props.initQuery) {
1175
+ let initData = props.initQuery(props.modelValue, props.extraQueryParams, !!init);
1176
+ if (initData.then) {
1177
+ return new Promise((resolve) => {
1178
+ initData.then((selected2) => {
1179
+ state.remoteData = selected2;
1180
+ vm.$refs.selectGrid.loadData(selected2);
1181
+ resolve(selected2);
1182
+ });
1183
+ });
1184
+ }
1185
+ selected = initData;
1186
+ state.remoteData = selected;
1187
+ vm.$refs.selectGrid.loadData(selected);
1188
+ }
1189
+ return Promise.resolve(selected);
1190
+ };
1191
+ const mounted = ({ api, parent, state, props, vm, designConfig }) => () => {
1192
+ var _a;
1193
+ state.defaultCheckedKeys = state.gridCheckedData;
1194
+ const parentEl = parent.$el;
1195
+ const inputEl = parentEl.querySelector('input[data-tag="tiny-input-inner"]');
1196
+ const inputClientRect = inputEl && inputEl.getBoundingClientRect() || {};
1197
+ if (inputEl === document.activeElement) {
1198
+ document.activeElement.blur();
1199
+ }
1200
+ state.completed = true;
1201
+ const defaultSizeMap = { default: 28, mini: 24, small: 32, medium: 40 };
1202
+ const sizeMap = ((_a = designConfig == null ? void 0 : designConfig.state) == null ? void 0 : _a.sizeMap) || defaultSizeMap;
1203
+ if (props.multiple && Array.isArray(props.modelValue) && props.modelValue.length > 0) {
1204
+ state.currentPlaceholder = "";
1205
+ }
1206
+ state.initialInputHeight = state.isDisplayOnly ? sizeMap[state.selectSize || "default"] : inputClientRect.height || sizeMap[state.selectSize];
1207
+ addResizeListener(parentEl, api.handleResize);
1208
+ if (vm.$refs.tags) {
1209
+ addResizeListener(vm.$refs.tags, api.resetInputHeight);
1210
+ }
1211
+ if (props.remote && props.multiple) {
1212
+ api.resetInputHeight();
1213
+ }
1214
+ state.inputWidth = inputClientRect.width;
1215
+ api.initQuery({ init: true }).then(() => api.setSelected());
1216
+ if (props.dataset) {
1217
+ api.watchPropsOption();
1218
+ }
1219
+ };
1220
+ const unMount = ({ api, parent, vm, state }) => () => {
1221
+ if (parent.$el && api.handleResize) {
1222
+ removeResizeListener(parent.$el, api.handleResize);
1223
+ }
1224
+ if (vm.$refs.tags) {
1225
+ removeResizeListener(vm.$refs.tags, api.resetInputHeight);
1226
+ }
1227
+ state.popperElm = null;
1228
+ };
1229
+ const optmzApis = {
1230
+ exist: (val, multiple) => multiple ? Array.isArray(val) && val.length : val,
1231
+ getValueIndex: (props) => {
1232
+ const { options, valueField, modelValue, multiple } = props;
1233
+ const contain = (val, arr) => Array.isArray(arr) && ~arr.indexOf(val);
1234
+ const equal = (val, opt) => multiple ? contain(opt[valueField], [val]) : opt[valueField] === val;
1235
+ let start = 0;
1236
+ if (optmzApis.exist(modelValue, multiple) && options) {
1237
+ const lastVal = multiple ? modelValue[modelValue.length - 1] : modelValue;
1238
+ for (let i = 0; i < options.length; i++) {
1239
+ if (!equal(lastVal, options[i]))
1240
+ continue;
1241
+ return i;
1242
+ }
1243
+ }
1244
+ return start;
1245
+ },
1246
+ queryVisibleOptions: (vm, isMobileFirstMode) => {
1247
+ const querySelectKey = isMobileFirstMode ? ".cursor-not-allowed" : ".is-disabled";
1248
+ return Array.from(
1249
+ vm.$refs.scrollbar.$el.querySelectorAll(
1250
+ '.tiny-recycle-scroller__slot, .tiny-recycle-scroller__item-view:not([style*="transform: translateY(-9999px) translateX(0px)"])'
1251
+ )
1252
+ ).map((item) => item.querySelector(`[data-tag="tiny-select-dropdown-item"]:not(${querySelectKey})`)).filter((v) => v);
1253
+ },
1254
+ setScrollTop: ({ refs, state }) => {
1255
+ const { optimizeStore } = state;
1256
+ refs.scrollbar.scrollToItem(optimizeStore.valueIndex);
1257
+ },
1258
+ setValueIndex: ({ props, state }) => {
1259
+ state.optimizeStore.valueIndex = optmzApis.getValueIndex(props);
1260
+ },
1261
+ natural: (val) => val < 0 ? 0 : val,
1262
+ checkDefaultFirstOption: ({ state }) => {
1263
+ state.hoverIndex = 0;
1264
+ state.hoverValue = state.optionIndexArr[0];
1265
+ }
1266
+ };
1267
+ const computeOptimizeOpts = ({ props, designConfig }) => () => {
1268
+ const { optimization } = props;
1269
+ const baseOpts = (designConfig == null ? void 0 : designConfig.baseOpts) ? designConfig.baseOpts : { gt: 20, rSize: 10, optionHeight: 30, limit: 20 };
1270
+ let optOpts;
1271
+ if (optimization) {
1272
+ if (typeof optimization === "boolean") {
1273
+ optOpts = extend(true, {}, baseOpts);
1274
+ } else {
1275
+ optOpts = extend(true, {}, baseOpts, optimization);
1276
+ }
1277
+ return optOpts;
1278
+ }
1279
+ };
1280
+ const watchOptimizeOpts = ({ props, state }) => () => {
1281
+ const { optimizeOpts, optimizeStore } = state;
1282
+ if (optimizeOpts) {
1283
+ if (props.optimization) {
1284
+ optimizeStore.valueIndex = optmzApis.getValueIndex(props);
1285
+ }
1286
+ }
1287
+ };
1288
+ const computeCollapseTags = (props) => () => props.collapseTags;
1289
+ const computeMultipleLimit = ({ props, state }) => () => {
1290
+ const { multipleLimit, multiple, optimization } = props;
1291
+ const { optimizeOpts } = state;
1292
+ return optmzApis.natural(multiple && optimization ? multipleLimit || optimizeOpts.limit : multipleLimit);
1293
+ };
1294
+ const updateModelValue = ({ props, emit, state }) => (value, needUpdate) => {
1295
+ state.isClickChoose = true;
1296
+ if (state.device === "mb" && props.multiple && !needUpdate) {
1297
+ state.modelValue = value;
1298
+ } else {
1299
+ emit("update:modelValue", value);
1300
+ }
1301
+ };
1302
+ const getLabelSlotValue = ({ props, state }) => (item) => {
1303
+ const datas = state.datas;
1304
+ const value = item.state ? item.state.currentValue : item.value;
1305
+ const data = datas.find((data2) => data2.value === value);
1306
+ const obj = __spreadProps(__spreadValues({}, data), {
1307
+ label: item.state ? item.state.currentLabel : item.currentLabel,
1308
+ value
1309
+ });
1310
+ return obj;
1311
+ };
1312
+ const computedTagsStyle = ({ props, parent, state, vm }) => () => {
1313
+ const isReadonly = props.disabled || (parent.form || {}).disabled || props.displayOnly;
1314
+ let tagsStyle = {
1315
+ "max-width": isReadonly ? "" : state.inputWidth - state.inputPaddingRight + "px",
1316
+ width: "100%"
1317
+ };
1318
+ if (props.clickExpand && !state.exceedMaxVisibleRow || state.visible) {
1319
+ Object.assign(tagsStyle, { height: "auto" });
1320
+ }
1321
+ if (props.clickExpand && state.exceedMaxVisibleRow && !state.showCollapseTag) {
1322
+ const tags = vm.$refs.tags;
1323
+ const { paddingTop: tagsPaddingTop, paddingBottom: tagsPaddingBottom } = window.getComputedStyle(tags);
1324
+ const tagsPaddingVertical = parseFloat(tagsPaddingTop) + parseFloat(tagsPaddingBottom);
1325
+ const tag = tags == null ? void 0 : tags.querySelector('[data-tag="tiny-tag"]');
1326
+ if (tag) {
1327
+ const { height: tagHeight, marginTop, marginBottom } = window.getComputedStyle(tag);
1328
+ const rowHeight = (parseFloat(tagHeight) + parseFloat(marginTop) + parseFloat(marginBottom)) * props.maxVisibleRows;
1329
+ Object.assign(tagsStyle, { "height": `${rowHeight + tagsPaddingVertical}px` });
1330
+ }
1331
+ }
1332
+ return tagsStyle;
1333
+ };
1334
+ const computedReadonly = ({ props, state }) => () => state.device === "mb" || props.readonly || !props.filterable || props.multiple || browserInfo.name !== BROWSER_NAME.IE && browserInfo.name !== BROWSER_NAME.Edge && !state.visible;
1335
+ const computedShowClose = ({ props, state }) => () => props.clearable && !state.selectDisabled && (state.inputHovering || props.multiple && state.visible) && (props.multiple ? Array.isArray(props.modelValue) && props.modelValue.length > 0 : !isNull(props.modelValue) && props.modelValue !== "");
1336
+ const computedCollapseTagSize = (state) => () => state.selectSize;
1337
+ const computedShowNewOption = ({ props, state }) => () => {
1338
+ const query = state.device === "mb" ? state.queryValue : state.query;
1339
+ return props.filterable && props.allowCreate && query && !state.options.filter((option) => !option.created).some((option) => option.state.currentLabel === state.query);
1340
+ };
1341
+ const computedShowCopy = ({ props, state }) => () => props.multiple && props.copyable && state.inputHovering && state.selected.length;
1342
+ const computedOptionsAllDisabled = (state) => () => state.options.filter((option) => option.visible).every((option) => option.disabled);
1343
+ const computedDisabledTooltipContent = (state) => () => state.selected.map((item) => item.state ? item.state.currentLabel : item.currentLabel).join("\uFF1B");
1344
+ const computedSelectDisabled = ({ props, parent }) => () => props.disabled || (parent.form || {}).disabled || props.displayOnly || (parent.form || {}).displayOnly;
1345
+ const computedIsExpand = ({ props, state }) => () => {
1346
+ const hoverExpanded = (state.selectHover || state.visible) && props.hoverExpand && !props.disabled;
1347
+ const clickExpanded = props.clickExpand && state.exceedMaxVisibleRow && state.showCollapseTag;
1348
+ return hoverExpanded || clickExpanded;
1349
+ };
1350
+ const watchInitValue = ({ props, emit }) => (value) => {
1351
+ if (props.multiple) {
1352
+ let modelValue = props.modelValue.slice();
1353
+ value.forEach((val) => {
1354
+ modelValue = modelValue.filter((item) => item !== val);
1355
+ });
1356
+ emit("update:modelValue", value.concat(modelValue));
1357
+ }
1358
+ };
1359
+ const watchShowClose = ({ nextTick, state, parent }) => () => {
1360
+ nextTick(() => {
1361
+ const parentEl = parent.$el;
1362
+ const inputEl = parentEl.querySelector('input[data-tag="tiny-input-inner"]');
1363
+ if (inputEl) {
1364
+ const { paddingRight } = getComputedStyle(inputEl);
1365
+ state.inputPaddingRight = parseFloat(paddingRight);
1366
+ }
1367
+ });
1368
+ };
1369
+ const computedGetIcon = ({ designConfig, props }) => () => {
1370
+ return props.dropdownIcon ? { icon: props.dropdownIcon } : {
1371
+ icon: (designConfig == null ? void 0 : designConfig.icons.dropdownIcon) || "icon-delta-down",
1372
+ isDefault: true
1373
+ };
1374
+ };
1375
+ const computedGetTagType = ({ designConfig, props }) => () => {
1376
+ var _a;
1377
+ if (((_a = designConfig == null ? void 0 : designConfig.props) == null ? void 0 : _a.tagType) && !props.tagType) {
1378
+ return designConfig.props.tagType;
1379
+ }
1380
+ return props.tagType;
1381
+ };
1382
+ const clearSearchText = ({ state, api }) => () => {
1383
+ state.query = "";
1384
+ state.previousQuery = void 0;
1385
+ api.handleQueryChange(state.query);
1386
+ };
1387
+ const clearNoMatchValue = ({ props, emit }) => (newModelValue) => {
1388
+ if (!props.clearNoMatchValue) {
1389
+ return;
1390
+ }
1391
+ if (props.multiple && props.modelValue.length !== newModelValue.length || !props.multiple && props.modelValue !== newModelValue) {
1392
+ emit("update:modelValue", newModelValue);
1393
+ }
1394
+ };
1395
+ const handleDebouncedQueryChange = ({ state, api }) => debounce(state.debounce, (value) => {
1396
+ api.handleQueryChange(value);
1397
+ });
1398
+ const onClickCollapseTag = ({ state, props, nextTick, api }) => (event) => {
1399
+ event.stopPropagation();
1400
+ if (props.clickExpand && !props.disabled && !state.isDisplayOnly) {
1401
+ state.showCollapseTag = !state.showCollapseTag;
1402
+ nextTick(api.resetInputHeight);
1403
+ }
1404
+ };
1405
+ const updateSelectedData = ({ state }) => (data) => {
1406
+ state.selected = data;
1407
+ };
1408
+ const hidePanel = ({ state }) => () => {
1409
+ state.visible = false;
1410
+ };
1411
+ export {
1412
+ blur,
1413
+ calcCollapseTags,
1414
+ calcOverFlow,
1415
+ checkDefaultFirstOption,
1416
+ clearNoMatchValue,
1417
+ clearSearchText,
1418
+ computeCollapseTags,
1419
+ computeMultipleLimit,
1420
+ computeOptimizeOpts,
1421
+ computedCollapseTagSize,
1422
+ computedDisabledTooltipContent,
1423
+ computedGetIcon,
1424
+ computedGetTagType,
1425
+ computedIsExpand,
1426
+ computedOptionsAllDisabled,
1427
+ computedReadonly,
1428
+ computedSelectDisabled,
1429
+ computedShowClose,
1430
+ computedShowCopy,
1431
+ computedShowNewOption,
1432
+ computedTagsStyle,
1433
+ debouncRquest,
1434
+ defaultOnQueryChange,
1435
+ deletePrevTag,
1436
+ deleteSelected,
1437
+ deleteTag,
1438
+ directEmitChange,
1439
+ doDestroy,
1440
+ emitChange,
1441
+ emptyFlag,
1442
+ emptyText,
1443
+ focus,
1444
+ getChildValue,
1445
+ getLabelSlotValue,
1446
+ getOption,
1447
+ getOptionIndexArr,
1448
+ getPluginOption,
1449
+ getSelectedOption,
1450
+ getValueIndex,
1451
+ getValueKey,
1452
+ getcheckedData,
1453
+ gridOnQueryChange,
1454
+ handleBlur,
1455
+ handleClearClick,
1456
+ handleClose,
1457
+ handleComposition,
1458
+ handleCopyClick,
1459
+ handleDebouncedQueryChange,
1460
+ handleDropdownClick,
1461
+ handleEnterTag,
1462
+ handleFocus,
1463
+ handleMenuEnter,
1464
+ handleOptionSelect,
1465
+ handleQueryChange,
1466
+ handleResize,
1467
+ hidePanel,
1468
+ initQuery,
1469
+ initValue,
1470
+ managePlaceholder,
1471
+ mounted,
1472
+ navigateOptions,
1473
+ onClickCollapseTag,
1474
+ onCopying,
1475
+ onInputChange,
1476
+ onMouseenterNative,
1477
+ onMouseleaveNative,
1478
+ onOptionDestroy,
1479
+ queryChange,
1480
+ queryVisibleOptions,
1481
+ recycleScrollerHeight,
1482
+ resetDatas,
1483
+ resetHoverIndex,
1484
+ resetInputHeight,
1485
+ resetInputState,
1486
+ resetInputWidth,
1487
+ scrollToOption,
1488
+ selectOption,
1489
+ setOptionHighlight,
1490
+ setSelected,
1491
+ setSoftFocus,
1492
+ showTip,
1493
+ toHide,
1494
+ toVisible,
1495
+ toggleCheckAll,
1496
+ toggleLastOptionHitState,
1497
+ toggleMenu,
1498
+ unMount,
1499
+ updateModelValue,
1500
+ updateSelectedData,
1501
+ watchHoverIndex,
1502
+ watchInitValue,
1503
+ watchInputHover,
1504
+ watchOptimizeOpts,
1505
+ watchOptions,
1506
+ watchPropsOption,
1507
+ watchShowClose,
1508
+ watchValue,
1509
+ watchVisible
1510
+ };