@arcblock/ux 2.5.64 → 2.5.66
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/NFTDisplay/index.js +46 -15
- package/package.json +5 -4
- package/src/NFTDisplay/index.js +47 -9
package/lib/NFTDisplay/index.js
CHANGED
@@ -13,6 +13,7 @@ var _get = _interopRequireDefault(require("lodash/get"));
|
|
13
13
|
var _pako = _interopRequireDefault(require("pako"));
|
14
14
|
var _base64Url = _interopRequireDefault(require("base64-url"));
|
15
15
|
var _isSvg = _interopRequireDefault(require("is-svg"));
|
16
|
+
var _reactSvg = require("react-svg");
|
16
17
|
var _aspectRatioContainer = _interopRequireDefault(require("./aspect-ratio-container"));
|
17
18
|
var _img = _interopRequireDefault(require("./svg-embedder/img"));
|
18
19
|
var _inlineSvg = _interopRequireDefault(require("./svg-embedder/inline-svg"));
|
@@ -142,6 +143,7 @@ function NFTDisplay(_ref) {
|
|
142
143
|
switch (type) {
|
143
144
|
case 'url':
|
144
145
|
{
|
146
|
+
var _state$fallback;
|
145
147
|
const urlObj = new URL(content);
|
146
148
|
if (!urlObj.searchParams.has('assetId')) {
|
147
149
|
urlObj.searchParams.append('assetId', address);
|
@@ -150,22 +152,51 @@ function NFTDisplay(_ref) {
|
|
150
152
|
urlObj.searchParams.append('vcId', vcId);
|
151
153
|
}
|
152
154
|
const url = urlObj.href;
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
(0, _jsxRuntime.jsx)("object", {
|
157
|
-
data: url
|
158
|
-
// onError={() => setState({ ...state, error: true })}
|
159
|
-
,
|
160
|
-
onLoad: () => setState(_objectSpread(_objectSpread({}, state), {}, {
|
155
|
+
const safeOnLoad = () => {
|
156
|
+
if (state.loading) {
|
157
|
+
setState(_objectSpread(_objectSpread({}, state), {}, {
|
161
158
|
loading: false
|
162
|
-
}))
|
163
|
-
|
164
|
-
|
165
|
-
|
159
|
+
}));
|
160
|
+
}
|
161
|
+
};
|
162
|
+
return state.fallback ? (_state$fallback = state.fallback) === null || _state$fallback === void 0 ? void 0 : _state$fallback.call(state) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactSvg.ReactSVG, {
|
163
|
+
src: url,
|
164
|
+
beforeInjection: svg => {
|
165
|
+
svg.setAttribute('style', 'pointer-events: none');
|
166
|
+
},
|
167
|
+
afterInjection: safeOnLoad,
|
168
|
+
onError: error => {
|
169
|
+
var _error$message, _error$message2;
|
170
|
+
let objectType = null;
|
171
|
+
if ((error === null || error === void 0 ? void 0 : (_error$message = error.message) === null || _error$message === void 0 ? void 0 : _error$message.indexOf('Invalid content type: ')) > -1) {
|
172
|
+
var _error$message$split;
|
173
|
+
objectType = (_error$message$split = error.message.split('Invalid content type: ')) === null || _error$message$split === void 0 ? void 0 : _error$message$split[1];
|
174
|
+
} else if ((error === null || error === void 0 ? void 0 : (_error$message2 = error.message) === null || _error$message2 === void 0 ? void 0 : _error$message2.indexOf('Unable to load SVG file: ')) > -1) {
|
175
|
+
objectType = 'image/svg+xml';
|
166
176
|
}
|
167
|
-
|
168
|
-
|
177
|
+
setState(_objectSpread(_objectSpread({}, state), {}, {
|
178
|
+
// fallback to object, and use objectType to render
|
179
|
+
fallback: () =>
|
180
|
+
/*#__PURE__*/
|
181
|
+
// eslint-disable-next-line jsx-a11y/alt-text
|
182
|
+
(0, _jsxRuntime.jsx)("object", {
|
183
|
+
type: objectType,
|
184
|
+
data: url
|
185
|
+
// onError={() => setState({ ...state, error: true })}
|
186
|
+
,
|
187
|
+
onLoad: safeOnLoad,
|
188
|
+
style: {
|
189
|
+
width: 'auto',
|
190
|
+
height: 'auto',
|
191
|
+
pointerEvents: 'none'
|
192
|
+
}
|
193
|
+
}, url)
|
194
|
+
}));
|
195
|
+
}
|
196
|
+
// evalScripts="always"
|
197
|
+
,
|
198
|
+
wrapper: "div"
|
199
|
+
});
|
169
200
|
}
|
170
201
|
case 'uri':
|
171
202
|
{
|
@@ -255,7 +286,7 @@ NFTDisplay.defaultProps = {
|
|
255
286
|
minimumLoadingTime: 0,
|
256
287
|
onCompleted: () => {}
|
257
288
|
};
|
258
|
-
const Root = (0, _Theme.styled)('div')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n justify-content: center;\n align-items: center;\n position: relative;\n /* \u9ED8\u8BA4\u5C3A\u5BF8 */\n width: 150px;\n height: 150px;\n overflow: hidden;\n\n &,\n img {\n max-width: 100%;\n max-height: 100%;\n }\n\n img {\n width: 100%;\n height: 100%;\n }\n\n &.nft-display--inset {\n width: 100%;\n height: 100%;\n }\n"])));
|
289
|
+
const Root = (0, _Theme.styled)('div')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n justify-content: center;\n align-items: center;\n position: relative;\n /* \u9ED8\u8BA4\u5C3A\u5BF8 */\n width: 150px;\n height: 150px;\n overflow: hidden;\n\n &,\n img,\n object {\n max-width: 100%;\n max-height: 100%;\n }\n\n img,\n object {\n width: 100%;\n height: 100%;\n }\n\n &.nft-display--inset {\n width: 100%;\n height: 100%;\n }\n"])));
|
259
290
|
function withAspectRatio(Component) {
|
260
291
|
// eslint-disable-next-line func-names, react/prop-types
|
261
292
|
return function (_ref2) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.5.
|
3
|
+
"version": "2.5.66",
|
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": "
|
50
|
+
"gitHead": "e2efc6b18c9495d805574465a7691b0367a82439",
|
51
51
|
"dependencies": {
|
52
52
|
"@arcblock/did-motif": "^1.1.13",
|
53
|
-
"@arcblock/icons": "^2.5.
|
54
|
-
"@arcblock/react-hooks": "^2.5.
|
53
|
+
"@arcblock/icons": "^2.5.66",
|
54
|
+
"@arcblock/react-hooks": "^2.5.66",
|
55
55
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
56
56
|
"@emotion/react": "^11.10.4",
|
57
57
|
"@emotion/styled": "^11.10.4",
|
@@ -83,6 +83,7 @@
|
|
83
83
|
"react-player": "^1.15.3",
|
84
84
|
"react-router-dom": "^6.4.2",
|
85
85
|
"react-shadow": "^19.0.3",
|
86
|
+
"react-svg": "^16.1.18",
|
86
87
|
"react-use": "^17.4.0",
|
87
88
|
"rebound": "^0.1.0",
|
88
89
|
"topojson-client": "^3.1.0",
|
package/src/NFTDisplay/index.js
CHANGED
@@ -7,6 +7,7 @@ import get from 'lodash/get';
|
|
7
7
|
import pako from 'pako';
|
8
8
|
import base64 from 'base64-url';
|
9
9
|
import isSvg from 'is-svg';
|
10
|
+
import { ReactSVG } from 'react-svg';
|
10
11
|
|
11
12
|
import AspectRatioContainer from './aspect-ratio-container';
|
12
13
|
import ImgSvgEmbedder from './svg-embedder/img';
|
@@ -127,13 +128,48 @@ function NFTDisplay({
|
|
127
128
|
}
|
128
129
|
|
129
130
|
const url = urlObj.href;
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
131
|
+
|
132
|
+
const safeOnLoad = () => {
|
133
|
+
if (state.loading) {
|
134
|
+
setState({ ...state, loading: false });
|
135
|
+
}
|
136
|
+
};
|
137
|
+
|
138
|
+
return state.fallback ? (
|
139
|
+
state.fallback?.()
|
140
|
+
) : (
|
141
|
+
<ReactSVG
|
142
|
+
src={url}
|
143
|
+
beforeInjection={(svg) => {
|
144
|
+
svg.setAttribute('style', 'pointer-events: none');
|
145
|
+
}}
|
146
|
+
afterInjection={safeOnLoad}
|
147
|
+
onError={(error) => {
|
148
|
+
let objectType = null;
|
149
|
+
if (error?.message?.indexOf('Invalid content type: ') > -1) {
|
150
|
+
objectType = error.message.split('Invalid content type: ')?.[1];
|
151
|
+
} else if (error?.message?.indexOf('Unable to load SVG file: ') > -1) {
|
152
|
+
objectType = 'image/svg+xml';
|
153
|
+
}
|
154
|
+
|
155
|
+
setState({
|
156
|
+
...state,
|
157
|
+
// fallback to object, and use objectType to render
|
158
|
+
fallback: () => (
|
159
|
+
// eslint-disable-next-line jsx-a11y/alt-text
|
160
|
+
<object
|
161
|
+
key={url}
|
162
|
+
type={objectType}
|
163
|
+
data={url}
|
164
|
+
// onError={() => setState({ ...state, error: true })}
|
165
|
+
onLoad={safeOnLoad}
|
166
|
+
style={{ width: 'auto', height: 'auto', pointerEvents: 'none' }}
|
167
|
+
/>
|
168
|
+
),
|
169
|
+
});
|
170
|
+
}}
|
171
|
+
// evalScripts="always"
|
172
|
+
wrapper="div"
|
137
173
|
/>
|
138
174
|
);
|
139
175
|
}
|
@@ -232,12 +268,14 @@ const Root = styled('div')`
|
|
232
268
|
overflow: hidden;
|
233
269
|
|
234
270
|
&,
|
235
|
-
img
|
271
|
+
img,
|
272
|
+
object {
|
236
273
|
max-width: 100%;
|
237
274
|
max-height: 100%;
|
238
275
|
}
|
239
276
|
|
240
|
-
img
|
277
|
+
img,
|
278
|
+
object {
|
241
279
|
width: 100%;
|
242
280
|
height: 100%;
|
243
281
|
}
|