@jupyter/chat 0.5.0 → 0.6.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.
@@ -86,7 +86,7 @@ type AvatarProps = {
86
86
  small?: boolean;
87
87
  };
88
88
  /**
89
- * the avatar component.
89
+ * The avatar component.
90
90
  */
91
91
  export declare function Avatar(props: AvatarProps): JSX.Element | null;
92
92
  export {};
@@ -358,9 +358,10 @@ export function Navigation(props) {
358
358
  React.createElement(LabIcon.resolveReact, { display: 'flex', icon: caretDownEmptyIcon, iconClass: classes('jp-Icon') })))));
359
359
  }
360
360
  /**
361
- * the avatar component.
361
+ * The avatar component.
362
362
  */
363
363
  export function Avatar(props) {
364
+ var _a, _b;
364
365
  const { user } = props;
365
366
  const sharedStyles = {
366
367
  height: `${props.small ? '16' : '24'}px`,
@@ -368,11 +369,12 @@ export function Avatar(props) {
368
369
  bgcolor: user.color,
369
370
  fontSize: `var(--jp-ui-font-size${props.small ? '0' : '1'})`
370
371
  };
372
+ const name = (_b = (_a = user.display_name) !== null && _a !== void 0 ? _a : user.name) !== null && _b !== void 0 ? _b : (user.username || 'User undefined');
371
373
  return user.avatar_url ? (React.createElement(MuiAvatar, { sx: {
372
374
  ...sharedStyles
373
- }, src: user.avatar_url })) : user.initials ? (React.createElement(MuiAvatar, { sx: {
375
+ }, src: user.avatar_url, alt: name, title: name })) : user.initials ? (React.createElement(MuiAvatar, { sx: {
374
376
  ...sharedStyles
375
- } },
377
+ }, alt: name, title: name },
376
378
  React.createElement(Typography, { sx: {
377
379
  fontSize: `var(--jp-ui-font-size${props.small ? '0' : '1'})`,
378
380
  color: 'var(--jp-ui-inverse-font-color1)'
@@ -51,7 +51,7 @@ export function CodeToolbar(props) {
51
51
  display: 'flex',
52
52
  justifyContent: 'flex-end',
53
53
  alignItems: 'center',
54
- padding: '6px 2px',
54
+ padding: '2px 2px',
55
55
  marginBottom: '1em',
56
56
  border: '1px solid var(--jp-cell-editor-border-color)',
57
57
  borderTop: 'none'
@@ -32,5 +32,9 @@ export function TooltippedIconButton(props) {
32
32
  }
33
33
  } },
34
34
  React.createElement("span", { className: props.className },
35
- React.createElement(IconButton, { ...props.iconButtonProps, onClick: props.onClick, disabled: props.disabled, sx: { lineHeight: 0, ...(props.disabled && { opacity: 0.5 }) }, "aria-label": props['aria-label'] }, props.children))));
35
+ React.createElement(IconButton, { ...props.iconButtonProps, onClick: props.onClick, disabled: props.disabled, sx: {
36
+ marginLeft: '8px',
37
+ lineHeight: 0,
38
+ ...(props.disabled && { opacity: 0.5 })
39
+ }, "aria-label": props['aria-label'] }, props.children))));
36
40
  }
@@ -9,14 +9,19 @@ import { MessageToolbar } from './toolbar';
9
9
  const MD_MIME_TYPE = 'text/markdown';
10
10
  const RENDERMIME_MD_CLASS = 'jp-chat-rendermime-markdown';
11
11
  /**
12
- * Takes \( and returns \\(. Escapes LaTeX delimeters by adding extra backslashes where needed for proper rendering by @jupyterlab/rendermime.
12
+ * Escapes backslashes in LaTeX delimiters such that they appear in the DOM
13
+ * after the initial MarkDown render. For example, this function takes '\(` and
14
+ * returns `\\(`.
15
+ *
16
+ * Required for proper rendering of MarkDown + LaTeX markup in the chat by
17
+ * `ILatexTypesetter`.
13
18
  */
14
19
  function escapeLatexDelimiters(text) {
15
20
  return text
16
- .replace('\\(', '\\\\(')
17
- .replace('\\)', '\\\\)')
18
- .replace('\\[', '\\\\[')
19
- .replace('\\]', '\\\\]');
21
+ .replace('\\(/g', '\\\\(')
22
+ .replace('\\)/g', '\\\\)')
23
+ .replace('\\[/g', '\\\\[')
24
+ .replace('\\]/g', '\\\\]');
20
25
  }
21
26
  function RendermimeMarkdownBase(props) {
22
27
  const appendContent = props.appendContent || false;
@@ -25,17 +30,21 @@ function RendermimeMarkdownBase(props) {
25
30
  const [codeToolbarDefns, setCodeToolbarDefns] = useState([]);
26
31
  useEffect(() => {
27
32
  const renderContent = async () => {
28
- var _a;
33
+ var _a, _b;
34
+ // initialize mime model
29
35
  const mdStr = escapeLatexDelimiters(props.markdownStr);
30
36
  const model = props.rmRegistry.createModel({
31
37
  data: { [MD_MIME_TYPE]: mdStr }
32
38
  });
33
39
  const renderer = props.rmRegistry.createRenderer(MD_MIME_TYPE);
40
+ // step 1: render markdown
34
41
  await renderer.renderModel(model);
35
42
  (_a = props.rmRegistry.latexTypesetter) === null || _a === void 0 ? void 0 : _a.typeset(renderer.node);
36
43
  if (!renderer.node) {
37
44
  throw new Error('Rendermime was unable to render Markdown content within a chat message. Please report this upstream to Jupyter chat on GitHub.');
38
45
  }
46
+ // step 2: render LaTeX via MathJax.
47
+ (_b = props.rmRegistry.latexTypesetter) === null || _b === void 0 ? void 0 : _b.typeset(renderer.node);
39
48
  const newCodeToolbarDefns = [];
40
49
  // Attach CodeToolbar root element to each <pre> block
41
50
  const preBlocks = renderer.node.querySelectorAll('pre');
package/lib/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
+ export * from './active-cell-manager';
1
2
  export * from './icons';
2
3
  export * from './model';
3
4
  export * from './registry';
4
- export * from './types';
5
- export * from './active-cell-manager';
6
5
  export * from './selection-watcher';
6
+ export * from './types';
7
7
  export * from './widgets/chat-error';
8
8
  export * from './widgets/chat-sidebar';
9
9
  export * from './widgets/chat-widget';
package/lib/index.js CHANGED
@@ -2,12 +2,12 @@
2
2
  * Copyright (c) Jupyter Development Team.
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
+ export * from './active-cell-manager';
5
6
  export * from './icons';
6
7
  export * from './model';
7
8
  export * from './registry';
8
- export * from './types';
9
- export * from './active-cell-manager';
10
9
  export * from './selection-watcher';
10
+ export * from './types';
11
11
  export * from './widgets/chat-error';
12
12
  export * from './widgets/chat-sidebar';
13
13
  export * from './widgets/chat-widget';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter/chat",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "A package that provides UI components that can be used to create a chat in a Jupyterlab extension.",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -581,7 +581,7 @@ type AvatarProps = {
581
581
  };
582
582
 
583
583
  /**
584
- * the avatar component.
584
+ * The avatar component.
585
585
  */
586
586
  export function Avatar(props: AvatarProps): JSX.Element | null {
587
587
  const { user } = props;
@@ -593,18 +593,24 @@ export function Avatar(props: AvatarProps): JSX.Element | null {
593
593
  fontSize: `var(--jp-ui-font-size${props.small ? '0' : '1'})`
594
594
  };
595
595
 
596
+ const name =
597
+ user.display_name ?? user.name ?? (user.username || 'User undefined');
596
598
  return user.avatar_url ? (
597
599
  <MuiAvatar
598
600
  sx={{
599
601
  ...sharedStyles
600
602
  }}
601
603
  src={user.avatar_url}
604
+ alt={name}
605
+ title={name}
602
606
  ></MuiAvatar>
603
607
  ) : user.initials ? (
604
608
  <MuiAvatar
605
609
  sx={{
606
610
  ...sharedStyles
607
611
  }}
612
+ alt={name}
613
+ title={name}
608
614
  >
609
615
  <Typography
610
616
  sx={{
@@ -80,7 +80,7 @@ export function CodeToolbar(props: CodeToolbarProps): JSX.Element {
80
80
  display: 'flex',
81
81
  justifyContent: 'flex-end',
82
82
  alignItems: 'center',
83
- padding: '6px 2px',
83
+ padding: '2px 2px',
84
84
  marginBottom: '1em',
85
85
  border: '1px solid var(--jp-cell-editor-border-color)',
86
86
  borderTop: 'none'
@@ -73,7 +73,11 @@ export function TooltippedIconButton(
73
73
  {...props.iconButtonProps}
74
74
  onClick={props.onClick}
75
75
  disabled={props.disabled}
76
- sx={{ lineHeight: 0, ...(props.disabled && { opacity: 0.5 }) }}
76
+ sx={{
77
+ marginLeft: '8px',
78
+ lineHeight: 0,
79
+ ...(props.disabled && { opacity: 0.5 })
80
+ }}
77
81
  aria-label={props['aria-label']}
78
82
  >
79
83
  {props.children}
@@ -24,14 +24,19 @@ type RendermimeMarkdownProps = {
24
24
  };
25
25
 
26
26
  /**
27
- * Takes \( and returns \\(. Escapes LaTeX delimeters by adding extra backslashes where needed for proper rendering by @jupyterlab/rendermime.
27
+ * Escapes backslashes in LaTeX delimiters such that they appear in the DOM
28
+ * after the initial MarkDown render. For example, this function takes '\(` and
29
+ * returns `\\(`.
30
+ *
31
+ * Required for proper rendering of MarkDown + LaTeX markup in the chat by
32
+ * `ILatexTypesetter`.
28
33
  */
29
34
  function escapeLatexDelimiters(text: string) {
30
35
  return text
31
- .replace('\\(', '\\\\(')
32
- .replace('\\)', '\\\\)')
33
- .replace('\\[', '\\\\[')
34
- .replace('\\]', '\\\\]');
36
+ .replace('\\(/g', '\\\\(')
37
+ .replace('\\)/g', '\\\\)')
38
+ .replace('\\[/g', '\\\\[')
39
+ .replace('\\]/g', '\\\\]');
35
40
  }
36
41
 
37
42
  function RendermimeMarkdownBase(props: RendermimeMarkdownProps): JSX.Element {
@@ -47,12 +52,15 @@ function RendermimeMarkdownBase(props: RendermimeMarkdownProps): JSX.Element {
47
52
 
48
53
  useEffect(() => {
49
54
  const renderContent = async () => {
55
+ // initialize mime model
50
56
  const mdStr = escapeLatexDelimiters(props.markdownStr);
51
57
  const model = props.rmRegistry.createModel({
52
58
  data: { [MD_MIME_TYPE]: mdStr }
53
59
  });
54
60
 
55
61
  const renderer = props.rmRegistry.createRenderer(MD_MIME_TYPE);
62
+
63
+ // step 1: render markdown
56
64
  await renderer.renderModel(model);
57
65
  props.rmRegistry.latexTypesetter?.typeset(renderer.node);
58
66
  if (!renderer.node) {
@@ -61,6 +69,9 @@ function RendermimeMarkdownBase(props: RendermimeMarkdownProps): JSX.Element {
61
69
  );
62
70
  }
63
71
 
72
+ // step 2: render LaTeX via MathJax.
73
+ props.rmRegistry.latexTypesetter?.typeset(renderer.node);
74
+
64
75
  const newCodeToolbarDefns: [HTMLDivElement, CodeToolbarProps][] = [];
65
76
 
66
77
  // Attach CodeToolbar root element to each <pre> block
package/src/index.ts CHANGED
@@ -3,12 +3,12 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
 
6
+ export * from './active-cell-manager';
6
7
  export * from './icons';
7
8
  export * from './model';
8
9
  export * from './registry';
9
- export * from './types';
10
- export * from './active-cell-manager';
11
10
  export * from './selection-watcher';
11
+ export * from './types';
12
12
  export * from './widgets/chat-error';
13
13
  export * from './widgets/chat-sidebar';
14
14
  export * from './widgets/chat-widget';