@arcblock/ux 1.16.15 → 1.16.19

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,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
44
44
  const Div = _styledComponents.default.div.withConfig({
45
45
  displayName: "Blocklet__Div",
46
46
  componentId: "sc-3dga5l-0"
47
- })(["&.arcblock-blocklet{border:1px solid #f2f2f2;padding:0 16px;border-radius:12px;background:#fff;overflow:hidden;&:hover{filter:drop-shadow(0px 4px 12px rgba(92,92,92,0.04));}}.arcblock-blocklet__content{padding:16px 0;}.arcblock-blocklet__content--main{display:flex;align-items:center;cursor:pointer;}.arcblock-blocklet__content--body{overflow:hidden;flex:1;display:flex;align-items:flex-start;}.arcblock-blocklet__addons{padding:16px 0;border-top:1px solid #f2f2f2;}.arcblock-blocklet__cover{width:100px;height:100px;margin-right:16px;overflow:hidden;border-radius:12px;}.arcblock-blocklet__info{flex:1;overflow:hidden;.arcblock-blocklet__button{margin-top:16px;display:inline-block;}}.arcblock-blocklet__button{& > *{position:relative;&::before{content:'';position:absolute;display:block;left:50%;top:50%;height:", "%;width:", "%;transform:translate(-50%,-50%);}}& > *:not(.Mui-disabled){background-color:rgba(79,106,246,0.06);color:", ";}}.arcblock-blocklet__title{margin:0;font-size:18px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}.arcblock-blocklet__describe{margin:2px 0 0;color:#999;font-size:14px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}.arcblock-blocklet__addons{display:flex;justify-content:space-between;color:#999;font-size:14px;position:relative;}.arcblock-blocklet__addons--item{white-space:nowrap;}&.arcblock-blocklet--size-md{&:hover{position:relative;}.arcblock-blocklet__title{margin-bottom:3px;}.arcblock-blocklet__describe{white-space:normal;height:2.86em;}.arcblock-blocklet__button{margin-top:5px;}}&.arcblock-blocklet--size-sm,&.arcblock-blocklet--size-xs{.arcblock-blocklet__content{padding:12px 0;}.arcblock-blocklet__cover{width:48px;height:48px;border-radius:6px;}.arcblock-blocklet__addons{padding:8px 0;.arcblock-blocklet__addons--item{font-size:12px;}}}&.arcblock-blocklet--size-xs{.arcblock-blocklet__addons{display:none !important;}}"], props => props.scaleClickZone * 100, props => props.scaleClickZone * 100, props => props.theme.palette.primary.main);
47
+ })(["&.arcblock-blocklet{border:1px solid #f2f2f2;padding:0 16px;border-radius:12px;background:", ";overflow:hidden;&:hover{filter:drop-shadow(0px 4px 12px rgba(92,92,92,0.04));}}.arcblock-blocklet__content{padding:16px 0;}.arcblock-blocklet__content--main{display:flex;align-items:center;cursor:pointer;}.arcblock-blocklet__content--body{overflow:hidden;flex:1;display:flex;align-items:flex-start;}.arcblock-blocklet__addons{padding:16px 0;border-top:1px solid #f2f2f2;}.arcblock-blocklet__cover{width:100px;height:100px;margin-right:16px;overflow:hidden;border-radius:12px;}.arcblock-blocklet__info{flex:1;overflow:hidden;.arcblock-blocklet__button{margin-top:16px;display:inline-block;}}.arcblock-blocklet__button{& > *:not(.Mui-disabled){position:relative;z-index:1;&::before{content:'';border-radius:100vw;position:absolute;height:100%;width:100%;left:0;top:0;transition:opacity 0.3s;}&:hover::before{opacity:0;}&::after{content:'';position:absolute;height:100%;width:100%;background-color:", ";transform:scale(0.1);opacity:0;z-index:-1;border-radius:100vw;transition:transform 0.3s,opacity 0.3s,background-color 0.3s;}&:hover::after{opacity:1;transform-origin:center;transform:scale(1);}}& > *:not(.Mui-disabled){background-color:rgba(79,106,246,0.06);color:", ";}&:hover > *:not(.Mui-disabled){color:", ";}}.arcblock-blocklet__title{margin:0;font-size:18px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}.arcblock-blocklet__describe{margin:2px 0 0;color:#999;font-size:14px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}.arcblock-blocklet__addons{display:flex;justify-content:space-between;color:#999;font-size:14px;position:relative;}.arcblock-blocklet__addons--item{white-space:nowrap;}&.arcblock-blocklet--size-md{&:hover{position:relative;}.arcblock-blocklet__title{margin-bottom:3px;}.arcblock-blocklet__describe{white-space:normal;height:2.86em;}.arcblock-blocklet__button{margin-top:5px;}}&.arcblock-blocklet--size-sm,&.arcblock-blocklet--size-xs{.arcblock-blocklet__content{padding:12px 0;}.arcblock-blocklet__cover{width:48px;height:48px;border-radius:6px;}.arcblock-blocklet__addons{padding:8px 0;.arcblock-blocklet__addons--item{font-size:12px;}}}&.arcblock-blocklet--size-xs{.arcblock-blocklet__addons{display:none !important;}}"], props => props.theme.palette.common.white, props => props.theme.palette.primary.main, props => props.theme.palette.primary.main, props => props.theme.palette.common.white);
48
48
 
49
49
  function BlockletIcon(_ref) {
50
50
  let {
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.LocaleProvider = LocaleProvider;
7
- exports.useLocaleContext = useLocaleContext;
8
- exports.languages = exports.getLocale = exports.setLocale = exports.LocaleContext = exports.LocaleConsumer = void 0;
6
+ exports.create = exports.languages = exports.getLocale = exports.setLocale = exports.useLocaleContext = exports.LocaleContext = exports.LocaleConsumer = exports.LocaleProvider = void 0;
9
7
 
10
8
  var _react = _interopRequireWildcard(require("react"));
11
9
 
@@ -70,60 +68,78 @@ exports.setLocale = setLocale;
70
68
 
71
69
  const replace = (template, data) => template.replace(/{(\w*)}/g, (m, key) => data.hasOwnProperty(key) ? data[key] : '');
72
70
 
73
- const LocaleContext = /*#__PURE__*/_react.default.createContext();
74
-
75
- exports.LocaleContext = LocaleContext;
76
- const {
77
- Provider,
78
- Consumer
79
- } = LocaleContext;
80
- exports.LocaleConsumer = Consumer;
81
-
82
- function LocaleProvider(_ref) {
83
- let {
84
- children,
85
- locale,
86
- translations
87
- } = _ref,
88
- rest = _objectWithoutProperties(_ref, _excluded);
89
-
90
- const [currentLocale, setCurrentLocale] = (0, _react.useState)(getLocale(locale));
91
- (0, _react.useEffect)(() => {
92
- setLocale(currentLocale);
93
- }, [currentLocale]);
94
-
95
- const changeLocale = newLocale => {
96
- setCurrentLocale(newLocale);
97
- };
71
+ const create = () => {
72
+ const LocaleContext = /*#__PURE__*/_react.default.createContext();
73
+
74
+ const {
75
+ Provider,
76
+ Consumer
77
+ } = LocaleContext;
78
+
79
+ function LocaleProvider(_ref) {
80
+ let {
81
+ children,
82
+ locale,
83
+ translations
84
+ } = _ref,
85
+ rest = _objectWithoutProperties(_ref, _excluded);
86
+
87
+ const [currentLocale, setCurrentLocale] = (0, _react.useState)(getLocale(locale));
88
+ (0, _react.useEffect)(() => {
89
+ setLocale(currentLocale);
90
+ }, [currentLocale]);
91
+
92
+ const changeLocale = newLocale => {
93
+ setCurrentLocale(newLocale);
94
+ };
95
+
96
+ const translate = (key, data) => {
97
+ if (!translations[currentLocale] || !translations[currentLocale][key]) {
98
+ console.warn("Warning: no ".concat(key, " translation of ").concat(currentLocale));
99
+ return key;
100
+ }
101
+
102
+ return replace(translations[currentLocale][key], data);
103
+ };
104
+
105
+ return /*#__PURE__*/_react.default.createElement(Provider, {
106
+ value: _objectSpread({
107
+ locale: currentLocale,
108
+ changeLocale,
109
+ t: translate
110
+ }, rest)
111
+ }, children);
112
+ }
98
113
 
99
- const translate = (key, data) => {
100
- if (!translations[currentLocale] || !translations[currentLocale][key]) {
101
- console.warn("Warning: no ".concat(key, " translation of ").concat(currentLocale));
102
- return key;
103
- }
114
+ function useLocaleContext() {
115
+ const context = (0, _react.useContext)(LocaleContext);
116
+ return context;
117
+ }
104
118
 
105
- return replace(translations[currentLocale][key], data);
119
+ LocaleProvider.propTypes = {
120
+ children: _propTypes.default.any.isRequired,
121
+ translations: _propTypes.default.object.isRequired,
122
+ locale: _propTypes.default.string
123
+ };
124
+ LocaleProvider.defaultProps = {
125
+ locale: ''
126
+ };
127
+ return {
128
+ Consumer,
129
+ LocaleProvider,
130
+ LocaleContext,
131
+ useLocaleContext
106
132
  };
107
-
108
- return /*#__PURE__*/_react.default.createElement(Provider, {
109
- value: _objectSpread({
110
- locale: currentLocale,
111
- changeLocale,
112
- t: translate
113
- }, rest)
114
- }, children);
115
- }
116
-
117
- function useLocaleContext() {
118
- const context = (0, _react.useContext)(LocaleContext);
119
- return context;
120
- }
121
-
122
- LocaleProvider.propTypes = {
123
- children: _propTypes.default.any.isRequired,
124
- translations: _propTypes.default.object.isRequired,
125
- locale: _propTypes.default.string
126
133
  };
127
- LocaleProvider.defaultProps = {
128
- locale: ''
129
- };
134
+
135
+ exports.create = create;
136
+ const {
137
+ Consumer,
138
+ LocaleProvider,
139
+ LocaleContext,
140
+ useLocaleContext
141
+ } = create();
142
+ exports.useLocaleContext = useLocaleContext;
143
+ exports.LocaleContext = LocaleContext;
144
+ exports.LocaleProvider = LocaleProvider;
145
+ exports.LocaleConsumer = Consumer;
@@ -56,11 +56,10 @@ function fromBase64(v) {
56
56
  }
57
57
 
58
58
  return Buffer.from(_base64Url.default.unescape(v), 'base64');
59
- }
60
-
61
- const isVC = type => {
62
- return String(type).includes('VerifiableCredential');
63
- }; // 仅针对非 url type 的情况
59
+ } // const isVC = type => {
60
+ // return String(type).includes('VerifiableCredential');
61
+ // };
62
+ // 仅针对非 url type 的情况
64
63
 
65
64
 
66
65
  const getSvgEmbedder = preferredSvgEmbedder => {
@@ -111,8 +110,7 @@ function NFTDisplay(_ref) {
111
110
  }
112
111
 
113
112
  const {
114
- vcId,
115
- type: assetType
113
+ vcId
116
114
  } = parsed.current;
117
115
  const display = (0, _get.default)(parsed.current, 'credentialSubject.display');
118
116
  const {
@@ -142,10 +140,9 @@ function NFTDisplay(_ref) {
142
140
  if (!state.loading && minimumLoadingReady || state.error) {
143
141
  onCompleted();
144
142
  }
145
- }, [state, minimumLoadingReady]); // VC 检查
146
-
143
+ }, [state, minimumLoadingReady]);
147
144
 
148
- if (state.error || !isVC(assetType)) {
145
+ if (state.error) {
149
146
  throw new Error('Failed to render NFT Display.');
150
147
  }
151
148
 
@@ -155,8 +152,15 @@ function NFTDisplay(_ref) {
155
152
  case 'url':
156
153
  {
157
154
  const urlObj = new URL(content);
158
- urlObj.searchParams.append('assetId', address);
159
- urlObj.searchParams.append('vcId', vcId);
155
+
156
+ if (!urlObj.searchParams.has('assetId')) {
157
+ urlObj.searchParams.append('assetId', address);
158
+ }
159
+
160
+ if (!urlObj.searchParams.has('vcId')) {
161
+ urlObj.searchParams.append('vcId', vcId);
162
+ }
163
+
160
164
  const url = urlObj.href;
161
165
  return /*#__PURE__*/_react.default.createElement("img", {
162
166
  src: url,
@@ -170,6 +174,20 @@ function NFTDisplay(_ref) {
170
174
  });
171
175
  }
172
176
 
177
+ case 'uri':
178
+ {
179
+ return /*#__PURE__*/_react.default.createElement("img", {
180
+ src: content,
181
+ onError: () => setState(_objectSpread(_objectSpread({}, state), {}, {
182
+ error: true
183
+ })),
184
+ onLoad: () => setState(_objectSpread(_objectSpread({}, state), {}, {
185
+ loading: false
186
+ })),
187
+ alt: "NFT Display"
188
+ });
189
+ }
190
+
173
191
  case 'svg_gzipped':
174
192
  {
175
193
  const buffer = _pako.default.ungzip(fromBase64(content), {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "1.16.15",
3
+ "version": "1.16.19",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -53,10 +53,10 @@
53
53
  "react": ">=16.12.0",
54
54
  "react-ga": "^2.7.0"
55
55
  },
56
- "gitHead": "34ef9d96c3a84d9f2ee694f5bfe89eca22450e48",
56
+ "gitHead": "88965cae9c1b0273e085c8779672cedef3abd633",
57
57
  "dependencies": {
58
- "@arcblock/icons": "^1.16.15",
59
- "@arcblock/react-hooks": "^1.16.15",
58
+ "@arcblock/icons": "^1.16.19",
59
+ "@arcblock/react-hooks": "^1.16.19",
60
60
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
61
61
  "@material-ui/core": "^4.12.3",
62
62
  "@material-ui/icons": "4.11.2",
@@ -17,7 +17,7 @@ const Div = styled.div`
17
17
  border: 1px solid #f2f2f2;
18
18
  padding: 0 16px;
19
19
  border-radius: 12px;
20
- background: #fff;
20
+ background: ${props => props.theme.palette.common.white};
21
21
  overflow: hidden;
22
22
  &:hover {
23
23
  filter: drop-shadow(0px 4px 12px rgba(92, 92, 92, 0.04));
@@ -58,24 +58,50 @@ const Div = styled.div`
58
58
  display: inline-block;
59
59
  }
60
60
  }
61
+ // 这里想覆盖 mui-button 的样式 做成 blocklet-button 的专有样式
61
62
  .arcblock-blocklet__button {
62
- & > * {
63
+ & > *:not(.Mui-disabled) {
63
64
  position: relative;
65
+ z-index: 1;
64
66
  &::before {
67
+ content: '';
68
+ border-radius: 100vw;
69
+ position: absolute;
70
+ height: 100%;
71
+ width: 100%;
72
+ left: 0;
73
+ top: 0;
74
+ transition: opacity 0.3s;
75
+ }
76
+ &:hover::before {
77
+ opacity: 0;
78
+ }
79
+ &::after {
65
80
  content: '';
66
81
  position: absolute;
67
- display: block;
68
- left: 50%;
69
- top: 50%;
70
- height: ${props => props.scaleClickZone * 100}%;
71
- width: ${props => props.scaleClickZone * 100}%;
72
- transform: translate(-50%, -50%);
82
+ height: 100%;
83
+ width: 100%;
84
+ background-color: ${props => props.theme.palette.primary.main};
85
+ transform: scale(0.1);
86
+ opacity: 0;
87
+ z-index: -1;
88
+ border-radius: 100vw;
89
+ transition: transform 0.3s, opacity 0.3s, background-color 0.3s;
90
+ }
91
+ &:hover::after {
92
+ opacity: 1;
93
+ transform-origin: center;
94
+ transform: scale(1);
73
95
  }
74
96
  }
97
+
75
98
  & > *:not(.Mui-disabled) {
76
99
  background-color: rgba(79, 106, 246, 0.06);
77
100
  color: ${props => props.theme.palette.primary.main};
78
101
  }
102
+ &:hover > *:not(.Mui-disabled) {
103
+ color: ${props => props.theme.palette.common.white};
104
+ }
79
105
  }
80
106
  .arcblock-blocklet__title {
81
107
  margin: 0;
@@ -32,50 +32,55 @@ const setLocale = locale => Cookie.set(cookieName, locale, getCookieOptions());
32
32
  const replace = (template, data) =>
33
33
  template.replace(/{(\w*)}/g, (m, key) => (data.hasOwnProperty(key) ? data[key] : ''));
34
34
 
35
- const LocaleContext = React.createContext();
36
- const { Provider, Consumer } = LocaleContext;
37
-
38
- function LocaleProvider({ children, locale, translations, ...rest }) {
39
- const [currentLocale, setCurrentLocale] = useState(getLocale(locale));
35
+ const create = () => {
36
+ const LocaleContext = React.createContext();
37
+ const { Provider, Consumer } = LocaleContext;
38
+ function LocaleProvider({ children, locale, translations, ...rest }) {
39
+ const [currentLocale, setCurrentLocale] = useState(getLocale(locale));
40
+
41
+ useEffect(() => {
42
+ setLocale(currentLocale);
43
+ }, [currentLocale]);
44
+
45
+ const changeLocale = newLocale => {
46
+ setCurrentLocale(newLocale);
47
+ };
48
+
49
+ const translate = (key, data) => {
50
+ if (!translations[currentLocale] || !translations[currentLocale][key]) {
51
+ console.warn(`Warning: no ${key} translation of ${currentLocale}`);
52
+ return key;
53
+ }
54
+
55
+ return replace(translations[currentLocale][key], data);
56
+ };
57
+
58
+ return (
59
+ <Provider value={{ locale: currentLocale, changeLocale, t: translate, ...rest }}>
60
+ {children}
61
+ </Provider>
62
+ );
63
+ }
40
64
 
41
- useEffect(() => {
42
- setLocale(currentLocale);
43
- }, [currentLocale]);
65
+ function useLocaleContext() {
66
+ const context = useContext(LocaleContext);
67
+ return context;
68
+ }
44
69
 
45
- const changeLocale = newLocale => {
46
- setCurrentLocale(newLocale);
70
+ LocaleProvider.propTypes = {
71
+ children: PropTypes.any.isRequired,
72
+ translations: PropTypes.object.isRequired,
73
+ locale: PropTypes.string,
47
74
  };
48
75
 
49
- const translate = (key, data) => {
50
- if (!translations[currentLocale] || !translations[currentLocale][key]) {
51
- console.warn(`Warning: no ${key} translation of ${currentLocale}`);
52
- return key;
53
- }
54
-
55
- return replace(translations[currentLocale][key], data);
76
+ LocaleProvider.defaultProps = {
77
+ locale: '',
56
78
  };
57
79
 
58
- return (
59
- <Provider value={{ locale: currentLocale, changeLocale, t: translate, ...rest }}>
60
- {children}
61
- </Provider>
62
- );
63
- }
64
-
65
- function useLocaleContext() {
66
- const context = useContext(LocaleContext);
67
- return context;
68
- }
69
-
70
- LocaleProvider.propTypes = {
71
- children: PropTypes.any.isRequired,
72
- translations: PropTypes.object.isRequired,
73
- locale: PropTypes.string,
80
+ return { Consumer, LocaleProvider, LocaleContext, useLocaleContext };
74
81
  };
75
82
 
76
- LocaleProvider.defaultProps = {
77
- locale: '',
78
- };
83
+ const { Consumer, LocaleProvider, LocaleContext, useLocaleContext } = create();
79
84
 
80
85
  export {
81
86
  LocaleProvider,
@@ -85,4 +90,5 @@ export {
85
90
  setLocale,
86
91
  getLocale,
87
92
  languages,
93
+ create,
88
94
  };
@@ -19,9 +19,9 @@ function fromBase64(v) {
19
19
  return Buffer.from(base64.unescape(v), 'base64');
20
20
  }
21
21
 
22
- const isVC = type => {
23
- return String(type).includes('VerifiableCredential');
24
- };
22
+ // const isVC = type => {
23
+ // return String(type).includes('VerifiableCredential');
24
+ // };
25
25
 
26
26
  // 仅针对非 url type 的情况
27
27
  const getSvgEmbedder = preferredSvgEmbedder => {
@@ -65,7 +65,7 @@ function NFTDisplay({
65
65
  parsed.current = JSON.parse(data);
66
66
  // console.log('[debug] parse data')
67
67
  }
68
- const { vcId, type: assetType } = parsed.current;
68
+ const { vcId } = parsed.current;
69
69
  const display = get(parsed.current, 'credentialSubject.display');
70
70
  const { content, type } = display;
71
71
  const isUrlType = type === 'url';
@@ -90,8 +90,7 @@ function NFTDisplay({
90
90
  }
91
91
  }, [state, minimumLoadingReady]);
92
92
 
93
- // VC 检查
94
- if (state.error || !isVC(assetType)) {
93
+ if (state.error) {
95
94
  throw new Error('Failed to render NFT Display.');
96
95
  }
97
96
 
@@ -100,8 +99,14 @@ function NFTDisplay({
100
99
  switch (type) {
101
100
  case 'url': {
102
101
  const urlObj = new URL(content);
103
- urlObj.searchParams.append('assetId', address);
104
- urlObj.searchParams.append('vcId', vcId);
102
+ if (!urlObj.searchParams.has('assetId')) {
103
+ urlObj.searchParams.append('assetId', address);
104
+ }
105
+
106
+ if (!urlObj.searchParams.has('vcId')) {
107
+ urlObj.searchParams.append('vcId', vcId);
108
+ }
109
+
105
110
  const url = urlObj.href;
106
111
  return (
107
112
  <img
@@ -112,6 +117,16 @@ function NFTDisplay({
112
117
  />
113
118
  );
114
119
  }
120
+ case 'uri': {
121
+ return (
122
+ <img
123
+ src={content}
124
+ onError={() => setState({ ...state, error: true })}
125
+ onLoad={() => setState({ ...state, loading: false })}
126
+ alt="NFT Display"
127
+ />
128
+ );
129
+ }
115
130
  case 'svg_gzipped': {
116
131
  const buffer = pako.ungzip(fromBase64(content), {});
117
132
  const svg = Buffer.from(buffer).toString('utf8');