@skbkontur/markdown 1.0.3
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/README.md +11 -0
- package/index.d.ts +5 -0
- package/index.js +3 -0
- package/package.json +105 -0
- package/src/Markdown/Files/Files.logic.d.ts +13 -0
- package/src/Markdown/Files/Files.logic.js +123 -0
- package/src/Markdown/Markdown.d.ts +20 -0
- package/src/Markdown/Markdown.js +148 -0
- package/src/Markdown/Markdown.styled.d.ts +69 -0
- package/src/Markdown/Markdown.styled.js +72 -0
- package/src/Markdown/MarkdownActions.d.ts +18 -0
- package/src/Markdown/MarkdownActions.js +64 -0
- package/src/Markdown/MarkdownEditor.d.ts +13 -0
- package/src/Markdown/MarkdownEditor.js +42 -0
- package/src/Markdown/MarkdownFormat.d.ts +18 -0
- package/src/Markdown/MarkdownFormat.js +19 -0
- package/src/Markdown/MarkdownHelpItems.d.ts +25 -0
- package/src/Markdown/MarkdownHelpItems.js +219 -0
- package/src/Markdown/MarkdownHelpers/MarkdownButton.d.ts +10 -0
- package/src/Markdown/MarkdownHelpers/MarkdownButton.js +10 -0
- package/src/Markdown/MarkdownHelpers/MarkdownCombination.d.ts +8 -0
- package/src/Markdown/MarkdownHelpers/MarkdownCombination.js +15 -0
- package/src/Markdown/MarkdownHelpers/MarkdownFormatButton.d.ts +8 -0
- package/src/Markdown/MarkdownHelpers/MarkdownFormatButton.js +11 -0
- package/src/Markdown/MarkdownHelpers/markdownHelpers.d.ts +10 -0
- package/src/Markdown/MarkdownHelpers/markdownHelpers.js +103 -0
- package/src/Markdown/MarkdownHelpers/markdownMentionHelpers.d.ts +7 -0
- package/src/Markdown/MarkdownHelpers/markdownMentionHelpers.js +44 -0
- package/src/Markdown/MarkdownHelpers/markdownTextareaHelpers.d.ts +11 -0
- package/src/Markdown/MarkdownHelpers/markdownTextareaHelpers.js +86 -0
- package/src/Markdown/MarkdownMention.d.ts +11 -0
- package/src/Markdown/MarkdownMention.js +88 -0
- package/src/Markdown/constants.d.ts +3 -0
- package/src/Markdown/constants.js +3 -0
- package/src/Markdown/types/turndownPluginGfm.d.ts +1 -0
- package/src/Markdown/types.d.ts +39 -0
- package/src/Markdown/types.js +5 -0
- package/src/Markdown/utils/guid.d.ts +6 -0
- package/src/Markdown/utils/guid.js +23 -0
- package/src/Markdown/utils/htmlToMd.d.ts +2 -0
- package/src/Markdown/utils/htmlToMd.js +5 -0
- package/src/Markdown/utils/isMacintosh.d.ts +1 -0
- package/src/Markdown/utils/isMacintosh.js +3 -0
- package/src/Markdown/utils/requestStatus.d.ts +6 -0
- package/src/Markdown/utils/requestStatus.js +7 -0
- package/src/Markdown/utils/saveFile.d.ts +1 -0
- package/src/Markdown/utils/saveFile.js +9 -0
- package/src/MarkdownIcons/AttachLink.d.ts +1 -0
- package/src/MarkdownIcons/AttachLink.js +5 -0
- package/src/MarkdownIcons/AttachPaperclip.d.ts +1 -0
- package/src/MarkdownIcons/AttachPaperclip.js +3 -0
- package/src/MarkdownIcons/CheckedList.d.ts +1 -0
- package/src/MarkdownIcons/CheckedList.js +8 -0
- package/src/MarkdownIcons/Collapse.d.ts +1 -0
- package/src/MarkdownIcons/Collapse.js +4 -0
- package/src/MarkdownIcons/Expand.d.ts +1 -0
- package/src/MarkdownIcons/Expand.js +4 -0
- package/src/MarkdownIcons/EyeOpen.d.ts +1 -0
- package/src/MarkdownIcons/EyeOpen.js +4 -0
- package/src/MarkdownIcons/List.d.ts +1 -0
- package/src/MarkdownIcons/List.js +8 -0
- package/src/MarkdownIcons/MarkdownIcons.styled.d.ts +2 -0
- package/src/MarkdownIcons/MarkdownIcons.styled.js +8 -0
- package/src/MarkdownIcons/NumberedList.d.ts +1 -0
- package/src/MarkdownIcons/NumberedList.js +6 -0
- package/src/MarkdownIcons/Table.d.ts +1 -0
- package/src/MarkdownIcons/Table.js +3 -0
- package/src/MarkdownIcons/ToolPencil.d.ts +1 -0
- package/src/MarkdownIcons/ToolPencil.js +3 -0
- package/src/MarkdownViewer/Helpers/MarkdownImage.d.ts +6 -0
- package/src/MarkdownViewer/Helpers/MarkdownImage.js +6 -0
- package/src/MarkdownViewer/Helpers/MarkdownLink.d.ts +2 -0
- package/src/MarkdownViewer/Helpers/MarkdownLink.js +5 -0
- package/src/MarkdownViewer/MarkdownViewer.d.ts +12 -0
- package/src/MarkdownViewer/MarkdownViewer.js +64 -0
- package/src/MarkdownViewer/MarkdownViewer.styles.d.ts +8 -0
- package/src/MarkdownViewer/MarkdownViewer.styles.js +15 -0
- package/src/MarkdownViewer/index.d.ts +1 -0
- package/src/MarkdownViewer/index.js +1 -0
- package/src/MarkdownViewer/types.d.ts +7 -0
- package/src/MarkdownViewer/types.js +1 -0
- package/src/styles/styled-components.d.ts +5 -0
- package/src/styles/styled-components.js +4 -0
- package/src/styles/theme.d.ts +11 -0
- package/src/styles/theme.js +13 -0
- package/src/styles/types.d.ts +9 -0
- package/src/styles/types.js +1 -0
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
import { Dropdown } from '@skbkontur/react-ui';
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { ActionsWrapper, ButtonsWrapper, MarkdownDropdown, MarkdownMenuItem, MarkdownActionsWrapper, } from './Markdown.styled';
|
|
15
|
+
import { MarkdownCombination } from './MarkdownHelpers/MarkdownCombination';
|
|
16
|
+
import { MarkdownFormatButton } from './MarkdownHelpers/MarkdownFormatButton';
|
|
17
|
+
import { setMarkdown } from './MarkdownHelpers/markdownHelpers';
|
|
18
|
+
import { markdownHelpHeaders, markdownHelpLists, markdownHelpOther, markdownHelpText } from './MarkdownHelpItems';
|
|
19
|
+
import { ViewMode } from './types';
|
|
20
|
+
import { AttachPaperclip } from '../MarkdownIcons/AttachPaperclip';
|
|
21
|
+
import { Collapse } from '../MarkdownIcons/Collapse';
|
|
22
|
+
import { Expand } from '../MarkdownIcons/Expand';
|
|
23
|
+
import { EyeOpen } from '../MarkdownIcons/EyeOpen';
|
|
24
|
+
import { ToolPencil } from '../MarkdownIcons/ToolPencil';
|
|
25
|
+
export var MarkdownActions = function (_a) {
|
|
26
|
+
var textAreaRef = _a.textAreaRef, selectionStart = _a.selectionStart, selectionEnd = _a.selectionEnd, loadingFile = _a.loadingFile, onOpenFileDialog = _a.onOpenFileDialog, onClickFullscreen = _a.onClickFullscreen, fullscreen = _a.fullscreen, viewMode = _a.viewMode, onChangeViewMode = _a.onChangeViewMode, horizontalPaddings = _a.horizontalPaddings, hasFilesApi = _a.hasFilesApi;
|
|
27
|
+
var isPreviewMode = viewMode === ViewMode.Preview;
|
|
28
|
+
return (React.createElement(MarkdownActionsWrapper, __assign({}, horizontalPaddings),
|
|
29
|
+
React.createElement(ButtonsWrapper, null,
|
|
30
|
+
React.createElement(ActionsWrapper, null,
|
|
31
|
+
React.createElement(MarkdownDropdown, null,
|
|
32
|
+
React.createElement(Dropdown, { disablePortal: true, disabled: isPreviewMode, menuWidth: 260, caption: "\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A" }, markdownHelpHeaders.map(function (helper, idx) { return (React.createElement(MarkdownMenuItem, { key: idx, onClick: function (event) { return handleMarkdownItemClick(event, helper.format); } },
|
|
33
|
+
React.createElement(MarkdownCombination, { format: helper.format, text: helper.node }))); }))),
|
|
34
|
+
markdownHelpText.map(function (helper, idx) { return (React.createElement(MarkdownFormatButton, { key: idx, disabled: isPreviewMode, format: helper.format, hintText: helper.node, icon: helper.icon, text: helper.text, onClick: function (event) { return handleMarkdownItemClick(event, helper.format); } })); }),
|
|
35
|
+
markdownHelpLists.map(function (helper, idx) { return (React.createElement(MarkdownFormatButton, { key: idx, disabled: isPreviewMode, format: helper.format, hintText: helper.node, icon: helper.icon, text: helper.text, onClick: function (event) { return handleMarkdownItemClick(event, helper.format); } })); }),
|
|
36
|
+
markdownHelpOther.map(function (helper, idx) { return (React.createElement(MarkdownFormatButton, { key: idx, disabled: isPreviewMode, format: helper.format, hintText: helper.node, icon: helper.icon, text: helper.text, onClick: function (event) { return handleMarkdownItemClick(event, helper.format); } })); }),
|
|
37
|
+
hasFilesApi && (React.createElement(MarkdownFormatButton, { hintText: "\u041F\u0440\u0438\u043A\u0440\u0435\u043F\u0438\u0442\u044C \u0444\u0430\u0439\u043B", disabled: isPreviewMode, isLoading: loadingFile, icon: React.createElement(AttachPaperclip, null), text: "\u041F\u0440\u0438\u043A\u0440\u0435\u043F\u0438\u0442\u044C \u0444\u0430\u0439\u043B", onClick: onOpenFileDialog }))),
|
|
38
|
+
React.createElement(ActionsWrapper, null,
|
|
39
|
+
renderViewModeButton(),
|
|
40
|
+
React.createElement(MarkdownFormatButton, { hintText: fullscreen ? 'Свернуть' : 'Развернуть', icon: fullscreen ? React.createElement(Collapse, null) : React.createElement(Expand, null), text: fullscreen ? 'Свернуть' : 'Развернуть', onClick: onClickFullscreen })))));
|
|
41
|
+
function renderViewModeButton() {
|
|
42
|
+
var buttonProps = {
|
|
43
|
+
hintText: isPreviewMode ? 'Вернуться в редактор' : 'Превью',
|
|
44
|
+
icon: isPreviewMode ? React.createElement(ToolPencil, null) : React.createElement(EyeOpen, null),
|
|
45
|
+
onClick: function () { return onChangeViewMode(isPreviewMode ? ViewMode.Edit : ViewMode.Preview); },
|
|
46
|
+
text: isPreviewMode ? 'Вернуться в редактор' : 'Превью',
|
|
47
|
+
};
|
|
48
|
+
return React.createElement(MarkdownFormatButton, __assign({}, buttonProps));
|
|
49
|
+
}
|
|
50
|
+
function handleMarkdownItemClick(event, format) {
|
|
51
|
+
var _a;
|
|
52
|
+
if (!isNaN(Number(selectionStart)) && !isNaN(Number(selectionEnd))) {
|
|
53
|
+
event.stopPropagation();
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
if (textAreaRef === null || textAreaRef === void 0 ? void 0 : textAreaRef.current) {
|
|
56
|
+
textAreaRef.current.focus();
|
|
57
|
+
var htmlTextArea = textAreaRef.current.node;
|
|
58
|
+
htmlTextArea.selectionStart = Number(selectionStart);
|
|
59
|
+
htmlTextArea.selectionEnd = Number(selectionEnd);
|
|
60
|
+
setMarkdown(htmlTextArea, (_a = htmlTextArea.value) !== null && _a !== void 0 ? _a : '', format, Number(selectionStart), selectionEnd);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Textarea, TextareaProps } from '@skbkontur/react-ui';
|
|
2
|
+
import { ValidationInfo } from '@skbkontur/react-ui-validations';
|
|
3
|
+
import { FC, RefObject } from 'react';
|
|
4
|
+
export interface MarkdownEditorProps extends Omit<TextareaProps, 'rows' | 'maxRows' | 'disableAnimations' | 'extraRow'> {
|
|
5
|
+
disableAnimations?: boolean;
|
|
6
|
+
extraRow?: boolean;
|
|
7
|
+
maxRows?: number;
|
|
8
|
+
rows?: number;
|
|
9
|
+
textareaRef?: RefObject<Textarea>;
|
|
10
|
+
/** Стандартная валидация из react-ui-validations */
|
|
11
|
+
validationInfo?: ValidationInfo | null;
|
|
12
|
+
}
|
|
13
|
+
export declare const MarkdownEditor: FC<MarkdownEditorProps>;
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { Textarea } from '@skbkontur/react-ui';
|
|
24
|
+
import { ValidationWrapper } from '@skbkontur/react-ui-validations';
|
|
25
|
+
import React from 'react';
|
|
26
|
+
import { useDropzone } from 'react-dropzone';
|
|
27
|
+
import { createMarkdownHelpKeyDownHandler } from './MarkdownHelpers/markdownHelpers';
|
|
28
|
+
export var MarkdownEditor = function (props) {
|
|
29
|
+
var _a = props.resize, resize = _a === void 0 ? 'none' : _a, _b = props.width, width = _b === void 0 ? '100%' : _b, _c = props.autoResize, autoResize = _c === void 0 ? true : _c, _d = props.showLengthCounter, propsShowLengthCounter = _d === void 0 ? true : _d, textareaRef = props.textareaRef, validationInfo = props.validationInfo, rest = __rest(props, ["resize", "width", "autoResize", "showLengthCounter", "textareaRef", "validationInfo"]);
|
|
30
|
+
var getInputProps = useDropzone().getInputProps;
|
|
31
|
+
return validationInfo !== undefined ? (React.createElement(ValidationWrapper, { validationInfo: validationInfo }, renderTextarea())) : (renderTextarea());
|
|
32
|
+
function renderTextarea() {
|
|
33
|
+
return (React.createElement(Textarea, __assign({ ref: textareaRef, id: "MarkdownTextArea" }, rest, getInputProps, { resize: resize, width: width, showLengthCounter: showLengthCounter(), autoResize: autoResize, onKeyDown: createMarkdownHelpKeyDownHandler(props.value || '', textareaRef, props.onKeyDown) })));
|
|
34
|
+
}
|
|
35
|
+
function showLengthCounter() {
|
|
36
|
+
if (propsShowLengthCounter) {
|
|
37
|
+
var value = rest.value, maxLength = rest.maxLength;
|
|
38
|
+
return Number(maxLength) - Number(value === null || value === void 0 ? void 0 : value.length) <= 500;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare enum MarkdownFormat {
|
|
2
|
+
h2 = "h2",
|
|
3
|
+
h3 = "h3",
|
|
4
|
+
h4 = "h4",
|
|
5
|
+
bold = "bold",
|
|
6
|
+
italic = "italic",
|
|
7
|
+
crossed = "crossed",
|
|
8
|
+
ref = "ref",
|
|
9
|
+
quote = "quote",
|
|
10
|
+
codeBlock = "codeBlock",
|
|
11
|
+
code = "code",
|
|
12
|
+
list = "list",
|
|
13
|
+
checkedList = "checkedList",
|
|
14
|
+
numberedList = "numberedList",
|
|
15
|
+
table = "table",
|
|
16
|
+
file = "file",
|
|
17
|
+
image = "image"
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export var MarkdownFormat;
|
|
2
|
+
(function (MarkdownFormat) {
|
|
3
|
+
MarkdownFormat["h2"] = "h2";
|
|
4
|
+
MarkdownFormat["h3"] = "h3";
|
|
5
|
+
MarkdownFormat["h4"] = "h4";
|
|
6
|
+
MarkdownFormat["bold"] = "bold";
|
|
7
|
+
MarkdownFormat["italic"] = "italic";
|
|
8
|
+
MarkdownFormat["crossed"] = "crossed";
|
|
9
|
+
MarkdownFormat["ref"] = "ref";
|
|
10
|
+
MarkdownFormat["quote"] = "quote";
|
|
11
|
+
MarkdownFormat["codeBlock"] = "codeBlock";
|
|
12
|
+
MarkdownFormat["code"] = "code";
|
|
13
|
+
MarkdownFormat["list"] = "list";
|
|
14
|
+
MarkdownFormat["checkedList"] = "checkedList";
|
|
15
|
+
MarkdownFormat["numberedList"] = "numberedList";
|
|
16
|
+
MarkdownFormat["table"] = "table";
|
|
17
|
+
MarkdownFormat["file"] = "file";
|
|
18
|
+
MarkdownFormat["image"] = "image";
|
|
19
|
+
})(MarkdownFormat || (MarkdownFormat = {}));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { MarkdownFormat } from './MarkdownFormat';
|
|
3
|
+
import { RefItem } from './types';
|
|
4
|
+
export declare const eventKeyCodeToMarkdownFormat: {
|
|
5
|
+
[key: number]: MarkdownFormat;
|
|
6
|
+
};
|
|
7
|
+
export declare const markdownFormatToShortKey: Partial<{
|
|
8
|
+
[key in MarkdownFormat]: string;
|
|
9
|
+
}>;
|
|
10
|
+
export interface MarkdownHelpItem {
|
|
11
|
+
format: MarkdownFormat;
|
|
12
|
+
node: ReactNode;
|
|
13
|
+
text: string;
|
|
14
|
+
wrapContent: (content: string) => string;
|
|
15
|
+
icon?: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export declare const markdownHelpHeaders: MarkdownHelpItem[];
|
|
18
|
+
export declare const markdownHelpText: MarkdownHelpItem[];
|
|
19
|
+
export declare const markdownHelpLists: MarkdownHelpItem[];
|
|
20
|
+
export declare const markdownHelpOther: MarkdownHelpItem[];
|
|
21
|
+
export interface MarkdownHelpFileItem extends Omit<MarkdownHelpItem, 'wrapContent'> {
|
|
22
|
+
wrapContent: (file: RefItem) => string;
|
|
23
|
+
}
|
|
24
|
+
export declare const markdownHelpFiles: (fileApiUrl?: string) => MarkdownHelpFileItem[];
|
|
25
|
+
export declare const markdownHelpItems: MarkdownHelpItem[];
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
10
|
+
var _a;
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { MarkdownSymbolWrapper } from './Markdown.styled';
|
|
13
|
+
import { MarkdownFormat } from './MarkdownFormat';
|
|
14
|
+
import { AttachLink } from '../MarkdownIcons/AttachLink';
|
|
15
|
+
import { AttachPaperclip } from '../MarkdownIcons/AttachPaperclip';
|
|
16
|
+
import { CheckedList } from '../MarkdownIcons/CheckedList';
|
|
17
|
+
import { List } from '../MarkdownIcons/List';
|
|
18
|
+
import { NumberedList } from '../MarkdownIcons/NumberedList';
|
|
19
|
+
import { Table } from '../MarkdownIcons/Table';
|
|
20
|
+
var newLinesRegexp = /([\n\r]+)/g;
|
|
21
|
+
export var eventKeyCodeToMarkdownFormat = {
|
|
22
|
+
50: MarkdownFormat.h2,
|
|
23
|
+
51: MarkdownFormat.h3,
|
|
24
|
+
52: MarkdownFormat.h4,
|
|
25
|
+
66: MarkdownFormat.bold,
|
|
26
|
+
73: MarkdownFormat.italic,
|
|
27
|
+
82: MarkdownFormat.crossed,
|
|
28
|
+
85: MarkdownFormat.ref,
|
|
29
|
+
76: MarkdownFormat.list,
|
|
30
|
+
68: MarkdownFormat.checkedList,
|
|
31
|
+
78: MarkdownFormat.numberedList,
|
|
32
|
+
69: MarkdownFormat.codeBlock,
|
|
33
|
+
81: MarkdownFormat.quote,
|
|
34
|
+
80: MarkdownFormat.image,
|
|
35
|
+
};
|
|
36
|
+
export var markdownFormatToShortKey = (_a = {},
|
|
37
|
+
_a[MarkdownFormat.h2] = '2',
|
|
38
|
+
_a[MarkdownFormat.h3] = '3',
|
|
39
|
+
_a[MarkdownFormat.h4] = '4',
|
|
40
|
+
_a[MarkdownFormat.bold] = 'B',
|
|
41
|
+
_a[MarkdownFormat.italic] = 'I',
|
|
42
|
+
_a[MarkdownFormat.crossed] = 'R',
|
|
43
|
+
_a[MarkdownFormat.ref] = 'U',
|
|
44
|
+
_a[MarkdownFormat.list] = 'L',
|
|
45
|
+
_a[MarkdownFormat.checkedList] = 'D',
|
|
46
|
+
_a[MarkdownFormat.numberedList] = 'N',
|
|
47
|
+
_a[MarkdownFormat.codeBlock] = 'E',
|
|
48
|
+
_a[MarkdownFormat.quote] = 'Q',
|
|
49
|
+
_a[MarkdownFormat.image] = 'P',
|
|
50
|
+
_a);
|
|
51
|
+
export var markdownHelpHeaders = [
|
|
52
|
+
{
|
|
53
|
+
format: MarkdownFormat.h2,
|
|
54
|
+
node: (React.createElement(React.Fragment, null,
|
|
55
|
+
React.createElement(MarkdownSymbolWrapper, null, "##"),
|
|
56
|
+
" \u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A 2")),
|
|
57
|
+
wrapContent: function (content) { return "## ".concat(content); },
|
|
58
|
+
text: 'Заголовок 2',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
format: MarkdownFormat.h3,
|
|
62
|
+
node: (React.createElement(React.Fragment, null,
|
|
63
|
+
React.createElement(MarkdownSymbolWrapper, null, "###"),
|
|
64
|
+
" \u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A 3")),
|
|
65
|
+
wrapContent: function (content) { return "### ".concat(content); },
|
|
66
|
+
text: 'Заголовок 3',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
format: MarkdownFormat.h4,
|
|
70
|
+
node: (React.createElement(React.Fragment, null,
|
|
71
|
+
React.createElement(MarkdownSymbolWrapper, null, "####"),
|
|
72
|
+
" \u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A 4")),
|
|
73
|
+
wrapContent: function (content) { return "#### ".concat(content); },
|
|
74
|
+
text: 'Заголовок 4',
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
export var markdownHelpText = [
|
|
78
|
+
{
|
|
79
|
+
format: MarkdownFormat.bold,
|
|
80
|
+
node: (React.createElement(React.Fragment, null,
|
|
81
|
+
React.createElement(MarkdownSymbolWrapper, null, "**"),
|
|
82
|
+
"\u0416\u0438\u0440\u043D\u044B\u0439",
|
|
83
|
+
React.createElement(MarkdownSymbolWrapper, null, "**"))),
|
|
84
|
+
icon: React.createElement("strong", null, "B"),
|
|
85
|
+
wrapContent: function (content) { return "**".concat(content, "**"); },
|
|
86
|
+
text: 'Жирный',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
format: MarkdownFormat.italic,
|
|
90
|
+
node: (React.createElement(React.Fragment, null,
|
|
91
|
+
React.createElement(MarkdownSymbolWrapper, null, "*"),
|
|
92
|
+
"\u041A\u0443\u0440\u0441\u0438\u0432",
|
|
93
|
+
React.createElement(MarkdownSymbolWrapper, null, "*"))),
|
|
94
|
+
icon: React.createElement("i", null, "I"),
|
|
95
|
+
wrapContent: function (content) { return "*".concat(content, "*"); },
|
|
96
|
+
text: 'Курсив',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
format: MarkdownFormat.crossed,
|
|
100
|
+
node: (React.createElement(React.Fragment, null,
|
|
101
|
+
React.createElement(MarkdownSymbolWrapper, null, "~~"),
|
|
102
|
+
"\u0417\u0430\u0447\u0435\u0440\u043A\u043D\u0443\u0442\u044B\u0439",
|
|
103
|
+
React.createElement(MarkdownSymbolWrapper, null, "~~"))),
|
|
104
|
+
icon: (React.createElement("span", { style: {
|
|
105
|
+
textDecoration: 'line-through',
|
|
106
|
+
} }, "S")),
|
|
107
|
+
wrapContent: function (content) { return "~~".concat(content, "~~"); },
|
|
108
|
+
text: 'Зачеркнутый',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
format: MarkdownFormat.ref,
|
|
112
|
+
node: (React.createElement(React.Fragment, null,
|
|
113
|
+
React.createElement(MarkdownSymbolWrapper, null, "["),
|
|
114
|
+
"\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u0441\u0441\u044B\u043B\u043A\u0438",
|
|
115
|
+
React.createElement(MarkdownSymbolWrapper, null, "]"),
|
|
116
|
+
React.createElement(MarkdownSymbolWrapper, null, "("),
|
|
117
|
+
"\u0421\u0441\u044B\u043B\u043A\u0430",
|
|
118
|
+
React.createElement(MarkdownSymbolWrapper, null, ")"))),
|
|
119
|
+
icon: React.createElement(AttachLink, null),
|
|
120
|
+
wrapContent: function (content) { return "[".concat(content, "]()"); },
|
|
121
|
+
text: 'Ссылка',
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
export var markdownHelpLists = [
|
|
125
|
+
{
|
|
126
|
+
format: MarkdownFormat.list,
|
|
127
|
+
node: (React.createElement(React.Fragment, null,
|
|
128
|
+
React.createElement(MarkdownSymbolWrapper, null, "*"),
|
|
129
|
+
" \u0421\u043F\u0438\u0441\u043E\u043A")),
|
|
130
|
+
icon: React.createElement(List, null),
|
|
131
|
+
wrapContent: function (content) { return getList(content, '*'); },
|
|
132
|
+
text: 'Список',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
format: MarkdownFormat.checkedList,
|
|
136
|
+
node: (React.createElement(React.Fragment, null,
|
|
137
|
+
React.createElement(MarkdownSymbolWrapper, null, "* [x]"),
|
|
138
|
+
" \u0421\u043F\u0438\u0441\u043E\u043A - \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u043E")),
|
|
139
|
+
icon: React.createElement(CheckedList, null),
|
|
140
|
+
wrapContent: function (content) { return getList(content, '* [x]'); },
|
|
141
|
+
text: 'Список - выполнено',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
format: MarkdownFormat.numberedList,
|
|
145
|
+
node: (React.createElement(React.Fragment, null,
|
|
146
|
+
React.createElement(MarkdownSymbolWrapper, null, "1. "),
|
|
147
|
+
" \u0421\u043F\u0438\u0441\u043E\u043A - \u043D\u0443\u043C\u0435\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439")),
|
|
148
|
+
icon: React.createElement(NumberedList, null),
|
|
149
|
+
wrapContent: function (content) { return getList(content, 1); },
|
|
150
|
+
text: 'Список - нумерованный',
|
|
151
|
+
},
|
|
152
|
+
];
|
|
153
|
+
export var markdownHelpOther = [
|
|
154
|
+
{
|
|
155
|
+
format: MarkdownFormat.codeBlock,
|
|
156
|
+
node: (React.createElement(React.Fragment, null,
|
|
157
|
+
React.createElement(MarkdownSymbolWrapper, null, "`"),
|
|
158
|
+
"\u0411\u043B\u043E\u043A \u043A\u043E\u0434\u0430",
|
|
159
|
+
React.createElement(MarkdownSymbolWrapper, null, "`"))),
|
|
160
|
+
icon: React.createElement("span", null, '</>'),
|
|
161
|
+
wrapContent: function (content) { return "`".concat(content, "`"); },
|
|
162
|
+
text: 'Блок кода',
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
format: MarkdownFormat.quote,
|
|
166
|
+
node: (React.createElement(React.Fragment, null,
|
|
167
|
+
React.createElement(MarkdownSymbolWrapper, null,
|
|
168
|
+
'>',
|
|
169
|
+
" "),
|
|
170
|
+
" \u0426\u0438\u0442\u0430\u0442\u0430")),
|
|
171
|
+
icon: '>',
|
|
172
|
+
wrapContent: function (content) { return "> ".concat(content); },
|
|
173
|
+
text: 'Цитата',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
format: MarkdownFormat.table,
|
|
177
|
+
node: 'Таблица',
|
|
178
|
+
icon: React.createElement(Table, null),
|
|
179
|
+
wrapContent: function () { return "| \u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A | \u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A |\n| ------ | ------ |\n| \u042F\u0447\u0435\u0439\u043A\u0430 | \u042F\u0447\u0435\u0439\u043A\u0430 |\n| \u042F\u0447\u0435\u0439\u043A\u0430 | \u042F\u0447\u0435\u0439\u043A\u0430 |"; },
|
|
180
|
+
text: 'Таблица',
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
export var markdownHelpFiles = function (fileApiUrl) {
|
|
184
|
+
if (!fileApiUrl)
|
|
185
|
+
return [];
|
|
186
|
+
return [
|
|
187
|
+
{
|
|
188
|
+
format: MarkdownFormat.image,
|
|
189
|
+
node: '',
|
|
190
|
+
icon: React.createElement("span", null),
|
|
191
|
+
wrapContent: function (file) { return ".concat(file.id, ")"); },
|
|
192
|
+
text: 'Картинка',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
format: MarkdownFormat.file,
|
|
196
|
+
node: '',
|
|
197
|
+
icon: React.createElement(AttachPaperclip, null),
|
|
198
|
+
wrapContent: function (file) { return "[".concat(file.caption, "](").concat(fileApiUrl).concat(file.id, ")"); },
|
|
199
|
+
text: 'Файл',
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
};
|
|
203
|
+
export var markdownHelpItems = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], markdownHelpHeaders, true), markdownHelpText, true), markdownHelpLists, true), markdownHelpOther, true);
|
|
204
|
+
function getList(value, symbol) {
|
|
205
|
+
var splitValueWithNewLines = value.split(newLinesRegexp);
|
|
206
|
+
var numberList = [];
|
|
207
|
+
return splitValueWithNewLines
|
|
208
|
+
.map(function (v, idx) {
|
|
209
|
+
if (!newLinesRegexp.test(v)) {
|
|
210
|
+
if (typeof symbol === 'number') {
|
|
211
|
+
numberList.push(idx);
|
|
212
|
+
return "".concat(numberList.length, ". ").concat(v);
|
|
213
|
+
}
|
|
214
|
+
return "".concat(symbol, " ").concat(v);
|
|
215
|
+
}
|
|
216
|
+
return v;
|
|
217
|
+
})
|
|
218
|
+
.join('');
|
|
219
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FC, ReactNode, SyntheticEvent } from 'react';
|
|
2
|
+
export interface MarkdownButtonProps {
|
|
3
|
+
hintText: ReactNode;
|
|
4
|
+
icon: ReactNode;
|
|
5
|
+
onClick: (event: SyntheticEvent) => void;
|
|
6
|
+
text: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
isLoading?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const MarkdownButton: FC<MarkdownButtonProps>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Hint } from '@skbkontur/react-ui';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { MarkdownButtonWrapper, VisuallyHidden } from '../Markdown.styled';
|
|
4
|
+
export var MarkdownButton = function (_a) {
|
|
5
|
+
var icon = _a.icon, hintText = _a.hintText, onClick = _a.onClick, isLoading = _a.isLoading, disabled = _a.disabled, text = _a.text;
|
|
6
|
+
return (React.createElement(Hint, { pos: "top center", manual: disabled, text: hintText, maxWidth: 300 },
|
|
7
|
+
React.createElement(MarkdownButtonWrapper, { borderless: true, loading: isLoading, disabled: disabled, onClick: onClick },
|
|
8
|
+
icon,
|
|
9
|
+
React.createElement(VisuallyHidden, null, text))));
|
|
10
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { HintContentWrapper } from '../Markdown.styled';
|
|
3
|
+
import { markdownFormatToShortKey } from '../MarkdownHelpItems';
|
|
4
|
+
import { isMacintosh } from '../utils/isMacintosh';
|
|
5
|
+
export var MarkdownCombination = function (_a) {
|
|
6
|
+
var format = _a.format, text = _a.text;
|
|
7
|
+
var shortKey = markdownFormatToShortKey[format];
|
|
8
|
+
return (React.createElement(HintContentWrapper, null,
|
|
9
|
+
React.createElement("span", null, text),
|
|
10
|
+
!!shortKey && (React.createElement("span", null,
|
|
11
|
+
"CTRL+",
|
|
12
|
+
isMacintosh() ? '⌥' : 'ALT',
|
|
13
|
+
"+",
|
|
14
|
+
markdownFormatToShortKey[format]))));
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { MarkdownButtonProps } from './MarkdownButton';
|
|
3
|
+
import { MarkdownFormat } from '../MarkdownFormat';
|
|
4
|
+
interface Props extends MarkdownButtonProps {
|
|
5
|
+
format?: MarkdownFormat;
|
|
6
|
+
}
|
|
7
|
+
export declare const MarkdownFormatButton: FC<Props>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Hint } from '@skbkontur/react-ui';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { MarkdownCombination } from './MarkdownCombination';
|
|
4
|
+
import { MarkdownButtonIcon, MarkdownButtonWrapper, VisuallyHidden } from '../Markdown.styled';
|
|
5
|
+
export var MarkdownFormatButton = function (_a) {
|
|
6
|
+
var icon = _a.icon, hintText = _a.hintText, onClick = _a.onClick, format = _a.format, disabled = _a.disabled, text = _a.text;
|
|
7
|
+
return (React.createElement(Hint, { manual: disabled, text: format ? React.createElement(MarkdownCombination, { format: format, text: hintText }) : hintText, pos: "top center", maxWidth: 300 },
|
|
8
|
+
React.createElement(MarkdownButtonWrapper, { borderless: true, disabled: disabled, onClick: onClick },
|
|
9
|
+
React.createElement(MarkdownButtonIcon, null, icon),
|
|
10
|
+
React.createElement(VisuallyHidden, null, text))));
|
|
11
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Textarea } from '@skbkontur/react-ui';
|
|
2
|
+
import { KeyboardEvent as ReactKeyboardEvent, RefObject } from 'react';
|
|
3
|
+
import { MarkdownFormat } from '../MarkdownFormat';
|
|
4
|
+
import { Nullable, RefItem } from '../types';
|
|
5
|
+
export declare function setMarkdown(textareaNode: HTMLTextAreaElement, text: string, format: MarkdownFormat, selectionStart: number, selectionEnd?: number | null): void;
|
|
6
|
+
export declare function setMarkdownFiles(file: RefItem, textarea: Textarea, format: MarkdownFormat, cursorPosition?: number | null, fileApiUrl?: string): void;
|
|
7
|
+
export declare function setMarkdownPastedHtml(text: string, textareaNode: HTMLTextAreaElement): void;
|
|
8
|
+
export declare function setTextareaCursor(format: MarkdownFormat, prevCommentPartLength: number, nextCommentPartLength: number, textareaNode: HTMLTextAreaElement, selectionEnd: number): void;
|
|
9
|
+
export declare function createMarkdownHelpKeyDownHandler(text: string, ref?: RefObject<Textarea> | null, callback?: (event: ReactKeyboardEvent<HTMLTextAreaElement>) => void): (event: ReactKeyboardEvent<HTMLTextAreaElement>) => void;
|
|
10
|
+
export declare const usePasteFromClipboard: (textarea: Nullable<Textarea>, uploadFileApi?: ((file: File) => Promise<RefItem>) | undefined, downloadFileApi?: ((id: string) => Promise<File>) | undefined, fileApiUrl?: string) => void;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { getPastedHtml } from './markdownTextareaHelpers';
|
|
3
|
+
import { useFileLogic } from '../Files/Files.logic';
|
|
4
|
+
import { MarkdownFormat } from '../MarkdownFormat';
|
|
5
|
+
import { eventKeyCodeToMarkdownFormat, markdownHelpFiles, markdownHelpItems } from '../MarkdownHelpItems';
|
|
6
|
+
var italic = MarkdownFormat.italic, bold = MarkdownFormat.bold, crossed = MarkdownFormat.crossed, codeBlock = MarkdownFormat.codeBlock, ref = MarkdownFormat.ref, file = MarkdownFormat.file, image = MarkdownFormat.image;
|
|
7
|
+
var betweenTextFormats = [italic, bold, crossed, codeBlock, file, image];
|
|
8
|
+
var specialFormats = [ref];
|
|
9
|
+
export function setMarkdown(textareaNode, text, format, selectionStart, selectionEnd) {
|
|
10
|
+
var markdownHelpItem = markdownHelpItems.find(function (item) { return item.format === format; });
|
|
11
|
+
if (markdownHelpItem) {
|
|
12
|
+
var prevCommentPart = text.substring(selectionStart, selectionEnd !== null && selectionEnd !== void 0 ? selectionEnd : undefined);
|
|
13
|
+
var nextCommentPart = markdownHelpItem.wrapContent(prevCommentPart);
|
|
14
|
+
document.execCommand('insertText', false, nextCommentPart);
|
|
15
|
+
setTextareaCursor(format, prevCommentPart.length, nextCommentPart.length, textareaNode, Number(selectionEnd));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function setMarkdownFiles(file, textarea, format, cursorPosition, fileApiUrl) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
var markdownHelpItem = markdownHelpFiles(fileApiUrl).find(function (item) { return item.format === format; });
|
|
21
|
+
if (markdownHelpItem) {
|
|
22
|
+
var textareaNode = textarea.node;
|
|
23
|
+
var currentCursorPosition = (_a = cursorPosition !== null && cursorPosition !== void 0 ? cursorPosition : textareaNode.selectionStart) !== null && _a !== void 0 ? _a : (_b = textareaNode === null || textareaNode === void 0 ? void 0 : textareaNode.value) === null || _b === void 0 ? void 0 : _b.length;
|
|
24
|
+
var nextCommentPart = markdownHelpItem.wrapContent(file);
|
|
25
|
+
var newCursorPosition = currentCursorPosition + nextCommentPart.length;
|
|
26
|
+
textareaNode.selectionStart = currentCursorPosition;
|
|
27
|
+
textareaNode.focus();
|
|
28
|
+
document.execCommand('insertText', false, nextCommentPart);
|
|
29
|
+
textareaNode.selectionStart = newCursorPosition;
|
|
30
|
+
textareaNode.selectionEnd = newCursorPosition;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function setMarkdownPastedHtml(text, textareaNode) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
var selectionStart = textareaNode.selectionStart;
|
|
36
|
+
var currentCursorPosition = (_b = selectionStart !== null && selectionStart !== void 0 ? selectionStart : (_a = textareaNode === null || textareaNode === void 0 ? void 0 : textareaNode.value) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
37
|
+
var newCursorPosition = currentCursorPosition + text.length;
|
|
38
|
+
textareaNode.selectionStart = currentCursorPosition;
|
|
39
|
+
textareaNode.focus();
|
|
40
|
+
document.execCommand('insertText', false, text);
|
|
41
|
+
textareaNode.selectionStart = newCursorPosition;
|
|
42
|
+
textareaNode.selectionEnd = newCursorPosition;
|
|
43
|
+
}
|
|
44
|
+
export function setTextareaCursor(format, prevCommentPartLength, nextCommentPartLength, textareaNode, selectionEnd) {
|
|
45
|
+
if (betweenTextFormats.includes(format)) {
|
|
46
|
+
var formatCenterPosition = (nextCommentPartLength - prevCommentPartLength) / 2;
|
|
47
|
+
textareaNode.selectionStart = selectionEnd + formatCenterPosition;
|
|
48
|
+
textareaNode.selectionEnd = selectionEnd + formatCenterPosition;
|
|
49
|
+
}
|
|
50
|
+
if (specialFormats.includes(format)) {
|
|
51
|
+
var nextCommentCursorPosition = nextCommentPartLength - 1;
|
|
52
|
+
textareaNode.selectionStart = selectionEnd - prevCommentPartLength + nextCommentCursorPosition;
|
|
53
|
+
textareaNode.selectionEnd = selectionEnd - prevCommentPartLength + nextCommentCursorPosition;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function createMarkdownHelpKeyDownHandler(text, ref, callback) {
|
|
57
|
+
return function (event) {
|
|
58
|
+
if (!(ref === null || ref === void 0 ? void 0 : ref.current)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
var textareaNode = ref.current.node;
|
|
62
|
+
var format = eventKeyCodeToMarkdownFormat[event.keyCode];
|
|
63
|
+
if (event.ctrlKey && event.altKey && format) {
|
|
64
|
+
var markdownHelpItem = markdownHelpItems.find(function (item) { return item.format === format; });
|
|
65
|
+
if (markdownHelpItem && textareaNode) {
|
|
66
|
+
event.stopPropagation();
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
var _a = [textareaNode.selectionStart, textareaNode.selectionEnd], start = _a[0], end = _a[1];
|
|
69
|
+
var prevCommentPart = text.substring(start, end);
|
|
70
|
+
var nextCommentPart = markdownHelpItem.wrapContent(prevCommentPart);
|
|
71
|
+
document.execCommand('insertText', false, nextCommentPart);
|
|
72
|
+
setTextareaCursor(format, prevCommentPart.length, nextCommentPart.length, textareaNode, end);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
callback && callback(event);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export var usePasteFromClipboard = function (textarea, uploadFileApi, downloadFileApi, fileApiUrl) {
|
|
79
|
+
var uploadFile = useFileLogic(uploadFileApi, downloadFileApi, fileApiUrl, textarea).uploadFile;
|
|
80
|
+
var textareaNode = textarea === null || textarea === void 0 ? void 0 : textarea.node;
|
|
81
|
+
useEffect(function () {
|
|
82
|
+
if (downloadFileApi && uploadFileApi) {
|
|
83
|
+
var handlePaste_1 = function (event) {
|
|
84
|
+
var _a, _b, _c, _d;
|
|
85
|
+
var files = (_a = event === null || event === void 0 ? void 0 : event.clipboardData) === null || _a === void 0 ? void 0 : _a.files;
|
|
86
|
+
var html = (_d = (_c = (_b = event === null || event === void 0 ? void 0 : event.clipboardData) === null || _b === void 0 ? void 0 : _b.getData('text/html')) === null || _c === void 0 ? void 0 : _c.replace("<meta charset='utf-8'>", '')) === null || _d === void 0 ? void 0 : _d.replace("<meta charset=\"utf-8\">", '');
|
|
87
|
+
if (files === null || files === void 0 ? void 0 : files.length) {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
void uploadFile(files[0]);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (html) {
|
|
93
|
+
getPastedHtml(html, event, textareaNode);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
if (textareaNode) {
|
|
98
|
+
textareaNode.addEventListener('paste', handlePaste_1);
|
|
99
|
+
}
|
|
100
|
+
return function () { return textareaNode === null || textareaNode === void 0 ? void 0 : textareaNode.removeEventListener('paste', handlePaste_1); };
|
|
101
|
+
}
|
|
102
|
+
}, [downloadFileApi, textareaNode, uploadFile, uploadFileApi]);
|
|
103
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Menu } from '@skbkontur/react-ui/internal/Menu';
|
|
2
|
+
import { ChangeEvent, MouseEvent, RefObject, SyntheticEvent } from 'react';
|
|
3
|
+
import { Token, User } from '../types';
|
|
4
|
+
export declare function mentionActions(event: ChangeEvent<HTMLTextAreaElement> | MouseEvent<HTMLTextAreaElement> | SyntheticEvent<HTMLTextAreaElement, Event>, setToken: (token?: Token) => void): void;
|
|
5
|
+
export declare const useMenuKeyListener: (onUserSelect: (login: string, name: string) => void, users?: User[], menuRef?: RefObject<Menu>) => void;
|
|
6
|
+
export declare const getMentionValue: (mention?: Token | null) => string;
|
|
7
|
+
export declare function getAvatarUrl(sid: undefined | null | string): string;
|