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