@jupyter/chat 0.24.0 → 0.24.1
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.
|
@@ -12,6 +12,11 @@ import { useChatContext } from '../../context';
|
|
|
12
12
|
import { replaceMentionToSpan } from '../../utils';
|
|
13
13
|
const RENDERED_CLASS = 'jp-chat-rendered-message';
|
|
14
14
|
const DEFAULT_MIME_TYPE = 'text/markdown';
|
|
15
|
+
/**
|
|
16
|
+
* The class name added to an output area widget. This is required to display cell
|
|
17
|
+
* output as a message in the chat.
|
|
18
|
+
*/
|
|
19
|
+
const OUTPUT_AREA_CLASS = 'jp-OutputArea';
|
|
15
20
|
/**
|
|
16
21
|
* The message renderer base component.
|
|
17
22
|
*/
|
|
@@ -22,6 +27,7 @@ function MessageRendererBase(props) {
|
|
|
22
27
|
const [renderedContent, setRenderedContent] = useState(null);
|
|
23
28
|
// Allow edition only on text messages.
|
|
24
29
|
const [canEdit, setCanEdit] = useState(false);
|
|
30
|
+
const [isOutputArea, setIsOutputArea] = useState(false);
|
|
25
31
|
// Each element is a two-tuple with the structure [codeToolbarRoot, codeToolbarProps].
|
|
26
32
|
const [codeToolbarDefns, setCodeToolbarDefns] = useState([]);
|
|
27
33
|
useEffect(() => {
|
|
@@ -86,6 +92,7 @@ function MessageRendererBase(props) {
|
|
|
86
92
|
// never been attached, only the node.
|
|
87
93
|
// This is necessary to render latex.
|
|
88
94
|
MessageLoop.sendMessage(renderer, Widget.Msg.AfterAttach);
|
|
95
|
+
setIsOutputArea(!isMarkdownRenderer);
|
|
89
96
|
// Add code toolbar if markdown has been rendered.
|
|
90
97
|
if (isMarkdownRenderer) {
|
|
91
98
|
const newCodeToolbarDefns = [];
|
|
@@ -110,7 +117,7 @@ function MessageRendererBase(props) {
|
|
|
110
117
|
renderContent();
|
|
111
118
|
}, [message.body, message.mime_model, message.mentions, rmRegistry]);
|
|
112
119
|
return (React.createElement(React.Fragment, null,
|
|
113
|
-
renderedContent && (React.createElement("div", { className: RENDERED_CLASS
|
|
120
|
+
renderedContent && (React.createElement("div", { className: `${RENDERED_CLASS}${isOutputArea ? ` ${OUTPUT_AREA_CLASS}` : ''}`, ref: node => node && node.replaceChildren(renderedContent) })),
|
|
114
121
|
React.createElement(MessageToolbar, { edit: canEdit ? props.edit : undefined, delete: props.delete }),
|
|
115
122
|
// Render a `CodeToolbar` element underneath each code block.
|
|
116
123
|
// We use ReactDOM.createPortal() so each `CodeToolbar` element is able
|
package/package.json
CHANGED
|
@@ -19,6 +19,12 @@ import { replaceMentionToSpan } from '../../utils';
|
|
|
19
19
|
const RENDERED_CLASS = 'jp-chat-rendered-message';
|
|
20
20
|
const DEFAULT_MIME_TYPE = 'text/markdown';
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* The class name added to an output area widget. This is required to display cell
|
|
24
|
+
* output as a message in the chat.
|
|
25
|
+
*/
|
|
26
|
+
const OUTPUT_AREA_CLASS = 'jp-OutputArea';
|
|
27
|
+
|
|
22
28
|
/**
|
|
23
29
|
* The type of the props for the MessageRenderer component.
|
|
24
30
|
*/
|
|
@@ -56,6 +62,8 @@ function MessageRendererBase(props: MessageRendererProps): JSX.Element {
|
|
|
56
62
|
// Allow edition only on text messages.
|
|
57
63
|
const [canEdit, setCanEdit] = useState<boolean>(false);
|
|
58
64
|
|
|
65
|
+
const [isOutputArea, setIsOutputArea] = useState<boolean>(false);
|
|
66
|
+
|
|
59
67
|
// Each element is a two-tuple with the structure [codeToolbarRoot, codeToolbarProps].
|
|
60
68
|
const [codeToolbarDefns, setCodeToolbarDefns] = useState<
|
|
61
69
|
Array<[HTMLDivElement, CodeToolbarProps]>
|
|
@@ -129,6 +137,8 @@ function MessageRendererBase(props: MessageRendererProps): JSX.Element {
|
|
|
129
137
|
// This is necessary to render latex.
|
|
130
138
|
MessageLoop.sendMessage(renderer, Widget.Msg.AfterAttach);
|
|
131
139
|
|
|
140
|
+
setIsOutputArea(!isMarkdownRenderer);
|
|
141
|
+
|
|
132
142
|
// Add code toolbar if markdown has been rendered.
|
|
133
143
|
if (isMarkdownRenderer) {
|
|
134
144
|
const newCodeToolbarDefns: [HTMLDivElement, CodeToolbarProps][] = [];
|
|
@@ -164,7 +174,7 @@ function MessageRendererBase(props: MessageRendererProps): JSX.Element {
|
|
|
164
174
|
<>
|
|
165
175
|
{renderedContent && (
|
|
166
176
|
<div
|
|
167
|
-
className={RENDERED_CLASS}
|
|
177
|
+
className={`${RENDERED_CLASS}${isOutputArea ? ` ${OUTPUT_AREA_CLASS}` : ''}`}
|
|
168
178
|
ref={node => node && node.replaceChildren(renderedContent)}
|
|
169
179
|
/>
|
|
170
180
|
)}
|