@skbkontur/markdown 2.6.3 → 2.7.0-alpha.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/package.json +2 -2
- package/src/Markdown/Emoji/Emoji.logic.js +4 -4
- package/src/Markdown/Emoji/Emoji.styled.js +14 -21
- package/src/Markdown/Emoji/EmojiDropdown.js +6 -11
- package/src/Markdown/Emoji/helpers.js +4 -4
- package/src/Markdown/Files/Files.logic.js +46 -108
- package/src/Markdown/Markdown.creevey.js +73 -221
- package/src/Markdown/Markdown.js +62 -86
- package/src/Markdown/Markdown.styled.js +251 -90
- package/src/Markdown/MarkdownActions/AIActionsDropdown/AIActionsDropdown.js +45 -111
- package/src/Markdown/MarkdownActions/AIActionsDropdown/AIActionsDropdown.styled.js +16 -8
- package/src/Markdown/MarkdownActions/AIActionsDropdown/constants.js +2 -2
- package/src/Markdown/MarkdownActions/MarkdownActions.js +24 -37
- package/src/Markdown/MarkdownActions/MarkdownDropdown/MarkdownDropdown.js +3 -7
- package/src/Markdown/MarkdownActions/MarkdownDropdown/MarkdownDropdown.styled.js +8 -6
- package/src/Markdown/MarkdownEditor.js +6 -28
- package/src/Markdown/MarkdownHelpItems.js +61 -63
- package/src/Markdown/MarkdownHelpers/EmptyPreview.js +1 -1
- package/src/Markdown/MarkdownHelpers/MarkdownFormatButton.js +6 -7
- package/src/Markdown/MarkdownHelpers/constants.js +2 -2
- package/src/Markdown/MarkdownHelpers/markdownHelpers.d.ts +1 -0
- package/src/Markdown/MarkdownHelpers/markdownHelpers.js +50 -47
- package/src/Markdown/MarkdownHelpers/markdownListEnterHelpers.d.ts +2 -0
- package/src/Markdown/MarkdownHelpers/markdownListEnterHelpers.js +45 -0
- package/src/Markdown/MarkdownHelpers/markdownMentionHelpers.js +12 -12
- package/src/Markdown/MarkdownHelpers/markdownTextareaHelpers.js +34 -36
- package/src/Markdown/MarkdownMention.js +18 -64
- package/src/Markdown/constants.js +6 -6
- package/src/Markdown/utils/guid.js +13 -18
- package/src/Markdown/utils/htmlToMd.js +2 -2
- package/src/Markdown/utils/onInsertText.d.ts +1 -0
- package/src/Markdown/utils/onInsertText.js +3 -0
- package/src/Markdown/utils/saveFile.js +4 -4
- package/src/MarkdownCombination/MarkdownCombination.js +8 -9
- package/src/MarkdownCombination/MarkdownCombination.styled.js +7 -6
- package/src/MarkdownIcons/AttachLink.js +2 -2
- package/src/MarkdownIcons/AttachPaperclip.js +2 -2
- package/src/MarkdownIcons/CheckboxCheckedIcon.js +2 -2
- package/src/MarkdownIcons/CheckboxUncheckedIcon.js +2 -2
- package/src/MarkdownIcons/CheckedList.js +2 -2
- package/src/MarkdownIcons/Collapse.js +2 -2
- package/src/MarkdownIcons/Copy.js +1 -1
- package/src/MarkdownIcons/DocIcon.js +2 -2
- package/src/MarkdownIcons/EmojiFace.js +2 -2
- package/src/MarkdownIcons/EmptyPrviewArrow.js +1 -1
- package/src/MarkdownIcons/Expand.js +2 -2
- package/src/MarkdownIcons/EyeOpen.js +2 -2
- package/src/MarkdownIcons/List.js +2 -2
- package/src/MarkdownIcons/MarkdownIcons.styled.js +3 -6
- package/src/MarkdownIcons/NatureFxSparkleA2.js +1 -1
- package/src/MarkdownIcons/NumberedList.js +2 -2
- package/src/MarkdownIcons/SplitView.js +1 -1
- package/src/MarkdownIcons/Table.js +2 -2
- package/src/MarkdownIcons/ToolPencil.js +2 -2
- package/src/MarkdownViewer/Helpers/MarkdownImage.js +1 -2
- package/src/MarkdownViewer/Helpers/MarkdownLink.js +1 -4
- package/src/MarkdownViewer/Helpers/MarkdownTable.js +1 -2
- package/src/MarkdownViewer/MarkdownViewer.js +18 -26
- package/src/MarkdownViewer/MarkdownViewer.styles.js +163 -19
- package/src/styles/styled-components.js +1 -1
- package/src/styles/theme.js +5 -5
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ImgHref } from '../MarkdownViewer.styles';
|
|
3
|
-
export
|
|
4
|
-
var src = _a.src;
|
|
3
|
+
export const MarkdownImage = ({ src }) => {
|
|
5
4
|
return (React.createElement(ImgHref, { "aria-label": "\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0435", href: src, target: "_blank", rel: "noopener noreferrer" },
|
|
6
5
|
React.createElement("img", { src: src, alt: "" })));
|
|
7
6
|
};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Href } from '../MarkdownViewer.styles';
|
|
3
|
-
export
|
|
4
|
-
var href = _a.href, children = _a.children, target = _a.target;
|
|
5
|
-
return (React.createElement(Href, { href: href, target: target !== null && target !== void 0 ? target : '_blank', rel: "noopener noreferrer" }, children));
|
|
6
|
-
};
|
|
3
|
+
export const MarkdownLink = ({ href, children, target }) => (React.createElement(Href, { href: href, target: target ?? '_blank', rel: "noopener noreferrer" }, children));
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Table, TableWrapper } from '../MarkdownViewer.styles';
|
|
3
|
-
export
|
|
4
|
-
var children = _a.children;
|
|
3
|
+
export const MarkdownTable = ({ children }) => {
|
|
5
4
|
return (React.createElement(TableWrapper, null,
|
|
6
5
|
React.createElement(Table, null, children)));
|
|
7
6
|
};
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import { Button } from '@skbkontur/react-ui';
|
|
13
2
|
import React from 'react';
|
|
14
3
|
import ReactMarkdown from 'react-markdown';
|
|
@@ -28,24 +17,27 @@ import { CheckboxCheckedIcon } from '../MarkdownIcons/CheckboxCheckedIcon';
|
|
|
28
17
|
import { CheckboxUncheckedIcon } from '../MarkdownIcons/CheckboxUncheckedIcon';
|
|
29
18
|
import { ThemeProvider } from '../styles/styled-components';
|
|
30
19
|
import { DEFAULT_MARKDOWN_THEME, MarkdownThemeConsumer } from '../styles/theme';
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
var downloadFile = useFileLogic(undefined, downloadFileApi).downloadFile;
|
|
20
|
+
export const MarkdownViewer = ({ source, fileApiUrl = '', profileUrl = '', downloadFileApi, }) => {
|
|
21
|
+
const { downloadFile } = useFileLogic(undefined, downloadFileApi);
|
|
34
22
|
if (!source) {
|
|
35
23
|
return null;
|
|
36
24
|
}
|
|
37
|
-
return (React.createElement(MarkdownThemeConsumer, null,
|
|
25
|
+
return (React.createElement(MarkdownThemeConsumer, null, theme => (React.createElement(ThemeProvider, { theme: theme ?? DEFAULT_MARKDOWN_THEME },
|
|
38
26
|
React.createElement(Wrapper, { "aria-label": "\u0424\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u0442\u0435\u043A\u0441\u0442" },
|
|
39
27
|
React.createElement(ReactMarkdown, { components: getCustomComponents(), remarkPlugins: [gfm, remarkMath, remarkBreaks], rehypePlugins: [
|
|
40
28
|
rehypeRaw,
|
|
41
29
|
[
|
|
42
30
|
rehypeSanitize,
|
|
43
31
|
{
|
|
44
|
-
attributes:
|
|
32
|
+
attributes: {
|
|
33
|
+
...defaultSchema.attributes,
|
|
34
|
+
div: [['className', /^language-./, 'math-inline', 'math-display', 'math']],
|
|
35
|
+
span: [['className', /^language-./, 'math-inline', 'math-display', 'math']],
|
|
36
|
+
},
|
|
45
37
|
},
|
|
46
38
|
],
|
|
47
39
|
rehypeKatex,
|
|
48
|
-
], linkTarget: "_blank" }, source))))
|
|
40
|
+
], linkTarget: "_blank" }, source))))));
|
|
49
41
|
function getCustomComponents() {
|
|
50
42
|
return {
|
|
51
43
|
a: renderLink,
|
|
@@ -53,22 +45,22 @@ export var MarkdownViewer = function (_a) {
|
|
|
53
45
|
input: renderInput,
|
|
54
46
|
ul: renderList,
|
|
55
47
|
ol: renderOrderedList,
|
|
56
|
-
blockquote:
|
|
57
|
-
p:
|
|
58
|
-
img:
|
|
59
|
-
table:
|
|
48
|
+
blockquote: props => React.createElement(BlockQuote, null, props.children),
|
|
49
|
+
p: props => React.createElement(Paragraph, null, props.children),
|
|
50
|
+
img: props => React.createElement(MarkdownImage, { src: props.src ?? '' }),
|
|
51
|
+
table: props => React.createElement(MarkdownTable, null, props.children),
|
|
60
52
|
};
|
|
61
53
|
}
|
|
62
54
|
function renderListItem(props) {
|
|
63
|
-
|
|
55
|
+
const children = props.children;
|
|
64
56
|
return checkIfChecklistItem(props) ? React.createElement(CheckListItem, null, children) : React.createElement(ListItem, null, children);
|
|
65
57
|
}
|
|
66
58
|
function renderLink(props) {
|
|
67
|
-
|
|
59
|
+
const { href = '', children } = props;
|
|
68
60
|
if (fileApiUrl && href.startsWith(fileApiUrl)) {
|
|
69
|
-
|
|
61
|
+
const id = href.replace(fileApiUrl, '');
|
|
70
62
|
return (React.createElement(FileButtonWrapper, null,
|
|
71
|
-
React.createElement(Button, { use: "link", icon: React.createElement(AttachPaperclip, null), onClick:
|
|
63
|
+
React.createElement(Button, { use: "link", icon: React.createElement(AttachPaperclip, null), onClick: () => downloadFile(id) },
|
|
72
64
|
React.createElement(FileName, null, children),
|
|
73
65
|
React.createElement(VisuallyHidden, null,
|
|
74
66
|
"\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u0444\u0430\u0439\u043B $",
|
|
@@ -86,6 +78,6 @@ export var MarkdownViewer = function (_a) {
|
|
|
86
78
|
return React.createElement("ul", { style: getListStyle(!!props.depth) }, props.children);
|
|
87
79
|
}
|
|
88
80
|
function renderOrderedList(props) {
|
|
89
|
-
return React.createElement("ol", { style: getListStyle(!!
|
|
81
|
+
return React.createElement("ol", { style: getListStyle(!!props?.depth) }, props.children);
|
|
90
82
|
}
|
|
91
83
|
};
|
|
@@ -1,23 +1,167 @@
|
|
|
1
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
-
return cooked;
|
|
4
|
-
};
|
|
5
1
|
import styled, { css } from '../styles/styled-components';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
const baseVisuallyHiddenStyle = css `
|
|
3
|
+
position: absolute;
|
|
4
|
+
width: 1px;
|
|
5
|
+
height: 1px;
|
|
6
|
+
padding: 0;
|
|
7
|
+
margin: -1px;
|
|
8
|
+
overflow: hidden;
|
|
9
|
+
clip: rect(0, 0, 0, 0);
|
|
10
|
+
border: 0;
|
|
11
|
+
`;
|
|
12
|
+
export const CheckBoxWrapper = styled.span `
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
align-items: baseline;
|
|
15
|
+
transform: translateX(-10%);
|
|
16
|
+
`;
|
|
17
|
+
export const Wrapper = styled.div `
|
|
18
|
+
overflow-wrap: break-word;
|
|
19
|
+
word-wrap: break-word;
|
|
20
|
+
position: relative;
|
|
21
|
+
|
|
22
|
+
word-break: break-word;
|
|
23
|
+
|
|
24
|
+
p,
|
|
25
|
+
hr,
|
|
26
|
+
table,
|
|
27
|
+
blockquote {
|
|
28
|
+
margin-bottom: 16px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
ul > li > ${CheckBoxWrapper}, ul > li > p > ${CheckBoxWrapper} {
|
|
32
|
+
display: inline-flex;
|
|
33
|
+
position: absolute;
|
|
34
|
+
inset-inline-start: 0;
|
|
35
|
+
inset-block-start: 0;
|
|
36
|
+
padding: 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
ul,
|
|
40
|
+
ol,
|
|
41
|
+
li {
|
|
42
|
+
p {
|
|
43
|
+
margin: 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
h1 {
|
|
48
|
+
margin-top: 36px;
|
|
49
|
+
margin-bottom: 28px;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
h2 {
|
|
53
|
+
margin-top: 32px;
|
|
54
|
+
margin-bottom: 24px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
h3 {
|
|
58
|
+
margin-top: 28px;
|
|
59
|
+
margin-bottom: 20px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
h4 {
|
|
63
|
+
margin-top: 24px;
|
|
64
|
+
margin-bottom: 16px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
img {
|
|
68
|
+
max-width: 100%;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
button {
|
|
72
|
+
text-align: left;
|
|
73
|
+
color: ${p => p.theme?.colors?.link};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
table {
|
|
77
|
+
background: transparent;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
blockquote {
|
|
81
|
+
margin: 24px 0;
|
|
82
|
+
padding-left: 16px;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
hr {
|
|
86
|
+
margin-top: 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
code {
|
|
90
|
+
display: inline-block;
|
|
91
|
+
white-space: pre-wrap;
|
|
92
|
+
padding: 4px;
|
|
93
|
+
border-radius: 8px;
|
|
94
|
+
border: 1px solid ${p => p.theme?.colors?.grayDefault};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
ul,
|
|
98
|
+
ol {
|
|
99
|
+
padding-inline-start: 0;
|
|
100
|
+
|
|
101
|
+
li {
|
|
102
|
+
margin-inline-start: 0;
|
|
103
|
+
margin: 8px 0 8px 20px;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.math {
|
|
108
|
+
[aria-hidden='true'] {
|
|
109
|
+
${baseVisuallyHiddenStyle};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
& > *:first-child {
|
|
114
|
+
margin-top: 0 !important;
|
|
115
|
+
padding-top: 0 !important;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
& > *:last-child {
|
|
119
|
+
margin-bottom: 0 !important;
|
|
120
|
+
padding-bottom: 0 !important;
|
|
121
|
+
}
|
|
122
|
+
`;
|
|
123
|
+
export const CheckListItem = styled.li `
|
|
124
|
+
list-style: none;
|
|
125
|
+
margin-left: 0 !important;
|
|
126
|
+
padding-inline-start: 22px;
|
|
127
|
+
position: relative;
|
|
128
|
+
`;
|
|
129
|
+
export const ListItem = styled.li `
|
|
130
|
+
padding-inline-start: 2px;
|
|
131
|
+
`;
|
|
132
|
+
export const Paragraph = styled.p `
|
|
133
|
+
margin: 0;
|
|
134
|
+
`;
|
|
135
|
+
export const BlockQuote = styled.blockquote `
|
|
136
|
+
margin: 0;
|
|
137
|
+
padding-left: 8px;
|
|
138
|
+
border-left: 4px solid ${p => p.theme?.colors?.grayDefault};
|
|
139
|
+
`;
|
|
140
|
+
export const FileButtonWrapper = styled.div `
|
|
141
|
+
display: flex;
|
|
142
|
+
white-space: pre-wrap;
|
|
143
|
+
`;
|
|
144
|
+
export const Href = styled.a `
|
|
145
|
+
white-space: pre-wrap;
|
|
146
|
+
`;
|
|
147
|
+
export const FileName = styled.span `
|
|
148
|
+
white-space: pre-wrap;
|
|
149
|
+
`;
|
|
150
|
+
export const ImgHref = styled.a `
|
|
151
|
+
text-decoration: none !important;
|
|
152
|
+
border: none !important;
|
|
153
|
+
`;
|
|
154
|
+
export const TableWrapper = styled.div `
|
|
155
|
+
width: 100%;
|
|
156
|
+
overflow-x: auto;
|
|
157
|
+
`;
|
|
158
|
+
export const Table = styled.table `
|
|
159
|
+
width: 100%;
|
|
160
|
+
min-width: 400px;
|
|
161
|
+
`;
|
|
19
162
|
export function getListStyle(depth) {
|
|
20
163
|
return depth ? { marginTop: 4 } : { marginBottom: 16 };
|
|
21
164
|
}
|
|
22
|
-
export
|
|
23
|
-
|
|
165
|
+
export const VisuallyHidden = styled.span `
|
|
166
|
+
${baseVisuallyHiddenStyle};
|
|
167
|
+
`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as styledComponents from 'styled-components';
|
|
2
|
-
|
|
2
|
+
const { default: styled, css, ThemeProvider, createGlobalStyle, useTheme, } = styledComponents;
|
|
3
3
|
export { css, ThemeProvider, useTheme, createGlobalStyle };
|
|
4
4
|
export default styled;
|
package/src/styles/theme.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
|
-
export
|
|
2
|
+
export const DEFAULT_MARKDOWN_THEME = {
|
|
3
3
|
colors: {
|
|
4
4
|
text: '#222',
|
|
5
5
|
brand: '#e76f57',
|
|
@@ -14,7 +14,7 @@ export var DEFAULT_MARKDOWN_THEME = {
|
|
|
14
14
|
elementsLineHeight: '24px',
|
|
15
15
|
themeMode: 'light',
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export const DEFAULT_MARKDOWN_DARK_THEME = {
|
|
18
18
|
colors: {
|
|
19
19
|
text: '#fff',
|
|
20
20
|
brand: '#e76f57',
|
|
@@ -29,6 +29,6 @@ export var DEFAULT_MARKDOWN_DARK_THEME = {
|
|
|
29
29
|
elementsLineHeight: '24px',
|
|
30
30
|
themeMode: 'dark',
|
|
31
31
|
};
|
|
32
|
-
export
|
|
33
|
-
export
|
|
34
|
-
export
|
|
32
|
+
export const MarkdownThemeContext = createContext(DEFAULT_MARKDOWN_THEME);
|
|
33
|
+
export const MarkdownThemeProvider = MarkdownThemeContext.Provider;
|
|
34
|
+
export const MarkdownThemeConsumer = MarkdownThemeContext.Consumer;
|