@opentiny/vue-search-box 0.0.1

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 (74) hide show
  1. package/README.md +111 -0
  2. package/es/composables/use-checkbox.es.js +87 -0
  3. package/es/composables/use-custom.es.js +48 -0
  4. package/es/composables/use-datepicker.es.js +86 -0
  5. package/es/composables/use-dropdown.es.js +207 -0
  6. package/es/composables/use-edit.es.js +106 -0
  7. package/es/composables/use-init.es.js +64 -0
  8. package/es/composables/use-match.es.js +170 -0
  9. package/es/composables/use-num-range.es.js +77 -0
  10. package/es/composables/use-placeholder.es.js +41 -0
  11. package/es/composables/use-tag.es.js +51 -0
  12. package/es/index-DCPOFFNd.css +337 -0
  13. package/es/index.es.js +10 -0
  14. package/es/index.type.es.js +1 -0
  15. package/es/index.vue.es.js +4 -0
  16. package/es/index.vue.es2.js +1287 -0
  17. package/es/smb-theme.es.js +18 -0
  18. package/es/utils/clone.es.js +29 -0
  19. package/es/utils/date.es.js +431 -0
  20. package/es/utils/dropdown.es.js +20 -0
  21. package/es/utils/en_US.es.js +44 -0
  22. package/es/utils/index.es.js +13 -0
  23. package/es/utils/tag.es.js +46 -0
  24. package/es/utils/type.es.js +4 -0
  25. package/es/utils/validate.es.js +179 -0
  26. package/es/utils/zh_CN.es.js +44 -0
  27. package/index.css +337 -0
  28. package/lib/composables/use-checkbox.cjs.js +87 -0
  29. package/lib/composables/use-custom.cjs.js +48 -0
  30. package/lib/composables/use-datepicker.cjs.js +86 -0
  31. package/lib/composables/use-dropdown.cjs.js +207 -0
  32. package/lib/composables/use-edit.cjs.js +106 -0
  33. package/lib/composables/use-init.cjs.js +64 -0
  34. package/lib/composables/use-match.cjs.js +170 -0
  35. package/lib/composables/use-num-range.cjs.js +77 -0
  36. package/lib/composables/use-placeholder.cjs.js +41 -0
  37. package/lib/composables/use-tag.cjs.js +51 -0
  38. package/lib/index-DCPOFFNd.css +337 -0
  39. package/lib/index.cjs.js +10 -0
  40. package/lib/index.type.cjs.js +1 -0
  41. package/lib/index.vue.cjs.js +4 -0
  42. package/lib/index.vue.cjs2.js +1287 -0
  43. package/lib/smb-theme.cjs.js +18 -0
  44. package/lib/utils/clone.cjs.js +29 -0
  45. package/lib/utils/date.cjs.js +431 -0
  46. package/lib/utils/dropdown.cjs.js +20 -0
  47. package/lib/utils/en_US.cjs.js +44 -0
  48. package/lib/utils/index.cjs.js +13 -0
  49. package/lib/utils/tag.cjs.js +46 -0
  50. package/lib/utils/type.cjs.js +4 -0
  51. package/lib/utils/validate.cjs.js +179 -0
  52. package/lib/utils/zh_CN.cjs.js +44 -0
  53. package/package.json +65 -0
  54. package/types/composables/use-checkbox.d.ts +10 -0
  55. package/types/composables/use-custom.d.ts +7 -0
  56. package/types/composables/use-datepicker.d.ts +11 -0
  57. package/types/composables/use-dropdown.d.ts +13 -0
  58. package/types/composables/use-edit.d.ts +13 -0
  59. package/types/composables/use-init.d.ts +10 -0
  60. package/types/composables/use-match.d.ts +8 -0
  61. package/types/composables/use-num-range.d.ts +9 -0
  62. package/types/composables/use-placeholder.d.ts +8 -0
  63. package/types/composables/use-tag.d.ts +9 -0
  64. package/types/index.type.d.ts +189 -0
  65. package/types/smb-theme.d.ts +15 -0
  66. package/types/utils/clone.d.ts +12 -0
  67. package/types/utils/date.d.ts +234 -0
  68. package/types/utils/dropdown.d.ts +12 -0
  69. package/types/utils/en_US.d.ts +41 -0
  70. package/types/utils/index.d.ts +1 -0
  71. package/types/utils/tag.d.ts +46 -0
  72. package/types/utils/type.d.ts +6 -0
  73. package/types/utils/validate.d.ts +31 -0
  74. package/types/utils/zh_CN.d.ts +41 -0
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const dropdown = require("../utils/dropdown.cjs.js");
4
+ const validate = require("../utils/validate.cjs.js");
5
+ const tag = require("../utils/tag.cjs.js");
6
+ function useDatePicker({ props, state, emits }) {
7
+ const { instance } = state;
8
+ const onConfirmDate = async (confirm, isDateTimeType = false) => {
9
+ if (!confirm) {
10
+ state.propItem.label = "";
11
+ return;
12
+ }
13
+ const newTag = await validate.getVerifyDateTag(instance, state, props, isDateTimeType);
14
+ if (newTag) {
15
+ const newValue = props.modelValue.filter((prev) => prev.type !== newTag.type || prev.field !== newTag.field);
16
+ newValue.push(newTag);
17
+ tag.emitChangeModelEvent({ emits, state, newValue });
18
+ dropdown.showDropdown(state, false);
19
+ } else {
20
+ dropdown.showDropdown(state);
21
+ }
22
+ };
23
+ const handleDateShow = () => dropdown.showDropdown(state);
24
+ const pickerOptions = (startDate, endName = "") => ({
25
+ disabledDate(time) {
26
+ const { maxTimeLength = 0, min, max } = state.prevItem;
27
+ const endDate = state[endName];
28
+ const curTime = time.getTime();
29
+ if (maxTimeLength > 0) {
30
+ if (min || max) {
31
+ if (endName && endDate) {
32
+ const end = new Date(endDate).getTime();
33
+ const start = !min && max ? end - maxTimeLength : Math.max(min.getTime(), end - maxTimeLength);
34
+ return curTime < start || curTime > end;
35
+ } else if (!endName && startDate) {
36
+ const start = new Date(startDate).getTime();
37
+ const end = min && !max ? start + maxTimeLength : Math.min(max.getTime(), start + maxTimeLength);
38
+ return curTime < start || curTime > end;
39
+ } else {
40
+ return min && curTime < min.getTime() || max && curTime > max.getTime();
41
+ }
42
+ } else {
43
+ if (endName && endDate) {
44
+ const end = new Date(endDate).getTime();
45
+ const start = end - maxTimeLength;
46
+ return curTime < start || curTime > end;
47
+ } else if (!endName && startDate) {
48
+ const start = new Date(startDate).getTime();
49
+ const end = start + maxTimeLength;
50
+ return curTime < start || curTime > end;
51
+ } else {
52
+ return false;
53
+ }
54
+ }
55
+ } else {
56
+ if (min || max) {
57
+ if (endName && endDate) {
58
+ const end = new Date(endDate).getTime();
59
+ return min && curTime < min.getTime() || curTime > end;
60
+ } else if (!endName && startDate) {
61
+ const start = new Date(startDate).getTime();
62
+ return curTime < start || max && curTime > max.getTime();
63
+ } else {
64
+ return curTime < min || curTime > max;
65
+ }
66
+ } else {
67
+ if (endName && endDate) {
68
+ const end = new Date(endDate).getTime();
69
+ return curTime > end;
70
+ } else if (!endName && startDate) {
71
+ const start = new Date(startDate).getTime();
72
+ return curTime < start;
73
+ } else {
74
+ return false;
75
+ }
76
+ }
77
+ }
78
+ }
79
+ });
80
+ return {
81
+ onConfirmDate,
82
+ handleDateShow,
83
+ pickerOptions
84
+ };
85
+ }
86
+ exports.useDatePicker = useDatePicker;
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tag = require("../utils/tag.cjs.js");
4
+ const dropdown = require("../utils/dropdown.cjs.js");
5
+ const validate = require("../utils/validate.cjs.js");
6
+ const clone = require("../utils/clone.cjs.js");
7
+ function useDropdown({ props, emits, state, t, format }) {
8
+ const { instance } = state;
9
+ const showValueItem = (item) => {
10
+ var _a;
11
+ const { start, end, type } = item;
12
+ state.backupList = ((_a = item.options) == null ? void 0 : _a.length) ? item.options : [];
13
+ if (type === "numRange") {
14
+ validate.setStateNumRange(state, item, t);
15
+ state.hiden = false;
16
+ } else if (type === "dateRange") {
17
+ const { dateRangeFormat } = state;
18
+ if (!state.startDate && start) {
19
+ const newStart = format(start, dateRangeFormat);
20
+ state.startDate = state.endDate < newStart ? null : newStart;
21
+ }
22
+ if (!state.endDate && end) {
23
+ const newEnd = format(end, dateRangeFormat);
24
+ state.endDate = newEnd < state.startDate ? null : newEnd;
25
+ }
26
+ state.hiden = false;
27
+ } else if (type === "datetimeRange") {
28
+ const { datetimeRangeFormat } = state;
29
+ if (!state.startDateTime && start) {
30
+ const newStart = format(start, datetimeRangeFormat);
31
+ state.startDateTime = state.endDateTime < newStart ? null : newStart;
32
+ }
33
+ if (!state.endDateTime && end) {
34
+ const newEnd = format(end, datetimeRangeFormat);
35
+ state.endDateTime = newEnd < state.startDateTime ? null : newEnd;
36
+ }
37
+ state.hiden = false;
38
+ } else if (state.backupList && type === "checkbox") {
39
+ state.filterList = state.backupList;
40
+ state.checkboxGroup = [];
41
+ state.backupList.forEach((subItem) => {
42
+ if (tag.hasTagItem(state, subItem.label)) {
43
+ state.checkboxGroup.push(`${item.label}${subItem.label}`);
44
+ }
45
+ subItem.isFilter = false;
46
+ });
47
+ state.hiden = false;
48
+ } else if (type === "custom") {
49
+ state.hiden = false;
50
+ }
51
+ if (state.backupList.length && type !== "checkbox") {
52
+ state.backupList.forEach((option) => {
53
+ option.isFilter = false;
54
+ option.isChecked = tag.hasTagItem(state, option.label);
55
+ });
56
+ }
57
+ state.currentOperators = null;
58
+ if (!((type === "radio" || !type) && !state.backupList.length)) {
59
+ dropdown.showDropdown(state);
60
+ }
61
+ };
62
+ const selectPropItem = (item) => {
63
+ const { field, label } = item;
64
+ state.propItem.label = label;
65
+ emits("first-level-select", field);
66
+ const inputRef = instance.refs.inputRef;
67
+ state.prevItem = item;
68
+ state.backupPrevItem = item;
69
+ const { operators } = item;
70
+ if (operators == null ? void 0 : operators.length) {
71
+ state.operatorValue = "";
72
+ state.currentOperators = operators;
73
+ state.isResetFlag = true;
74
+ dropdown.showDropdown(state);
75
+ } else {
76
+ state.operatorValue = ":";
77
+ showValueItem(item);
78
+ }
79
+ state.inputValue = "";
80
+ inputRef.focus();
81
+ };
82
+ const setOperator = (operator) => {
83
+ state.operatorValue = operator;
84
+ showValueItem(state.prevItem);
85
+ };
86
+ const updateModelValue = (prevItem, item, label, value) => {
87
+ const { replace, operators, mergeTag } = prevItem;
88
+ const rest = clone.omitObj(prevItem);
89
+ const { indexMap } = state;
90
+ const index = indexMap.get(label);
91
+ const id = tag.getTagId(props, prevItem, item);
92
+ const operator = state.operatorValue && operators ? { operator: state.operatorValue } : null;
93
+ let newTag = null;
94
+ if (mergeTag) {
95
+ const options = { label: value, ...id };
96
+ if (index >= 0) {
97
+ const newValue2 = `${state.innerModelValue[index].value} | ${value}`;
98
+ const newOptions = [...state.innerModelValue[index].options, options];
99
+ newTag = tag.createNewTag({ ...state.innerModelValue[index], value: newValue2, options: newOptions });
100
+ } else {
101
+ newTag = tag.createNewTag({ ...rest, label, value, options: [options] });
102
+ }
103
+ } else {
104
+ newTag = tag.createNewTag({ ...rest, label, value, ...id, ...operator });
105
+ }
106
+ if (tag.hasTagItem(state, value, label)) {
107
+ tag.resetInput(state);
108
+ return;
109
+ }
110
+ const oldValue = clone.deepClone(state.innerModelValue);
111
+ if ((replace || mergeTag) && index >= 0) {
112
+ state.innerModelValue.splice(index, 1);
113
+ }
114
+ state.innerModelValue.push(newTag);
115
+ const newValue = state.innerModelValue;
116
+ tag.emitChangeModelEvent({ emits, state, newValue, oldValue });
117
+ };
118
+ const selectRadioItem = (item, isPotential = false) => {
119
+ if (isPotential) {
120
+ state.prevItem = item;
121
+ state.backupPrevItem = item;
122
+ }
123
+ const { prevItem } = state;
124
+ const value = item.value || item.label;
125
+ const inputRef = instance.refs.inputRef;
126
+ if (!tag.hasTagItem(state, value)) {
127
+ const tagLabel = state.propItem.label || item.label;
128
+ updateModelValue(prevItem, item, tagLabel, value);
129
+ }
130
+ inputRef.focus();
131
+ };
132
+ const hasNotInputValueCreateTag = (propItem, prevItem) => {
133
+ if (propItem.label) {
134
+ if (!prevItem.options) {
135
+ return;
136
+ }
137
+ const hasTag = props.modelValue.find((item) => item.value === prevItem.options[0].label);
138
+ if (!hasTag) {
139
+ const label = prevItem.label;
140
+ const value = prevItem.options && prevItem.options[0].label;
141
+ updateModelValue(prevItem, prevItem.options[0], label, value);
142
+ return;
143
+ }
144
+ } else {
145
+ emits("search", state.innerModelValue);
146
+ }
147
+ };
148
+ const newTagUpdateModelValue = (prevItem, propItem, tag2) => {
149
+ const item = state.backupList.find((subItem) => subItem.label === tag2);
150
+ updateModelValue(prevItem, item, propItem.label, tag2);
151
+ };
152
+ const hasInputValueCreateTag = (inputValue, propItem, prevItem) => {
153
+ var _a;
154
+ if (propItem.label) {
155
+ const { regexp, replace, type, mergeTag } = prevItem;
156
+ const tagList = type !== "checkbox" && replace || type === "checkbox" && mergeTag ? [inputValue] : inputValue.split(props.splitInputValue);
157
+ if (regexp) {
158
+ for (const tag2 of tagList) {
159
+ if (regexp.test(tag2)) {
160
+ newTagUpdateModelValue(prevItem, propItem, tag2);
161
+ }
162
+ }
163
+ } else {
164
+ for (const tag2 of tagList) {
165
+ newTagUpdateModelValue(prevItem, propItem, tag2);
166
+ }
167
+ }
168
+ } else {
169
+ const { items, defaultField } = props;
170
+ const currentItem = defaultField ? items.find((item) => item.field === defaultField) : state.allTypeAttri;
171
+ const { replace, type, mergeTag } = currentItem;
172
+ const tagList = type !== "checkbox" && replace || type === "checkbox" && mergeTag ? [inputValue] : inputValue.split(props.splitInputValue);
173
+ if ((_a = currentItem == null ? void 0 : currentItem.options) == null ? void 0 : _a.length) {
174
+ state.backupList = [...currentItem.options];
175
+ state.backupList.forEach((item) => {
176
+ const label2 = item.value || item.label;
177
+ if (tagList.includes(label2)) {
178
+ item.isChecked = true;
179
+ }
180
+ });
181
+ }
182
+ const label = currentItem.label;
183
+ for (const tag2 of tagList) {
184
+ updateModelValue(currentItem, {}, label, tag2);
185
+ }
186
+ }
187
+ };
188
+ const createTag = () => {
189
+ const { inputValue, propItem, prevItem } = state;
190
+ dropdown.showDropdown(state, false);
191
+ if (!inputValue) {
192
+ hasNotInputValueCreateTag(propItem, prevItem);
193
+ } else {
194
+ const { maxlength } = props;
195
+ if (maxlength && maxlength < inputValue.length) {
196
+ emits("exceed", maxlength);
197
+ return;
198
+ }
199
+ hasInputValueCreateTag(inputValue, propItem, prevItem);
200
+ }
201
+ };
202
+ const helpClick = () => {
203
+ emits("help");
204
+ };
205
+ return { selectPropItem, selectRadioItem, createTag, helpClick, setOperator };
206
+ }
207
+ exports.useDropdown = useDropdown;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tag = require("../utils/tag.cjs.js");
4
+ const validate = require("../utils/validate.cjs.js");
5
+ const dropdown = require("../utils/dropdown.cjs.js");
6
+ function useEdit({ props, state, t, nextTick, format, emits }) {
7
+ const { instance } = state;
8
+ const setDropdownProps = (curTag) => {
9
+ var _a;
10
+ const { operator, value, start, end } = curTag;
11
+ const { options, operators, type, mergeTag } = state.prevItem;
12
+ if (type === "custom") {
13
+ return;
14
+ } else if (type === "numRange") {
15
+ validate.setStateNumRange(state, curTag, t);
16
+ } else if (type === "dateRange") {
17
+ const { dateRangeFormat } = state;
18
+ state.startDate = format(start, dateRangeFormat);
19
+ state.endDate = format(end, dateRangeFormat);
20
+ } else if (type === "datetimeRange") {
21
+ const { datetimeRangeFormat } = state;
22
+ state.startDateTime = format(start, datetimeRangeFormat);
23
+ state.endDateTime = format(end, datetimeRangeFormat);
24
+ } else {
25
+ if (mergeTag) {
26
+ state.inputEditValue = (_a = curTag.options) == null ? void 0 : _a.flatMap((item) => item.label);
27
+ state.currentEditSelectTags = state.inputEditValue;
28
+ } else {
29
+ state.inputEditValue = value;
30
+ }
31
+ state.currentEditValue = options;
32
+ }
33
+ state.operatorValue = operator;
34
+ state.currentOperators = operators;
35
+ };
36
+ const editTag = (tag2, index, e) => {
37
+ if (!props.editable || tag2.type && tag2.type === "map") {
38
+ return;
39
+ }
40
+ dropdown.showDropdown(state, false);
41
+ state.popoverVisible = false;
42
+ const dom = e.target.classList.contains("tiny-tag") ? e.target : e.srcElement.parentElement;
43
+ nextTick(() => {
44
+ const { popoverRef } = instance.refs;
45
+ popoverRef.state.referenceElm = dom;
46
+ popoverRef.state.popperElm && (popoverRef.state.popperElm.style.display = "none");
47
+ popoverRef.doDestroy();
48
+ state.popoverVisible = true;
49
+ });
50
+ state.prevItem = state.recordItems.find((item) => item.field === tag2.field);
51
+ !state.prevItem && (state.prevItem = tag2);
52
+ state.selectValue = tag2.label;
53
+ state.currentModelValueIndex = index;
54
+ setDropdownProps(tag2);
55
+ };
56
+ const selectPropChange = (item, disabled) => {
57
+ if (disabled) return;
58
+ state.prevItem = item;
59
+ setDropdownProps(item);
60
+ };
61
+ const confirmEditTag = async (isConfirm) => {
62
+ if (!isConfirm) {
63
+ state.popoverVisible = false;
64
+ return;
65
+ }
66
+ const { prevItem, currentModelValueIndex: index } = state;
67
+ let newTag = null;
68
+ if (prevItem.type === "numRange") {
69
+ newTag = await validate.getVerifyNumTag(instance, state, props);
70
+ } else if (prevItem.type === "dateRange") {
71
+ newTag = await validate.getVerifyDateTag(instance, state, props, false);
72
+ } else if (prevItem.type === "datetimeRange") {
73
+ newTag = await validate.getVerifyDateTag(instance, state, props, true);
74
+ } else {
75
+ newTag = await validate.getVerifyTag(instance, state, props);
76
+ }
77
+ if (newTag) {
78
+ tag.emitChangeModelEvent({ emits, state, index, newTag, isEdit: true });
79
+ state.popoverVisible = false;
80
+ } else {
81
+ state.popoverVisible = true;
82
+ }
83
+ state.currentEditValue = [];
84
+ };
85
+ const selectItemIsDisable = (item) => {
86
+ var _a, _b, _c, _d;
87
+ if (item.type && item.type === "map") {
88
+ return true;
89
+ }
90
+ if (((_a = state.prevItem) == null ? void 0 : _a.operators) || item.operators) {
91
+ return ((_b = state.prevItem.operators) == null ? void 0 : _b.length) !== ((_c = item.operators) == null ? void 0 : _c.length);
92
+ }
93
+ const typeArr = ["radio", "checkbox"];
94
+ if (state.prevItem.type && typeArr.includes(state.prevItem.type)) {
95
+ return !item.type ? false : !typeArr.includes(item.type);
96
+ }
97
+ return ((_d = state.prevItem) == null ? void 0 : _d.type) !== item.type;
98
+ };
99
+ return {
100
+ editTag,
101
+ confirmEditTag,
102
+ selectPropChange,
103
+ selectItemIsDisable
104
+ };
105
+ }
106
+ exports.useEdit = useEdit;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const dropdown = require("../utils/dropdown.cjs.js");
4
+ function useInit({ props, state }) {
5
+ const { instance } = state;
6
+ const initItems = () => {
7
+ state.groupItems = {};
8
+ state.recordItems.forEach((item) => {
9
+ const { groupKey = "0" } = item;
10
+ if (state.groupItems[groupKey]) {
11
+ state.groupItems[groupKey].push({ ...item });
12
+ } else {
13
+ state.groupItems[groupKey] = [{ ...item }];
14
+ state.matchItems[groupKey] = { attr: [], attrValue: [] };
15
+ }
16
+ });
17
+ };
18
+ const handleClick = (e) => {
19
+ const { backupPrevItem, prevItem } = state;
20
+ e.stopPropagation();
21
+ state.isResetFlag = true;
22
+ if (props.editable) {
23
+ state.popoverVisible = false;
24
+ state.currentEditValue = [];
25
+ if (state.propItem.label && backupPrevItem && backupPrevItem !== prevItem) {
26
+ state.prevItem = backupPrevItem;
27
+ }
28
+ }
29
+ if (!state.isShowPanel || props.items.length === 0) {
30
+ dropdown.showDropdown(state, false);
31
+ } else {
32
+ dropdown.showDropdown(state);
33
+ }
34
+ };
35
+ const watchOutsideClick = () => {
36
+ var _a, _b, _c;
37
+ if (!state.isMouseDown) {
38
+ return;
39
+ }
40
+ if (props.editable) {
41
+ dropdown.showPopover(state, false);
42
+ }
43
+ state.isMouseDown = false;
44
+ if ((_c = (_b = (_a = instance == null ? void 0 : instance.refs) == null ? void 0 : _a.dropdownRef) == null ? void 0 : _b.state) == null ? void 0 : _c.visible) {
45
+ dropdown.showDropdown(state, false);
46
+ }
47
+ };
48
+ const watchMouseDown = () => {
49
+ state.isMouseDown = true;
50
+ };
51
+ const watchMouseMove = () => {
52
+ if (state.isMouseDown) {
53
+ state.isMouseDown = false;
54
+ }
55
+ };
56
+ return {
57
+ initItems,
58
+ watchOutsideClick,
59
+ watchMouseDown,
60
+ watchMouseMove,
61
+ handleClick
62
+ };
63
+ }
64
+ exports.useInit = useInit;
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const vue = require("vue");
4
+ const Loading = require("@opentiny/vue-loading");
5
+ const index = require("../utils/index.cjs.js");
6
+ const tag = require("../utils/tag.cjs.js");
7
+ const dropdown = require("../utils/dropdown.cjs.js");
8
+ const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9
+ const getHighlightMatch = (labelRegex, label, valueLength) => {
10
+ const match = [];
11
+ let lastIndex;
12
+ while (labelRegex.exec(label) !== null) {
13
+ lastIndex = labelRegex.lastIndex;
14
+ const startIndex = lastIndex - valueLength;
15
+ const prevMatch = label.slice(0, startIndex);
16
+ const currentMatch = [label.slice(startIndex, lastIndex)];
17
+ prevMatch && match.push(prevMatch);
18
+ match.push(currentMatch);
19
+ }
20
+ if (lastIndex < label.length) {
21
+ match.push(label.slice(lastIndex));
22
+ }
23
+ return match;
24
+ };
25
+ function useMatch({ props, state, emits }) {
26
+ const loadingInstance = vue.ref(null);
27
+ vue.watch(
28
+ () => state.inputValue,
29
+ (newInput) => {
30
+ if (!newInput.trim()) {
31
+ state.isShowDropdown = true;
32
+ } else {
33
+ state.isShowDropdown = false;
34
+ }
35
+ dropdown.showDropdown(state, false);
36
+ }
37
+ );
38
+ const getMatchList = async (keyword) => {
39
+ !loadingInstance.value && (loadingInstance.value = Loading.service({
40
+ target: document.getElementById("potential-loading")
41
+ }));
42
+ state.potentialOptions = await props.potentialOptions.getMatchList(keyword);
43
+ loadingInstance.value && loadingInstance.value.close();
44
+ if (state.potentialOptions.length) {
45
+ state.isShowDropdown = true;
46
+ }
47
+ dropdown.showDropdown(state, state.isShowDropdown);
48
+ };
49
+ const handleSearch = (e) => {
50
+ const { recordItems, propItem } = state;
51
+ const inputValue = e.target.value.trim();
52
+ const { maxlength } = props;
53
+ if (maxlength && maxlength < inputValue.length) {
54
+ emits("exceed", maxlength);
55
+ return;
56
+ }
57
+ if (inputValue.length === 0) {
58
+ return;
59
+ }
60
+ Object.keys(state.matchItems).forEach((key) => {
61
+ state.matchItems[key].attr = [];
62
+ state.matchItems[key].attrValue = [];
63
+ });
64
+ state.isShowDropdown = false;
65
+ const value = escapeRegExp(inputValue);
66
+ const patt = new RegExp(value, "i");
67
+ const hasItem = propItem.label || !value ? null : recordItems.find((item) => item.type === "map" && patt.test(item.label));
68
+ if (hasItem) {
69
+ state.propItem.label = hasItem.label;
70
+ state.inputValue = "";
71
+ state.prevItem = hasItem;
72
+ state.backupPrevItem = hasItem;
73
+ state.backupList = hasItem.options || [];
74
+ return;
75
+ }
76
+ state.filterList = state.backupList.filter((item) => {
77
+ if (patt.test(item.label)) {
78
+ delete item.isFilter;
79
+ if (tag.hasTagItem(state, item.label)) {
80
+ state.checkboxGroup.push(`${state.prevItem.label}${item.label}`);
81
+ }
82
+ return true;
83
+ } else {
84
+ item.isFilter = true;
85
+ return false;
86
+ }
87
+ });
88
+ const labelRegex = new RegExp(value, "ig");
89
+ const valueLength = inputValue.length;
90
+ if (state.propItem.label) {
91
+ state.backupList.forEach((item) => {
92
+ const itemLabel = item.label;
93
+ if (patt.test(itemLabel)) {
94
+ item.match = getHighlightMatch(labelRegex, itemLabel, valueLength);
95
+ item.isFilter = false;
96
+ state.isShowDropdown = true;
97
+ } else {
98
+ item.isFilter = true;
99
+ }
100
+ });
101
+ return;
102
+ }
103
+ for (const item of recordItems) {
104
+ const { options = [], groupKey = "0", ...rest } = item;
105
+ const itemLabel = rest.label;
106
+ if (patt.test(itemLabel)) {
107
+ const match = getHighlightMatch(labelRegex, itemLabel, valueLength);
108
+ state.matchItems[groupKey].attr.push({ ...item, match });
109
+ state.isShowDropdown = true;
110
+ }
111
+ for (const option of options) {
112
+ const optionLabel = state.propItem.label ? itemLabel : `${itemLabel}:${option.label}`;
113
+ if (patt.test(optionLabel)) {
114
+ const match = getHighlightMatch(labelRegex, optionLabel, valueLength);
115
+ state.matchItems[groupKey].attrValue.push({
116
+ ...option,
117
+ ...rest,
118
+ value: option.label,
119
+ match
120
+ });
121
+ state.isShowDropdown = true;
122
+ }
123
+ }
124
+ }
125
+ if (value && props.potentialOptions && props.potentialOptions.getMatchList) {
126
+ getMatchList(value);
127
+ } else {
128
+ dropdown.showDropdown(state, state.isShowDropdown);
129
+ }
130
+ };
131
+ const handleInput = index.debounce(handleSearch, 500);
132
+ const resetBackupList = () => {
133
+ state.backupList.forEach((item) => item.isFilter && delete item.isFilter);
134
+ };
135
+ const selectFirstMap = (item, isFirst) => {
136
+ const { options } = item;
137
+ const { prevItem, propItem } = state;
138
+ if (options) {
139
+ state.propItem.value = `${item.label}=`;
140
+ state.isShowTagKey = false;
141
+ state.inputValue = "";
142
+ state.backupList = item.options || [];
143
+ resetBackupList();
144
+ state.backupList.forEach((subItem) => {
145
+ const value = propItem.value + subItem.label;
146
+ subItem.isChecked = tag.hasTagItem(state, value);
147
+ });
148
+ } else {
149
+ if (item.isChecked) {
150
+ return;
151
+ }
152
+ state.isShowTagKey = true;
153
+ resetBackupList();
154
+ const { field, type } = prevItem;
155
+ const value = propItem.value + item.label;
156
+ const id = tag.getTagId(props, prevItem, item);
157
+ const newTag = tag.createNewTag({ type, field, label: propItem.label, value, ...id });
158
+ const tagList = [newTag];
159
+ tag.emitChangeModelEvent({ emits, state, tagList });
160
+ }
161
+ if (isFirst) {
162
+ dropdown.showDropdown(state);
163
+ }
164
+ };
165
+ return {
166
+ handleInput,
167
+ selectFirstMap
168
+ };
169
+ }
170
+ exports.useMatch = useMatch;