@jupyter/collaboration 4.4.0-alpha.0 → 4.4.0-rc.0
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/components.js +21 -4
- package/lib/menu.js +17 -1
- package/package.json +1 -1
- package/style/sidepanel.css +1 -0
package/lib/components.js
CHANGED
|
@@ -10,19 +10,36 @@ import React, { useEffect, useState } from 'react';
|
|
|
10
10
|
export function UserIconComponent(props) {
|
|
11
11
|
var _a;
|
|
12
12
|
const { userManager, onClick } = props;
|
|
13
|
-
const [user, setUser] = useState((_a = userManager.identity) !== null && _a !== void 0 ? _a : {
|
|
13
|
+
const [user, setUser] = useState((_a = userManager.identity) !== null && _a !== void 0 ? _a : {
|
|
14
|
+
display_name: '',
|
|
15
|
+
color: '',
|
|
16
|
+
initials: '',
|
|
17
|
+
avatar_url: ''
|
|
18
|
+
});
|
|
19
|
+
const [imgError, setImgError] = useState(false);
|
|
14
20
|
useEffect(() => {
|
|
15
21
|
const updateUser = () => {
|
|
16
22
|
var _a;
|
|
17
|
-
setUser((_a = userManager.identity) !== null && _a !== void 0 ? _a : {
|
|
23
|
+
setUser((_a = userManager.identity) !== null && _a !== void 0 ? _a : {
|
|
24
|
+
display_name: '',
|
|
25
|
+
color: '',
|
|
26
|
+
initials: '',
|
|
27
|
+
avatar_url: ''
|
|
28
|
+
});
|
|
18
29
|
};
|
|
19
30
|
userManager.userChanged.connect(updateUser);
|
|
20
31
|
return () => {
|
|
21
32
|
userManager.userChanged.disconnect(updateUser);
|
|
22
33
|
};
|
|
23
34
|
}, [userManager]);
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
const showImage = user.avatar_url && !imgError;
|
|
36
|
+
return (React.createElement("div", { title: user.display_name, className: "jp-UserInfo-Icon", style: !showImage ? { backgroundColor: user.color } : undefined, onClick: onClick }, showImage ? (React.createElement("img", { src: user.avatar_url, alt: user.display_name, onError: () => setImgError(true), style: {
|
|
37
|
+
width: '100%',
|
|
38
|
+
height: '100%',
|
|
39
|
+
borderRadius: '50%',
|
|
40
|
+
objectFit: 'cover',
|
|
41
|
+
cursor: 'pointer'
|
|
42
|
+
} })) : (React.createElement("span", null, user.initials))));
|
|
26
43
|
}
|
|
27
44
|
/**
|
|
28
45
|
* React widget for the user details.
|
package/lib/menu.js
CHANGED
|
@@ -50,7 +50,23 @@ export class RendererUserMenu extends MenuBar.Renderer {
|
|
|
50
50
|
if (this._user.isReady && (identity === null || identity === void 0 ? void 0 : identity.avatar_url)) {
|
|
51
51
|
return h.div({
|
|
52
52
|
className: 'lm-MenuBar-itemIcon jp-MenuBar-imageIcon'
|
|
53
|
-
}, h.img({
|
|
53
|
+
}, h.img({
|
|
54
|
+
src: identity.avatar_url,
|
|
55
|
+
onerror: (event) => {
|
|
56
|
+
const img = event.currentTarget;
|
|
57
|
+
const parent = img.parentElement;
|
|
58
|
+
if (parent) {
|
|
59
|
+
// Clear broken image and fallback to initials with colors
|
|
60
|
+
parent.textContent = '';
|
|
61
|
+
parent.style.backgroundColor = identity.color || '';
|
|
62
|
+
const span = document.createElement('span');
|
|
63
|
+
span.textContent = identity.initials;
|
|
64
|
+
parent.appendChild(span);
|
|
65
|
+
parent.classList.remove('jp-MenuBar-imageIcon');
|
|
66
|
+
parent.classList.add('jp-MenuBar-anonymousIcon');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
54
70
|
}
|
|
55
71
|
else if (this._user.isReady && identity) {
|
|
56
72
|
return h.div({
|
package/package.json
CHANGED