@arcblock/ux 2.6.3 → 2.6.4

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.
package/lib/Util/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.appendParams = void 0;
6
7
  exports.detectWalletExtension = detectWalletExtension;
7
8
  exports.formatToDate = formatToDate;
8
9
  exports.formatToDatetime = formatToDatetime;
@@ -296,15 +297,45 @@ const isEthereumDid = did => {
296
297
  }
297
298
  return true;
298
299
  };
300
+
301
+ /**
302
+ *
303
+ * @param {string} url 需要处理的 url
304
+ * @param {{imageFilter: 'crop'|'resize'; w?: number; h?: number; r?: 0|90|180|270}} params
305
+ * @returns
306
+ */
299
307
  exports.isEthereumDid = isEthereumDid;
308
+ const appendParams = (url, params) => {
309
+ if (!params) {
310
+ return url;
311
+ }
312
+ try {
313
+ // HACK: 如果 url 中带有域名,则 urlInstance.origin 为 url 中的域名;否则,借用当前页面的 location.origin 作为域名来拼接一个 url
314
+ const urlInstance = new URL(url, window.location.origin);
315
+ Object.keys(params).forEach(key => {
316
+ urlInstance.searchParams.set(key, params[key]);
317
+ });
318
+ // HACK: 如果前后域名一致,代表前面已经借用了 location.origin,这个时候只需要返回 urlInstance.pathname + urlInstance.search 即可
319
+ if (urlInstance.origin === window.location.origin) {
320
+ return urlInstance.pathname + urlInstance.search;
321
+ }
322
+ return urlInstance.href;
323
+ } catch (_unused) {
324
+ return url;
325
+ }
326
+ };
327
+ exports.appendParams = appendParams;
300
328
  const getUserAvatar = function getUserAvatar(avatar) {
301
- var _window$blocklet, _window$blocklet$capa;
302
329
  let size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 48;
303
330
  if (!avatar) {
304
331
  return avatar;
305
332
  }
306
- if (avatar.indexOf('/.well-known/service') >= 0 && (_window$blocklet = window.blocklet) !== null && _window$blocklet !== void 0 && (_window$blocklet$capa = _window$blocklet.capabilities) !== null && _window$blocklet$capa !== void 0 && _window$blocklet$capa.httpImageFilter) {
307
- return "".concat(avatar, "/resize?w=").concat(size, "&h=").concat(size);
333
+ if (avatar.indexOf('/.well-known/service') >= 0) {
334
+ return appendParams(avatar, {
335
+ imageFilter: 'resize',
336
+ w: size,
337
+ h: size
338
+ });
308
339
  }
309
340
  return avatar;
310
341
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.6.3",
3
+ "version": "2.6.4",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -47,11 +47,11 @@
47
47
  "peerDependencies": {
48
48
  "react": ">=18.1.0"
49
49
  },
50
- "gitHead": "1b4d3ea0e13aa11bc06cad0be0e3dd630ffd7008",
50
+ "gitHead": "15205ba8243468982ed04553234ca9c54eaafe6a",
51
51
  "dependencies": {
52
52
  "@arcblock/did-motif": "^1.1.13",
53
- "@arcblock/icons": "^2.6.3",
54
- "@arcblock/react-hooks": "^2.6.3",
53
+ "@arcblock/icons": "^2.6.4",
54
+ "@arcblock/react-hooks": "^2.6.4",
55
55
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
56
56
  "@emotion/react": "^11.10.4",
57
57
  "@emotion/styled": "^11.10.4",
package/src/Util/index.js CHANGED
@@ -283,13 +283,43 @@ export const isEthereumDid = (did) => {
283
283
  return true;
284
284
  };
285
285
 
286
+ /**
287
+ *
288
+ * @param {string} url 需要处理的 url
289
+ * @param {{imageFilter: 'crop'|'resize'; w?: number; h?: number; r?: 0|90|180|270}} params
290
+ * @returns
291
+ */
292
+ export const appendParams = (url, params) => {
293
+ if (!params) {
294
+ return url;
295
+ }
296
+ try {
297
+ // HACK: 如果 url 中带有域名,则 urlInstance.origin 为 url 中的域名;否则,借用当前页面的 location.origin 作为域名来拼接一个 url
298
+ const urlInstance = new URL(url, window.location.origin);
299
+ Object.keys(params).forEach((key) => {
300
+ urlInstance.searchParams.set(key, params[key]);
301
+ });
302
+ // HACK: 如果前后域名一致,代表前面已经借用了 location.origin,这个时候只需要返回 urlInstance.pathname + urlInstance.search 即可
303
+ if (urlInstance.origin === window.location.origin) {
304
+ return urlInstance.pathname + urlInstance.search;
305
+ }
306
+ return urlInstance.href;
307
+ } catch {
308
+ return url;
309
+ }
310
+ };
311
+
286
312
  export const getUserAvatar = (avatar, size = 48) => {
287
313
  if (!avatar) {
288
314
  return avatar;
289
315
  }
290
316
 
291
- if (avatar.indexOf('/.well-known/service') >= 0 && window.blocklet?.capabilities?.httpImageFilter) {
292
- return `${avatar}/resize?w=${size}&h=${size}`;
317
+ if (avatar.indexOf('/.well-known/service') >= 0) {
318
+ return appendParams(avatar, {
319
+ imageFilter: 'resize',
320
+ w: size,
321
+ h: size,
322
+ });
293
323
  }
294
324
 
295
325
  return avatar;