@memori.ai/memori-react 7.8.5 → 7.8.7
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/CHANGELOG.md +14 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js +1 -1
- package/dist/components/Snippet/Snippet.d.ts +1 -2
- package/dist/components/Snippet/Snippet.js +36 -25
- package/dist/components/Snippet/Snippet.js.map +1 -1
- package/dist/components/WhyThisAnswer/WhyThisAnswer.js +1 -1
- package/dist/components/WhyThisAnswer/WhyThisAnswer.js.map +1 -1
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js +1 -1
- package/esm/components/Snippet/Snippet.d.ts +1 -2
- package/esm/components/Snippet/Snippet.js +36 -25
- package/esm/components/Snippet/Snippet.js.map +1 -1
- package/esm/components/WhyThisAnswer/WhyThisAnswer.js +1 -1
- package/esm/components/WhyThisAnswer/WhyThisAnswer.js.map +1 -1
- package/package.json +1 -2
- package/src/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.ts +1 -1
- package/src/components/MediaWidget/__snapshots__/MediaItemWidget.test.tsx.snap +5 -88
- package/src/components/Snippet/Snippet.stories.tsx +0 -8
- package/src/components/Snippet/Snippet.test.tsx +0 -1
- package/src/components/Snippet/Snippet.tsx +55 -36
- package/src/components/Snippet/__snapshots__/Snippet.test.tsx.snap +66 -2544
- package/src/components/WhyThisAnswer/WhyThisAnswer.tsx +0 -1
|
@@ -1,66 +1,85 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import { Medium } from '@memori.ai/memori-api-client/dist/types';
|
|
3
3
|
import Button from '../ui/Button';
|
|
4
4
|
import Copy from '../icons/Copy';
|
|
5
5
|
import { prismSyntaxLangs } from '../../helpers/constants';
|
|
6
|
-
import { PrismAsyncLight as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
7
|
-
import { atomDark } from 'react-syntax-highlighter/dist/cjs/styles/prism';
|
|
8
|
-
import tsx from 'react-syntax-highlighter/dist/cjs/languages/prism/tsx';
|
|
9
|
-
import json from 'react-syntax-highlighter/dist/cjs/languages/prism/json';
|
|
10
|
-
import scss from 'react-syntax-highlighter/dist/cjs/languages/prism/scss';
|
|
11
|
-
import bash from 'react-syntax-highlighter/dist/cjs/languages/prism/bash';
|
|
12
|
-
import python from 'react-syntax-highlighter/dist/cjs/languages/prism/python';
|
|
13
|
-
import cpp from 'react-syntax-highlighter/dist/cjs/languages/prism/cpp';
|
|
14
|
-
import php from 'react-syntax-highlighter/dist/cjs/languages/prism/php';
|
|
15
|
-
import ruby from 'react-syntax-highlighter/dist/cjs/languages/prism/ruby';
|
|
16
|
-
import sql from 'react-syntax-highlighter/dist/cjs/languages/prism/sql';
|
|
17
6
|
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import cx from 'classnames';
|
|
18
8
|
|
|
19
9
|
export interface Props {
|
|
20
10
|
medium: Medium;
|
|
21
11
|
className?: string;
|
|
22
12
|
preview?: boolean;
|
|
23
|
-
showLineNumbers?: boolean;
|
|
24
13
|
showCopyButton?: boolean;
|
|
25
14
|
}
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
const loadPrismScripts = () => {
|
|
17
|
+
const existingScript = document.getElementById('memori-prism-script');
|
|
18
|
+
if (existingScript) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const script = document.createElement('script');
|
|
23
|
+
script.src = 'https://cdn.jsdelivr.net/npm/prismjs@1.29.0/prism.min.js';
|
|
24
|
+
script.async = true;
|
|
25
|
+
script.id = 'memori-prism-script';
|
|
26
|
+
|
|
27
|
+
const autoloaderScript = document.createElement('script');
|
|
28
|
+
autoloaderScript.src =
|
|
29
|
+
'https://cdn.jsdelivr.net/npm/prismjs@v1.29.0/plugins/autoloader/prism-autoloader.min.js';
|
|
30
|
+
autoloaderScript.async = true;
|
|
31
|
+
autoloaderScript.id = 'memori-prism-autoloader-script';
|
|
32
|
+
|
|
33
|
+
const prismCss = document.createElement('link');
|
|
34
|
+
prismCss.rel = 'stylesheet';
|
|
35
|
+
prismCss.href =
|
|
36
|
+
'https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/prism-tomorrow.min.css';
|
|
37
|
+
|
|
38
|
+
document.head.appendChild(prismCss);
|
|
39
|
+
|
|
40
|
+
document.head.appendChild(script);
|
|
41
|
+
document.head.appendChild(autoloaderScript);
|
|
42
|
+
};
|
|
37
43
|
|
|
38
44
|
const Snippet = ({
|
|
39
45
|
medium,
|
|
40
46
|
className,
|
|
41
47
|
preview = false,
|
|
42
|
-
showLineNumbers = true,
|
|
43
48
|
showCopyButton = true,
|
|
44
49
|
}: Props) => {
|
|
45
50
|
const { t } = useTranslation();
|
|
46
51
|
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
loadPrismScripts();
|
|
54
|
+
}, []);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
// eslint-disable-next-line no-undef
|
|
59
|
+
if ('Prism' in window && window.Prism.highlightAll) Prism.highlightAll();
|
|
60
|
+
}, [medium.content]);
|
|
61
|
+
|
|
47
62
|
return (
|
|
48
63
|
<div className="memori-snippet">
|
|
49
64
|
<div className="memori-snippet--content">
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
showLineNumbers={showLineNumbers}
|
|
55
|
-
language={
|
|
56
|
-
prismSyntaxLangs.find(l => medium.mimeType === l.mimeType)?.lang ??
|
|
57
|
-
'text'
|
|
65
|
+
<pre
|
|
66
|
+
className={cx('line-numbers', className)}
|
|
67
|
+
aria-labelledby={
|
|
68
|
+
!!medium.title?.length ? `#snippet-${medium.mediumID}` : undefined
|
|
58
69
|
}
|
|
59
70
|
>
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
<code
|
|
72
|
+
className={`language-${
|
|
73
|
+
prismSyntaxLangs.find(l => medium.mimeType === l.mimeType)
|
|
74
|
+
?.lang ?? 'text'
|
|
75
|
+
}`}
|
|
76
|
+
>
|
|
77
|
+
{medium.content?.length && medium.content.length > 200 && preview
|
|
78
|
+
? `${medium.content.slice(0, 200)}\n...`
|
|
79
|
+
: `${medium.content}`}
|
|
80
|
+
</code>
|
|
81
|
+
</pre>
|
|
82
|
+
|
|
64
83
|
{showCopyButton && (
|
|
65
84
|
<Button
|
|
66
85
|
padded={false}
|