@opentiny/vue-search-box 0.1.6 → 2.27.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 (87) hide show
  1. package/es/index.es.js +2772 -0
  2. package/es/index.es.js.map +1 -0
  3. package/lib/index.cjs.js +2 -0
  4. package/lib/index.cjs.js.map +1 -0
  5. package/package.json +36 -56
  6. package/README.md +0 -134
  7. package/README.zh-CN.md +0 -135
  8. package/dist/es/components/first-level-panel.vue.es.js +0 -4
  9. package/dist/es/components/first-level-panel.vue.es2.js +0 -177
  10. package/dist/es/components/second-level-panel.vue.es.js +0 -4
  11. package/dist/es/components/second-level-panel.vue.es2.js +0 -466
  12. package/dist/es/composables/use-checkbox.es.js +0 -74
  13. package/dist/es/composables/use-custom.es.js +0 -49
  14. package/dist/es/composables/use-datepicker.es.js +0 -86
  15. package/dist/es/composables/use-dropdown.es.js +0 -216
  16. package/dist/es/composables/use-edit.es.js +0 -108
  17. package/dist/es/composables/use-init.es.js +0 -78
  18. package/dist/es/composables/use-match.es.js +0 -170
  19. package/dist/es/composables/use-num-range.es.js +0 -77
  20. package/dist/es/composables/use-placeholder.es.js +0 -41
  21. package/dist/es/composables/use-tag.es.js +0 -56
  22. package/dist/es/index-Tlzvfwv-.css +0 -401
  23. package/dist/es/index.es.js +0 -45
  24. package/dist/es/index.type.es.js +0 -1
  25. package/dist/es/index.vue.es.js +0 -4
  26. package/dist/es/index.vue.es2.js +0 -780
  27. package/dist/es/smb-theme.es.js +0 -18
  28. package/dist/es/utils/clone.es.js +0 -29
  29. package/dist/es/utils/date.es.js +0 -431
  30. package/dist/es/utils/dropdown.es.js +0 -24
  31. package/dist/es/utils/en_US.es.js +0 -45
  32. package/dist/es/utils/index.es.js +0 -13
  33. package/dist/es/utils/tag.es.js +0 -44
  34. package/dist/es/utils/type.es.js +0 -4
  35. package/dist/es/utils/validate.es.js +0 -179
  36. package/dist/es/utils/zh_CN.es.js +0 -45
  37. package/dist/index.css +0 -401
  38. package/dist/lib/components/first-level-panel.vue.cjs.js +0 -4
  39. package/dist/lib/components/first-level-panel.vue.cjs2.js +0 -177
  40. package/dist/lib/components/second-level-panel.vue.cjs.js +0 -4
  41. package/dist/lib/components/second-level-panel.vue.cjs2.js +0 -466
  42. package/dist/lib/composables/use-checkbox.cjs.js +0 -74
  43. package/dist/lib/composables/use-custom.cjs.js +0 -49
  44. package/dist/lib/composables/use-datepicker.cjs.js +0 -86
  45. package/dist/lib/composables/use-dropdown.cjs.js +0 -216
  46. package/dist/lib/composables/use-edit.cjs.js +0 -108
  47. package/dist/lib/composables/use-init.cjs.js +0 -78
  48. package/dist/lib/composables/use-match.cjs.js +0 -170
  49. package/dist/lib/composables/use-num-range.cjs.js +0 -77
  50. package/dist/lib/composables/use-placeholder.cjs.js +0 -41
  51. package/dist/lib/composables/use-tag.cjs.js +0 -56
  52. package/dist/lib/index-Tlzvfwv-.css +0 -401
  53. package/dist/lib/index.cjs.js +0 -45
  54. package/dist/lib/index.type.cjs.js +0 -1
  55. package/dist/lib/index.vue.cjs.js +0 -4
  56. package/dist/lib/index.vue.cjs2.js +0 -780
  57. package/dist/lib/smb-theme.cjs.js +0 -18
  58. package/dist/lib/utils/clone.cjs.js +0 -29
  59. package/dist/lib/utils/date.cjs.js +0 -431
  60. package/dist/lib/utils/dropdown.cjs.js +0 -24
  61. package/dist/lib/utils/en_US.cjs.js +0 -45
  62. package/dist/lib/utils/index.cjs.js +0 -13
  63. package/dist/lib/utils/tag.cjs.js +0 -44
  64. package/dist/lib/utils/type.cjs.js +0 -4
  65. package/dist/lib/utils/validate.cjs.js +0 -179
  66. package/dist/lib/utils/zh_CN.cjs.js +0 -45
  67. package/dist/types/composables/use-checkbox.d.ts +0 -8
  68. package/dist/types/composables/use-custom.d.ts +0 -7
  69. package/dist/types/composables/use-datepicker.d.ts +0 -11
  70. package/dist/types/composables/use-dropdown.d.ts +0 -14
  71. package/dist/types/composables/use-edit.d.ts +0 -13
  72. package/dist/types/composables/use-init.d.ts +0 -10
  73. package/dist/types/composables/use-match.d.ts +0 -8
  74. package/dist/types/composables/use-num-range.d.ts +0 -9
  75. package/dist/types/composables/use-placeholder.d.ts +0 -8
  76. package/dist/types/composables/use-tag.d.ts +0 -9
  77. package/dist/types/smb-theme.d.ts +0 -15
  78. package/dist/types/utils/clone.d.ts +0 -12
  79. package/dist/types/utils/date.d.ts +0 -234
  80. package/dist/types/utils/dropdown.d.ts +0 -12
  81. package/dist/types/utils/en_US.d.ts +0 -43
  82. package/dist/types/utils/index.d.ts +0 -1
  83. package/dist/types/utils/tag.d.ts +0 -46
  84. package/dist/types/utils/type.d.ts +0 -6
  85. package/dist/types/utils/validate.d.ts +0 -31
  86. package/dist/types/utils/zh_CN.d.ts +0 -43
  87. /package/{dist/types → types}/index.type.d.ts +0 -0
@@ -1,170 +0,0 @@
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) => {
10
- const match = [];
11
- let lastIndex = 0;
12
- let result;
13
- while ((result = labelRegex.exec(label)) !== null) {
14
- const startIndex = result.index;
15
- const endIndex = labelRegex.lastIndex;
16
- if (startIndex > lastIndex) {
17
- match.push(label.slice(lastIndex, startIndex));
18
- }
19
- match.push(label.slice(startIndex, endIndex));
20
- lastIndex = endIndex;
21
- }
22
- if (lastIndex < label.length) {
23
- match.push(label.slice(lastIndex));
24
- }
25
- return match;
26
- };
27
- function useMatch({ props, state, emits }) {
28
- const loadingInstance = vue.ref(null);
29
- const getMatchList = async (keyword) => {
30
- if (typeof document !== "undefined") {
31
- !loadingInstance.value && (loadingInstance.value = Loading.service({
32
- target: document.getElementById("potential-loading")
33
- }));
34
- }
35
- state.potentialOptions = await props.potentialOptions.getMatchList(keyword);
36
- loadingInstance.value && loadingInstance.value.close();
37
- dropdown.showDropdown(state, true);
38
- };
39
- const handleSearch = (e) => {
40
- var _a, _b, _c;
41
- const { recordItems, propItem } = state;
42
- const inputValue = e.target.value.trim();
43
- const { maxlength } = props;
44
- if (maxlength && maxlength < inputValue.length) {
45
- emits("exceed", maxlength);
46
- return;
47
- }
48
- if (inputValue.length === 0) {
49
- dropdown.showDropdown(state);
50
- return;
51
- }
52
- Object.keys(state.matchItems).forEach((key) => {
53
- state.matchItems[key].attr = [];
54
- state.matchItems[key].attrValue = [];
55
- });
56
- const value = escapeRegExp(inputValue);
57
- const patt = new RegExp(value, "i");
58
- const hasItem = propItem.label || !value ? null : recordItems.find((item) => item.type === "map" && patt.test(item.label));
59
- if (hasItem) {
60
- state.propItem.label = hasItem.label;
61
- state.inputValue = "";
62
- state.prevItem = hasItem;
63
- state.backupPrevItem = hasItem;
64
- state.backupList = hasItem.options || [];
65
- return;
66
- }
67
- state.filterList = (_a = state.backupList) == null ? void 0 : _a.filter((item) => {
68
- if (patt.test(item.label)) {
69
- delete item.isFilter;
70
- if (tag.hasTagItem(state, item.label)) {
71
- state.checkboxGroup.push(`${state.prevItem.label}${item.label}`);
72
- }
73
- return true;
74
- } else {
75
- item.isFilter = true;
76
- return false;
77
- }
78
- });
79
- const labelRegex = new RegExp(value, "ig");
80
- const hightlighStr = inputValue.toLowerCase();
81
- if (state.propItem.label) {
82
- (_b = state.backupList) == null ? void 0 : _b.forEach((item) => {
83
- item.hightlighStr = hightlighStr;
84
- const itemLabel = item.label;
85
- if (patt.test(itemLabel)) {
86
- item.match = getHighlightMatch(labelRegex, itemLabel);
87
- item.isFilter = false;
88
- } else {
89
- item.isFilter = true;
90
- }
91
- });
92
- if (((_c = state.backupList) == null ? void 0 : _c.length) || inputValue) {
93
- dropdown.showDropdown(state);
94
- } else {
95
- dropdown.showDropdown(state, false);
96
- }
97
- return;
98
- }
99
- for (const item of recordItems) {
100
- const { options = [], groupKey = "0", ...rest } = item;
101
- const itemLabel = rest.label;
102
- if (patt.test(itemLabel)) {
103
- const match = getHighlightMatch(labelRegex, itemLabel);
104
- state.matchItems[groupKey].attr.push({ ...item, match, hightlighStr });
105
- }
106
- for (const option of options) {
107
- const optionLabel = state.propItem.label ? itemLabel : `${itemLabel}:${option.label}`;
108
- if (patt.test(optionLabel)) {
109
- const match = getHighlightMatch(labelRegex, optionLabel);
110
- state.matchItems[groupKey].attrValue.push({
111
- ...option,
112
- ...rest,
113
- options,
114
- hightlighStr,
115
- value: option.label,
116
- match
117
- });
118
- }
119
- }
120
- }
121
- if (value && props.potentialOptions && props.potentialOptions.getMatchList) {
122
- getMatchList(value);
123
- } else {
124
- dropdown.showDropdown(state);
125
- }
126
- };
127
- const handleInput = index.debounce(handleSearch, 500);
128
- const resetBackupList = () => {
129
- var _a;
130
- (_a = state.backupList) == null ? void 0 : _a.forEach((item) => item.isFilter && delete item.isFilter);
131
- };
132
- const selectFirstMap = (item, isFirst) => {
133
- var _a;
134
- const { options } = item;
135
- const { prevItem, propItem } = state;
136
- if (options) {
137
- dropdown.showDropdown(state, false);
138
- state.propItem.value = `${item.label}=`;
139
- state.isShowTagKey = false;
140
- state.inputValue = "";
141
- state.backupList = item.options || [];
142
- resetBackupList();
143
- (_a = state.backupList) == null ? void 0 : _a.forEach((subItem) => {
144
- const value = propItem.value + subItem.label;
145
- subItem.isChecked = tag.hasTagItem(state, value);
146
- });
147
- } else {
148
- if (item.isChecked) {
149
- return;
150
- }
151
- dropdown.showDropdown(state, false);
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;
@@ -1,77 +0,0 @@
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 useNumRange({ props, state, t, emits }) {
7
- const { instance } = state;
8
- const sizeChange = async (confirm) => {
9
- if (!confirm) {
10
- state.propItem.label = "";
11
- return;
12
- }
13
- const newTag = await validate.getVerifyNumTag(instance, state, props);
14
- if (newTag) {
15
- dropdown.showDropdown(state, false);
16
- const newValue = props.modelValue.filter((prev) => prev.type !== newTag.type || prev.field !== newTag.field);
17
- newValue.push(newTag);
18
- tag.emitChangeModelEvent({ emits, state, newValue });
19
- } else {
20
- dropdown.showDropdown(state);
21
- }
22
- };
23
- const createDateRules = (item, startKey, endKey) => {
24
- const { maxTimeLength = 0 } = item;
25
- return {
26
- [startKey]: {
27
- validator: (rule, value, cb) => {
28
- if (maxTimeLength > 0 && !value) {
29
- cb(new Error(t("tvp.tvpSearchbox.notBeNull")));
30
- } else if (!value && !state[endKey]) {
31
- cb(new Error(t("tvp.tvpSearchbox.rangeDateTitle")));
32
- } else {
33
- cb();
34
- }
35
- }
36
- },
37
- [endKey]: {
38
- validator: (rule, value, cb) => {
39
- if (maxTimeLength > 0 && !value) {
40
- cb(new Error(t("tvp.tvpSearchbox.notBeNull")));
41
- } else if (!value && !state[startKey]) {
42
- cb(new Error(t("tvp.tvpSearchbox.rangeDateTitle")));
43
- } else {
44
- cb();
45
- }
46
- }
47
- }
48
- };
49
- };
50
- const initFormRule = () => {
51
- let dateRules = {}, datetimeRules = {};
52
- props.items.forEach((item) => {
53
- if (item.type === "dateRange") {
54
- dateRules = createDateRules(item, "startDate", "endDate");
55
- }
56
- if (item.type === "datetimeRange") {
57
- datetimeRules = createDateRules(item, "startDateTime", "endDateTime");
58
- }
59
- });
60
- state.formRules = {
61
- ...dateRules,
62
- ...datetimeRules
63
- };
64
- if (props.editable) {
65
- state.formRules.inputEditValue = {
66
- required: true,
67
- message: t("tvp.tvpSearchbox.notBeNull"),
68
- trigger: ["change", "blur"]
69
- };
70
- }
71
- };
72
- return {
73
- initFormRule,
74
- sizeChange
75
- };
76
- }
77
- exports.useNumRange = useNumRange;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const vue = require("vue");
4
- function usePlaceholder({ props, state, t }) {
5
- const placeholder = vue.ref(props.emptyPlaceholder);
6
- const setPlaceholder = (placeholderValue) => {
7
- placeholder.value = placeholderValue;
8
- };
9
- if (props.modelValue.length > 0) {
10
- setPlaceholder(t("tvp.tvpSearchbox.addPlaceholder"));
11
- }
12
- vue.watch(
13
- () => state.propItem.label,
14
- (newValue) => {
15
- var _a;
16
- if (newValue) {
17
- const { placeholder: placeholder2, type } = state.prevItem;
18
- if (placeholder2) {
19
- setPlaceholder(placeholder2);
20
- } else if (type === "map") {
21
- setPlaceholder(t("tvp.tvpSearchbox.tagPlaceholder"));
22
- } else if ((_a = state.backupList) == null ? void 0 : _a.length) {
23
- setPlaceholder(t("tvp.tvpSearchbox.dynamicPlaceholder", { newValue }));
24
- } else {
25
- setPlaceholder(t("tvp.tvpSearchbox.addPlaceholder"));
26
- }
27
- } else {
28
- if (props.modelValue.length > 0) {
29
- setPlaceholder(t("tvp.tvpSearchbox.addPlaceholder"));
30
- } else {
31
- setPlaceholder(props.emptyPlaceholder);
32
- }
33
- }
34
- }
35
- );
36
- return {
37
- placeholder,
38
- setPlaceholder
39
- };
40
- }
41
- exports.usePlaceholder = usePlaceholder;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const vue = require("vue");
4
- const dropdown = require("../utils/dropdown.cjs.js");
5
- const tag = require("../utils/tag.cjs.js");
6
- function useTag({ props, state, emits }) {
7
- const lastInputValue = vue.ref(state.inputValue);
8
- const changeIsChecked = (tag2) => {
9
- if (tag2) {
10
- const parent = state.recordItems.find((item) => item.label === tag2.label);
11
- if (parent && parent.options) {
12
- const child = parent.options.find((item) => item.label === tag2.value);
13
- child && (child.isChecked = false);
14
- }
15
- }
16
- };
17
- const deleteTag = (tag$1) => {
18
- dropdown.showDropdown(state, false);
19
- changeIsChecked(tag$1);
20
- const newValue = props.modelValue.filter((item) => item !== tag$1);
21
- tag.emitChangeModelEvent({ emits, state, newValue });
22
- };
23
- const clearTag = () => {
24
- dropdown.showDropdown(state, false);
25
- props.modelValue.forEach((item) => changeIsChecked(item));
26
- state.propItem = {};
27
- state.inputValue = "";
28
- tag.emitChangeModelEvent({ emits, state, newValue: [] });
29
- emits("clear");
30
- };
31
- const backspaceDeleteTag = () => {
32
- var _a, _b;
33
- if (state.inputValue) {
34
- return;
35
- }
36
- if (state.propItem.label) {
37
- state.propItem = {};
38
- return;
39
- }
40
- if (lastInputValue.value === "" && state.inputValue === "") {
41
- dropdown.showDropdown(state, false);
42
- const lastIndex = props.modelValue.length - 1;
43
- changeIsChecked(props.modelValue[lastIndex]);
44
- const newValue = state.innerModelValue.slice(0, props.modelValue.length - 1);
45
- tag.emitChangeModelEvent({ emits, state, newValue });
46
- }
47
- lastInputValue.value = state.inputValue;
48
- (_b = (_a = state == null ? void 0 : state.instance) == null ? void 0 : _a.refs) == null ? void 0 : _b.inputRef.$el.click();
49
- };
50
- return {
51
- deleteTag,
52
- clearTag,
53
- backspaceDeleteTag
54
- };
55
- }
56
- exports.useTag = useTag;