@blocklet/list 0.9.11 → 0.9.14

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.
@@ -44,7 +44,8 @@ function Autocomplete() {
44
44
  filters,
45
45
  endpoint,
46
46
  handleKeyword,
47
- t
47
+ t,
48
+ serverUrl
48
49
  } = (0, _filter.useFilterContext)();
49
50
  const muiTheme = (0, _styles.useTheme)();
50
51
  const getResults = (0, _react.useCallback)(async params => {
@@ -55,6 +56,15 @@ function Autocomplete() {
55
56
  });
56
57
  return data.dataList || [];
57
58
  }, [storeApi]);
59
+ const getBlockletDetail = (0, _react.useCallback)(item => {
60
+ const blockletDetail = new URL((0, _urlJoin.default)(endpoint, "/blocklets/".concat(item.did)));
61
+
62
+ if (serverUrl) {
63
+ blockletDetail.searchParams.set('server-url', serverUrl);
64
+ }
65
+
66
+ return blockletDetail.href;
67
+ }, [endpoint, serverUrl]);
58
68
 
59
69
  const onClickItem = detailUrl => {
60
70
  window.location.href = detailUrl;
@@ -140,8 +150,8 @@ function Autocomplete() {
140
150
  let {
141
151
  item
142
152
  } = _ref4;
143
- const detailUrl = (0, _urlJoin.default)(endpoint, 'blocklets', item.did);
144
- return detailUrl;
153
+ const blockletDetail = getBlockletDetail(item);
154
+ return blockletDetail;
145
155
  },
146
156
 
147
157
  templates: {
@@ -151,7 +161,7 @@ function Autocomplete() {
151
161
  item
152
162
  } = _ref5;
153
163
  const logoUrl = item.logo ? (0, _urlJoin.default)(endpoint, 'assets', item.did, item.logo) : null;
154
- const detailUrl = (0, _urlJoin.default)(endpoint, 'blocklets', item.did);
164
+ const blockletDetail = getBlockletDetail(item);
155
165
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.ThemeProvider, {
156
166
  theme: muiTheme,
157
167
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.ThemeProvider, {
@@ -162,7 +172,7 @@ function Autocomplete() {
162
172
  did: item.did,
163
173
  description: item.description,
164
174
  cover: logoUrl,
165
- onMainClick: () => onClickItem(detailUrl)
175
+ onMainClick: () => onClickItem(blockletDetail)
166
176
  })
167
177
  })
168
178
  });
@@ -180,7 +190,7 @@ function Autocomplete() {
180
190
  return () => {
181
191
  search.destroy();
182
192
  };
183
- }, [endpoint, filters, getResults, muiTheme, onReset, onSubmit, t]);
193
+ }, [endpoint, filters, getBlockletDetail, getResults, muiTheme, onReset, onSubmit, t]);
184
194
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
185
195
  className: "bl-search-container",
186
196
  ref: containerRef
@@ -50,7 +50,8 @@ function FilterProvider(_ref) {
50
50
  locale,
51
51
  blockletRender,
52
52
  onFilterChange,
53
- extraFilter
53
+ extraFilter,
54
+ serverUrl
54
55
  } = _ref;
55
56
 
56
57
  const storeApi = _axios.default.create({
@@ -161,6 +162,7 @@ function FilterProvider(_ref) {
161
162
  categoryOptions,
162
163
  priceOptions,
163
164
  storeApi,
165
+ serverUrl,
164
166
  hasNextPage: blockletsState.list.length < blockletsState.total,
165
167
  handleSort: sort => {
166
168
  const changeData = _objectSpread(_objectSpread({}, finalFilters), {}, {
@@ -22,13 +22,15 @@ const propTypes = {
22
22
  endpoint: _propTypes.default.string.isRequired,
23
23
  blockletRender: _propTypes.default.func.isRequired,
24
24
  onFilterChange: _propTypes.default.func,
25
- locale: _propTypes.default.oneOf(['zh', 'en'])
25
+ locale: _propTypes.default.oneOf(['zh', 'en']),
26
+ serverUrl: _propTypes.default.string
26
27
  };
27
28
  exports.propTypes = propTypes;
28
29
  const defaultProps = {
29
30
  locale: 'zh',
30
31
  filters: {},
31
32
  onFilterChange: () => {},
32
- extraFilter: list => list
33
+ extraFilter: list => list,
34
+ serverUrl: null
33
35
  };
34
36
  exports.defaultProps = defaultProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/list",
3
- "version": "0.9.11",
3
+ "version": "0.9.14",
4
4
  "description": "Common ux components of blocklet",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -68,5 +68,5 @@
68
68
  "eslint": "^8.22.0",
69
69
  "prettier": "^2.7.1"
70
70
  },
71
- "gitHead": "816aadb1ee96d04ab7a0752d8c41a2da5238d333"
71
+ "gitHead": "40d7cadfadce2b34158e5bf1c14d7504fae82d46"
72
72
  }
@@ -15,7 +15,7 @@ export default function Autocomplete() {
15
15
  const containerRef = useRef(null);
16
16
  const panelRootRef = useRef(null);
17
17
  const rootRef = useRef(null);
18
- const { storeApi, filters, endpoint, handleKeyword, t } = useFilterContext();
18
+ const { storeApi, filters, endpoint, handleKeyword, t, serverUrl } = useFilterContext();
19
19
  const muiTheme = useTheme();
20
20
 
21
21
  const getResults = useCallback(
@@ -27,6 +27,17 @@ export default function Autocomplete() {
27
27
  [storeApi]
28
28
  );
29
29
 
30
+ const getBlockletDetail = useCallback(
31
+ (item) => {
32
+ const blockletDetail = new URL(joinUrl(endpoint, `/blocklets/${item.did}`));
33
+ if (serverUrl) {
34
+ blockletDetail.searchParams.set('server-url', serverUrl);
35
+ }
36
+ return blockletDetail.href;
37
+ },
38
+ [endpoint, serverUrl]
39
+ );
40
+
30
41
  const onClickItem = (detailUrl) => {
31
42
  window.location.href = detailUrl;
32
43
  };
@@ -90,14 +101,14 @@ export default function Autocomplete() {
90
101
  return item.title;
91
102
  },
92
103
  getItemUrl({ item }) {
93
- const detailUrl = joinUrl(endpoint, 'blocklets', item.did);
94
- return detailUrl;
104
+ const blockletDetail = getBlockletDetail(item);
105
+ return blockletDetail;
95
106
  },
96
107
  templates: {
97
108
  // eslint-disable-next-line react/no-unstable-nested-components
98
109
  item({ item }) {
99
110
  const logoUrl = item.logo ? joinUrl(endpoint, 'assets', item.did, item.logo) : null;
100
- const detailUrl = joinUrl(endpoint, 'blocklets', item.did);
111
+ const blockletDetail = getBlockletDetail(item);
101
112
  return (
102
113
  <MuiThemeProvider theme={muiTheme}>
103
114
  <EmotionThemeProvider theme={muiTheme}>
@@ -107,7 +118,7 @@ export default function Autocomplete() {
107
118
  did={item.did}
108
119
  description={item.description}
109
120
  cover={logoUrl}
110
- onMainClick={() => onClickItem(detailUrl)}
121
+ onMainClick={() => onClickItem(blockletDetail)}
111
122
  />
112
123
  </EmotionThemeProvider>
113
124
  </MuiThemeProvider>
@@ -125,7 +136,7 @@ export default function Autocomplete() {
125
136
  return () => {
126
137
  search.destroy();
127
138
  };
128
- }, [endpoint, filters, getResults, muiTheme, onReset, onSubmit, t]);
139
+ }, [endpoint, filters, getBlockletDetail, getResults, muiTheme, onReset, onSubmit, t]);
129
140
 
130
141
  return <div className="bl-search-container" ref={containerRef} />;
131
142
  }
@@ -11,7 +11,16 @@ import constant from '../libs/constant';
11
11
  const Filter = createContext({});
12
12
  const { Provider, Consumer } = Filter;
13
13
 
14
- function FilterProvider({ filters, children, endpoint, locale, blockletRender, onFilterChange, extraFilter }) {
14
+ function FilterProvider({
15
+ filters,
16
+ children,
17
+ endpoint,
18
+ locale,
19
+ blockletRender,
20
+ onFilterChange,
21
+ extraFilter,
22
+ serverUrl,
23
+ }) {
15
24
  const storeApi = axios.create({
16
25
  baseURL: endpoint,
17
26
  });
@@ -105,6 +114,7 @@ function FilterProvider({ filters, children, endpoint, locale, blockletRender, o
105
114
  categoryOptions,
106
115
  priceOptions,
107
116
  storeApi,
117
+ serverUrl,
108
118
  hasNextPage: blockletsState.list.length < blockletsState.total,
109
119
  handleSort: (sort) => {
110
120
  const changeData = {
@@ -14,6 +14,7 @@ const propTypes = {
14
14
  blockletRender: PropTypes.func.isRequired,
15
15
  onFilterChange: PropTypes.func,
16
16
  locale: PropTypes.oneOf(['zh', 'en']),
17
+ serverUrl: PropTypes.string,
17
18
  };
18
19
 
19
20
  const defaultProps = {
@@ -21,6 +22,7 @@ const defaultProps = {
21
22
  filters: {},
22
23
  onFilterChange: () => {},
23
24
  extraFilter: (list) => list,
25
+ serverUrl: null,
24
26
  };
25
27
 
26
28
  export { propTypes, defaultProps };