@jupyter/chat 0.6.2 → 0.7.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.
- package/lib/components/chat-input.js +12 -6
- package/lib/components/chat-messages.d.ts +10 -9
- package/lib/components/chat-messages.js +77 -63
- package/lib/components/chat.js +5 -2
- package/lib/components/code-blocks/index.d.ts +2 -0
- package/lib/components/code-blocks/index.js +6 -0
- package/lib/components/index.d.ts +10 -0
- package/lib/components/index.js +14 -0
- package/lib/components/input/cancel-button.d.ts +0 -1
- package/lib/components/input/cancel-button.js +1 -2
- package/lib/components/input/index.d.ts +2 -0
- package/lib/components/input/index.js +6 -0
- package/lib/components/markdown-renderer.d.ts +37 -0
- package/lib/components/{rendermime-markdown.js → markdown-renderer.js} +10 -8
- package/lib/components/mui-extras/index.d.ts +3 -0
- package/lib/components/mui-extras/index.js +7 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/model.d.ts +4 -0
- package/lib/model.js +3 -0
- package/lib/types.d.ts +0 -4
- package/package.json +2 -1
- package/src/components/chat-input.tsx +14 -11
- package/src/components/chat-messages.tsx +151 -129
- package/src/components/chat.tsx +3 -0
- package/src/components/code-blocks/index.ts +7 -0
- package/src/components/index.ts +15 -0
- package/src/components/input/cancel-button.tsx +0 -3
- package/src/components/input/index.ts +7 -0
- package/src/components/{rendermime-markdown.tsx → markdown-renderer.tsx} +36 -10
- package/src/components/mui-extras/index.ts +8 -0
- package/src/index.ts +1 -0
- package/src/model.ts +9 -0
- package/src/types.ts +0 -4
- package/style/chat.css +14 -6
- package/lib/components/mui-extras/stacking-alert.d.ts +0 -28
- package/lib/components/mui-extras/stacking-alert.js +0 -56
- package/lib/components/rendermime-markdown.d.ts +0 -14
- package/src/components/mui-extras/stacking-alert.tsx +0 -105
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { AlertColor } from '@mui/material';
|
|
3
|
-
export type StackingAlert = {
|
|
4
|
-
/**
|
|
5
|
-
* A function that triggers an alert. Successive alerts are indicated in the
|
|
6
|
-
* JSX element.
|
|
7
|
-
* @param alertType Type of alert.
|
|
8
|
-
* @param msg Message contained within the alert.
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
show: (alertType: AlertColor, msg: string | Error) => void;
|
|
12
|
-
/**
|
|
13
|
-
* The Alert JSX element that should be rendered by the consumer.
|
|
14
|
-
* This will be `null` if no alerts were triggered.
|
|
15
|
-
*/
|
|
16
|
-
jsx: JSX.Element | null;
|
|
17
|
-
/**
|
|
18
|
-
* An async function that closes the alert, and returns a Promise that
|
|
19
|
-
* resolves when the onClose animation is completed.
|
|
20
|
-
*/
|
|
21
|
-
clear: () => void | Promise<void>;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Hook that returns a function to trigger an alert, and a corresponding alert
|
|
25
|
-
* JSX element for the consumer to render. The number of successive identical
|
|
26
|
-
* alerts `X` is indicated in the element via the suffix "(X)".
|
|
27
|
-
*/
|
|
28
|
-
export declare function useStackingAlert(): StackingAlert;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Jupyter Development Team.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
import React, { useState, useMemo, useCallback } from 'react';
|
|
6
|
-
import { Alert, Collapse } from '@mui/material';
|
|
7
|
-
/**
|
|
8
|
-
* Hook that returns a function to trigger an alert, and a corresponding alert
|
|
9
|
-
* JSX element for the consumer to render. The number of successive identical
|
|
10
|
-
* alerts `X` is indicated in the element via the suffix "(X)".
|
|
11
|
-
*/
|
|
12
|
-
export function useStackingAlert() {
|
|
13
|
-
const [type, setType] = useState(null);
|
|
14
|
-
const [msg, setMsg] = useState('');
|
|
15
|
-
const [repeatCount, setRepeatCount] = useState(0);
|
|
16
|
-
const [expand, setExpand] = useState(false);
|
|
17
|
-
const [exitPromise, setExitPromise] = useState();
|
|
18
|
-
const [exitPromiseResolver, setExitPromiseResolver] = useState();
|
|
19
|
-
const showAlert = useCallback((nextType, _nextMsg) => {
|
|
20
|
-
// if the alert is identical to the previous alert, increment the
|
|
21
|
-
// `repeatCount` indicator.
|
|
22
|
-
const nextMsg = _nextMsg.toString();
|
|
23
|
-
if (nextType === type && nextMsg === msg) {
|
|
24
|
-
setRepeatCount(currCount => currCount + 1);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (type === null) {
|
|
28
|
-
// if this alert is being shown for the first time, initialize the
|
|
29
|
-
// exitPromise so we can await it on `clear()`.
|
|
30
|
-
setExitPromise(new Promise(res => {
|
|
31
|
-
setExitPromiseResolver(() => res);
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
setType(nextType);
|
|
35
|
-
setMsg(nextMsg);
|
|
36
|
-
setRepeatCount(0);
|
|
37
|
-
setExpand(true);
|
|
38
|
-
}, [msg, type]);
|
|
39
|
-
const alertJsx = useMemo(() => (React.createElement(Collapse, { in: expand, onExited: () => {
|
|
40
|
-
exitPromiseResolver === null || exitPromiseResolver === void 0 ? void 0 : exitPromiseResolver();
|
|
41
|
-
// only clear the alert after the Collapse exits, otherwise the alert
|
|
42
|
-
// disappears without any animation.
|
|
43
|
-
setType(null);
|
|
44
|
-
setMsg('');
|
|
45
|
-
setRepeatCount(0);
|
|
46
|
-
}, timeout: 200 }, type !== null && (React.createElement(Alert, { severity: type }, msg + (repeatCount ? ` (${repeatCount})` : ''))))), [msg, repeatCount, type, expand, exitPromiseResolver]);
|
|
47
|
-
const clearAlert = useCallback(() => {
|
|
48
|
-
setExpand(false);
|
|
49
|
-
return exitPromise;
|
|
50
|
-
}, [expand, exitPromise]);
|
|
51
|
-
return {
|
|
52
|
-
show: showAlert,
|
|
53
|
-
jsx: alertJsx,
|
|
54
|
-
clear: clearAlert
|
|
55
|
-
};
|
|
56
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { IChatModel } from '../model';
|
|
4
|
-
type RendermimeMarkdownProps = {
|
|
5
|
-
markdownStr: string;
|
|
6
|
-
rmRegistry: IRenderMimeRegistry;
|
|
7
|
-
appendContent?: boolean;
|
|
8
|
-
model: IChatModel;
|
|
9
|
-
edit?: () => void;
|
|
10
|
-
delete?: () => void;
|
|
11
|
-
};
|
|
12
|
-
declare function RendermimeMarkdownBase(props: RendermimeMarkdownProps): JSX.Element;
|
|
13
|
-
export declare const RendermimeMarkdown: React.MemoExoticComponent<typeof RendermimeMarkdownBase>;
|
|
14
|
-
export {};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Jupyter Development Team.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import React, { useState, useMemo, useCallback } from 'react';
|
|
7
|
-
import { Alert, AlertColor, Collapse } from '@mui/material';
|
|
8
|
-
|
|
9
|
-
export type StackingAlert = {
|
|
10
|
-
/**
|
|
11
|
-
* A function that triggers an alert. Successive alerts are indicated in the
|
|
12
|
-
* JSX element.
|
|
13
|
-
* @param alertType Type of alert.
|
|
14
|
-
* @param msg Message contained within the alert.
|
|
15
|
-
* @returns
|
|
16
|
-
*/
|
|
17
|
-
show: (alertType: AlertColor, msg: string | Error) => void;
|
|
18
|
-
/**
|
|
19
|
-
* The Alert JSX element that should be rendered by the consumer.
|
|
20
|
-
* This will be `null` if no alerts were triggered.
|
|
21
|
-
*/
|
|
22
|
-
jsx: JSX.Element | null;
|
|
23
|
-
/**
|
|
24
|
-
* An async function that closes the alert, and returns a Promise that
|
|
25
|
-
* resolves when the onClose animation is completed.
|
|
26
|
-
*/
|
|
27
|
-
clear: () => void | Promise<void>;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Hook that returns a function to trigger an alert, and a corresponding alert
|
|
32
|
-
* JSX element for the consumer to render. The number of successive identical
|
|
33
|
-
* alerts `X` is indicated in the element via the suffix "(X)".
|
|
34
|
-
*/
|
|
35
|
-
export function useStackingAlert(): StackingAlert {
|
|
36
|
-
const [type, setType] = useState<AlertColor | null>(null);
|
|
37
|
-
const [msg, setMsg] = useState<string>('');
|
|
38
|
-
const [repeatCount, setRepeatCount] = useState(0);
|
|
39
|
-
const [expand, setExpand] = useState(false);
|
|
40
|
-
const [exitPromise, setExitPromise] = useState<Promise<void>>();
|
|
41
|
-
const [exitPromiseResolver, setExitPromiseResolver] = useState<() => void>();
|
|
42
|
-
|
|
43
|
-
const showAlert = useCallback(
|
|
44
|
-
(nextType: AlertColor, _nextMsg: string | Error) => {
|
|
45
|
-
// if the alert is identical to the previous alert, increment the
|
|
46
|
-
// `repeatCount` indicator.
|
|
47
|
-
const nextMsg = _nextMsg.toString();
|
|
48
|
-
if (nextType === type && nextMsg === msg) {
|
|
49
|
-
setRepeatCount(currCount => currCount + 1);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (type === null) {
|
|
54
|
-
// if this alert is being shown for the first time, initialize the
|
|
55
|
-
// exitPromise so we can await it on `clear()`.
|
|
56
|
-
setExitPromise(
|
|
57
|
-
new Promise(res => {
|
|
58
|
-
setExitPromiseResolver(() => res);
|
|
59
|
-
})
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
setType(nextType);
|
|
64
|
-
setMsg(nextMsg);
|
|
65
|
-
setRepeatCount(0);
|
|
66
|
-
setExpand(true);
|
|
67
|
-
},
|
|
68
|
-
[msg, type]
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const alertJsx = useMemo(
|
|
72
|
-
() => (
|
|
73
|
-
<Collapse
|
|
74
|
-
in={expand}
|
|
75
|
-
onExited={() => {
|
|
76
|
-
exitPromiseResolver?.();
|
|
77
|
-
// only clear the alert after the Collapse exits, otherwise the alert
|
|
78
|
-
// disappears without any animation.
|
|
79
|
-
setType(null);
|
|
80
|
-
setMsg('');
|
|
81
|
-
setRepeatCount(0);
|
|
82
|
-
}}
|
|
83
|
-
timeout={200}
|
|
84
|
-
>
|
|
85
|
-
{type !== null && (
|
|
86
|
-
<Alert severity={type}>
|
|
87
|
-
{msg + (repeatCount ? ` (${repeatCount})` : '')}
|
|
88
|
-
</Alert>
|
|
89
|
-
)}
|
|
90
|
-
</Collapse>
|
|
91
|
-
),
|
|
92
|
-
[msg, repeatCount, type, expand, exitPromiseResolver]
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const clearAlert = useCallback(() => {
|
|
96
|
-
setExpand(false);
|
|
97
|
-
return exitPromise;
|
|
98
|
-
}, [expand, exitPromise]);
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
show: showAlert,
|
|
102
|
-
jsx: alertJsx,
|
|
103
|
-
clear: clearAlert
|
|
104
|
-
};
|
|
105
|
-
}
|