@blocklet/list 0.9.9 → 0.9.10
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.
|
@@ -19,6 +19,8 @@ var _urlJoin = _interopRequireDefault(require("url-join"));
|
|
|
19
19
|
|
|
20
20
|
var _constant = _interopRequireDefault(require("../../libs/constant"));
|
|
21
21
|
|
|
22
|
+
var _utils = require("../../libs/utils");
|
|
23
|
+
|
|
22
24
|
var _filter = require("../../contexts/filter");
|
|
23
25
|
|
|
24
26
|
var _item = _interopRequireDefault(require("./item"));
|
|
@@ -33,8 +35,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
33
35
|
|
|
34
36
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
35
37
|
|
|
36
|
-
const cachePool = new Map();
|
|
37
|
-
|
|
38
38
|
function Autocomplete() {
|
|
39
39
|
const containerRef = (0, _react.useRef)(null);
|
|
40
40
|
const panelRootRef = (0, _react.useRef)(null);
|
|
@@ -48,22 +48,11 @@ function Autocomplete() {
|
|
|
48
48
|
} = (0, _filter.useFilterContext)();
|
|
49
49
|
const muiTheme = (0, _styles.useTheme)();
|
|
50
50
|
const getResults = (0, _react.useCallback)(async params => {
|
|
51
|
-
const key = JSON.stringify(params);
|
|
52
|
-
const target = cachePool.get(key);
|
|
53
|
-
if (target) return target.data;
|
|
54
51
|
const {
|
|
55
52
|
data
|
|
56
53
|
} = await storeApi.get(_constant.default.blockletsPath, {
|
|
57
54
|
params
|
|
58
55
|
});
|
|
59
|
-
|
|
60
|
-
if (cachePool.size > _constant.default.cacheSize) {
|
|
61
|
-
cachePool.clear();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
cachePool.set(key, {
|
|
65
|
-
data: data.dataList
|
|
66
|
-
});
|
|
67
56
|
return data.dataList || [];
|
|
68
57
|
}, [storeApi]);
|
|
69
58
|
|
|
@@ -110,7 +99,8 @@ function Autocomplete() {
|
|
|
110
99
|
panel: 'bl-autocomplete-panel',
|
|
111
100
|
label: 'bl-autocomplete-label',
|
|
112
101
|
form: 'bl-autocomplete-form',
|
|
113
|
-
input: 'bl-autocomplete-input'
|
|
102
|
+
input: 'bl-autocomplete-input',
|
|
103
|
+
clearButton: 'bl-autocomplete-clear'
|
|
114
104
|
},
|
|
115
105
|
placeholder: t('common.searchStore'),
|
|
116
106
|
initialState: {
|
|
@@ -131,7 +121,7 @@ function Autocomplete() {
|
|
|
131
121
|
keyword: query
|
|
132
122
|
});
|
|
133
123
|
|
|
134
|
-
return [{
|
|
124
|
+
return (0, _utils.debounced)([{
|
|
135
125
|
sourceId: 'blocklets',
|
|
136
126
|
|
|
137
127
|
getItems() {
|
|
@@ -183,7 +173,7 @@ function Autocomplete() {
|
|
|
183
173
|
}
|
|
184
174
|
|
|
185
175
|
}
|
|
186
|
-
}];
|
|
176
|
+
}]);
|
|
187
177
|
}
|
|
188
178
|
|
|
189
179
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/list",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.10",
|
|
4
4
|
"description": "Common ux components of blocklet",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"eslint": "^8.21.0",
|
|
69
69
|
"prettier": "^2.7.1"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "3dd78770094c338b18c0958af3db442b9f4784c8"
|
|
72
72
|
}
|
|
@@ -7,11 +7,10 @@ import { ThemeProvider as MuiThemeProvider, useTheme } from '@mui/material/style
|
|
|
7
7
|
import joinUrl from 'url-join';
|
|
8
8
|
|
|
9
9
|
import constant from '../../libs/constant';
|
|
10
|
+
import { debounced } from '../../libs/utils';
|
|
10
11
|
import { useFilterContext } from '../../contexts/filter';
|
|
11
12
|
import Blocklet from './item';
|
|
12
13
|
|
|
13
|
-
const cachePool = new Map();
|
|
14
|
-
|
|
15
14
|
export default function Autocomplete() {
|
|
16
15
|
const containerRef = useRef(null);
|
|
17
16
|
const panelRootRef = useRef(null);
|
|
@@ -21,20 +20,8 @@ export default function Autocomplete() {
|
|
|
21
20
|
|
|
22
21
|
const getResults = useCallback(
|
|
23
22
|
async (params) => {
|
|
24
|
-
const key = JSON.stringify(params);
|
|
25
|
-
const target = cachePool.get(key);
|
|
26
|
-
|
|
27
|
-
if (target) return target.data;
|
|
28
|
-
|
|
29
23
|
const { data } = await storeApi.get(constant.blockletsPath, { params });
|
|
30
24
|
|
|
31
|
-
if (cachePool.size > constant.cacheSize) {
|
|
32
|
-
cachePool.clear();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
cachePool.set(key, {
|
|
36
|
-
data: data.dataList,
|
|
37
|
-
});
|
|
38
25
|
return data.dataList || [];
|
|
39
26
|
},
|
|
40
27
|
[storeApi]
|
|
@@ -76,6 +63,7 @@ export default function Autocomplete() {
|
|
|
76
63
|
label: 'bl-autocomplete-label',
|
|
77
64
|
form: 'bl-autocomplete-form',
|
|
78
65
|
input: 'bl-autocomplete-input',
|
|
66
|
+
clearButton: 'bl-autocomplete-clear',
|
|
79
67
|
},
|
|
80
68
|
placeholder: t('common.searchStore'),
|
|
81
69
|
initialState: {
|
|
@@ -91,7 +79,7 @@ export default function Autocomplete() {
|
|
|
91
79
|
pageSize: 10,
|
|
92
80
|
keyword: query,
|
|
93
81
|
};
|
|
94
|
-
return [
|
|
82
|
+
return debounced([
|
|
95
83
|
{
|
|
96
84
|
sourceId: 'blocklets',
|
|
97
85
|
getItems() {
|
|
@@ -130,7 +118,7 @@ export default function Autocomplete() {
|
|
|
130
118
|
},
|
|
131
119
|
},
|
|
132
120
|
},
|
|
133
|
-
];
|
|
121
|
+
]);
|
|
134
122
|
},
|
|
135
123
|
});
|
|
136
124
|
|