@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,39 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
1
|
import { Button, Hint, Spinner, Toast, Tooltip } from '@skbkontur/react-ui';
|
|
38
2
|
import React, { useEffect, useRef, useState } from 'react';
|
|
39
3
|
import { TooltipButtonsWrapper, TooltipContentWrapper, TooltipWrapper } from './AIActionsDropdown.styled';
|
|
@@ -43,34 +7,29 @@ import { NatureFxSparkleA2 } from '../../../MarkdownIcons/NatureFxSparkleA2';
|
|
|
43
7
|
import { MarkdownMenuItem } from '../../Markdown.styled';
|
|
44
8
|
import { MarkdownTids } from '../../MarkdownTids';
|
|
45
9
|
import { Guid } from '../../utils/guid';
|
|
10
|
+
import { onInsertText } from '../../utils/onInsertText';
|
|
46
11
|
import { RequestStatus } from '../../utils/requestStatus';
|
|
47
12
|
import { MarkdownDropdown } from '../MarkdownDropdown/MarkdownDropdown';
|
|
48
|
-
export
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var selectionEnd = (_d = htmlTextArea === null || htmlTextArea === void 0 ? void 0 : htmlTextArea.selectionEnd) !== null && _d !== void 0 ? _d : 0;
|
|
59
|
-
useEffect(function () {
|
|
13
|
+
export const AIActionsDropdown = ({ textareaRef, isPreviewMode, showActionHint, api }) => {
|
|
14
|
+
const [processedText, setProcessedText] = useState();
|
|
15
|
+
const [requestStatus, setRequestStatus] = useState(RequestStatus.Default);
|
|
16
|
+
const tooltipRef = useRef(null);
|
|
17
|
+
const taskIdRef = useRef(new Guid());
|
|
18
|
+
const { availableMethods, onSendMessage } = api;
|
|
19
|
+
const htmlTextArea = textareaRef?.current?.node;
|
|
20
|
+
const selectionStart = htmlTextArea?.selectionStart ?? 0;
|
|
21
|
+
const selectionEnd = htmlTextArea?.selectionEnd ?? 0;
|
|
22
|
+
useEffect(() => {
|
|
60
23
|
handleCloseTooltip();
|
|
61
24
|
}, [selectionStart, selectionEnd]);
|
|
62
|
-
useEffect(
|
|
63
|
-
var _a;
|
|
25
|
+
useEffect(() => {
|
|
64
26
|
if (processedText)
|
|
65
|
-
|
|
27
|
+
tooltipRef.current?.show();
|
|
66
28
|
}, [processedText]);
|
|
67
|
-
|
|
68
|
-
|
|
29
|
+
const value = htmlTextArea?.value.substring(Number(selectionStart), selectionEnd ?? undefined) ?? '';
|
|
30
|
+
const isEmptySelected = selectionEnd === selectionStart;
|
|
69
31
|
return (React.createElement(Tooltip, { key: processedText, ref: tooltipRef, pos: "top right", allowedPositions: ['top right', 'right middle', 'bottom right', 'bottom left'], trigger: "manual", render: renderTooltipContent },
|
|
70
|
-
React.createElement(MarkdownDropdown, { dataTid: MarkdownTids.AI, hintPos: "top center", showActionHint: showActionHint, showHintWhenDisabled: !isPreviewMode, hintText: isEmptySelected ? 'Выдели текст' : 'ИИ-помощник', icon: React.createElement(NatureFxSparkleA2, null), caption: "\u0418\u0418", menuWidth: 180, disabled: isPreviewMode || isEmptySelected, onOpen: handleCloseTooltip }, availableMethods.map(
|
|
71
|
-
var method = _a.method, caption = _a.caption;
|
|
72
|
-
return (React.createElement(MarkdownMenuItem, { key: method, onClick: function () { return handleProcessText(method); } }, caption));
|
|
73
|
-
}))));
|
|
32
|
+
React.createElement(MarkdownDropdown, { dataTid: MarkdownTids.AI, hintPos: "top center", showActionHint: showActionHint, showHintWhenDisabled: !isPreviewMode, hintText: isEmptySelected ? 'Выдели текст' : 'ИИ-помощник', icon: React.createElement(NatureFxSparkleA2, null), caption: "\u0418\u0418", menuWidth: 180, disabled: isPreviewMode || isEmptySelected, onOpen: handleCloseTooltip }, availableMethods.map(({ method, caption }) => (React.createElement(MarkdownMenuItem, { key: method, onClick: () => handleProcessText(method) }, caption))))));
|
|
74
33
|
function renderTooltipContent() {
|
|
75
34
|
if (requestStatus === RequestStatus.isFetching)
|
|
76
35
|
return React.createElement(Spinner, { caption: "\u041E\u0431\u0440\u0430\u0431\u0430\u0442\u044B\u0432\u0430\u0435\u043C", type: "mini" });
|
|
@@ -79,69 +38,44 @@ export var AIActionsDropdown = function (_a) {
|
|
|
79
38
|
processedText !== ERRORS_NOT_FOUND_TEXT && (React.createElement(TooltipButtonsWrapper, null,
|
|
80
39
|
React.createElement(Button, { onClick: handleSetText }, "\u0417\u0430\u043C\u0435\u043D\u0438\u0442\u044C \u0442\u0435\u043A\u0441\u0442"),
|
|
81
40
|
React.createElement(Hint, { text: COPY_BUTTON_TEXT },
|
|
82
|
-
React.createElement(Button, { "aria-label": COPY_BUTTON_TEXT, icon: React.createElement(Copy, null), onMouseDown:
|
|
41
|
+
React.createElement(Button, { "aria-label": COPY_BUTTON_TEXT, icon: React.createElement(Copy, null), onMouseDown: e => e.preventDefault(), onClick: handleCopyText }))))));
|
|
83
42
|
}
|
|
84
|
-
function handleProcessText(method) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
setRequestStatus(RequestStatus.isLoaded);
|
|
103
|
-
setProcessedText(value.trim() === response ? ERRORS_NOT_FOUND_TEXT : response);
|
|
104
|
-
}
|
|
105
|
-
return [3 /*break*/, 4];
|
|
106
|
-
case 3:
|
|
107
|
-
e_1 = _b.sent();
|
|
108
|
-
if (taskId === taskIdRef.current.generated) {
|
|
109
|
-
handleCloseTooltip();
|
|
110
|
-
Toast.push('Ошибка обработки текста');
|
|
111
|
-
}
|
|
112
|
-
return [3 /*break*/, 4];
|
|
113
|
-
case 4: return [2 /*return*/];
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
});
|
|
43
|
+
async function handleProcessText(method) {
|
|
44
|
+
const taskId = taskIdRef.current.generate();
|
|
45
|
+
try {
|
|
46
|
+
tooltipRef?.current?.show();
|
|
47
|
+
setRequestStatus(RequestStatus.isFetching);
|
|
48
|
+
const response = await onSendMessage(value, method);
|
|
49
|
+
/* Игнорируем ответ, если это не последний запрос Например, закрыли тултип и отправили новый запрос */
|
|
50
|
+
if (response && taskId === taskIdRef.current.generated) {
|
|
51
|
+
setRequestStatus(RequestStatus.isLoaded);
|
|
52
|
+
setProcessedText(value.trim() === response ? ERRORS_NOT_FOUND_TEXT : response);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
if (taskId === taskIdRef.current.generated) {
|
|
57
|
+
handleCloseTooltip();
|
|
58
|
+
Toast.push('Ошибка обработки текста');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
117
61
|
}
|
|
118
|
-
function handleCopyText() {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
switch (_a.label) {
|
|
122
|
-
case 0: return [4 /*yield*/, navigator.clipboard.writeText(processedText || '')];
|
|
123
|
-
case 1:
|
|
124
|
-
_a.sent();
|
|
125
|
-
handleCloseTooltip();
|
|
126
|
-
return [2 /*return*/];
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
});
|
|
62
|
+
async function handleCopyText() {
|
|
63
|
+
await navigator.clipboard.writeText(processedText || '');
|
|
64
|
+
handleCloseTooltip();
|
|
130
65
|
}
|
|
131
66
|
function handleSetText() {
|
|
132
|
-
if (!
|
|
67
|
+
if (!textareaRef?.current)
|
|
133
68
|
return null;
|
|
134
69
|
textareaRef.current.focus();
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
htmlTextArea
|
|
139
|
-
|
|
70
|
+
const valueLength = value.length;
|
|
71
|
+
const spaceInStartCount = valueLength - value.trimStart().length;
|
|
72
|
+
const spaceInEndCount = valueLength - value.trimEnd().length;
|
|
73
|
+
htmlTextArea?.setSelectionRange(selectionStart + spaceInStartCount, selectionEnd - spaceInEndCount);
|
|
74
|
+
onInsertText(processedText);
|
|
140
75
|
handleCloseTooltip();
|
|
141
76
|
}
|
|
142
77
|
function handleCloseTooltip() {
|
|
143
|
-
var _a;
|
|
144
78
|
setProcessedText(undefined);
|
|
145
|
-
|
|
79
|
+
tooltipRef?.current?.hide();
|
|
146
80
|
}
|
|
147
81
|
};
|
|
@@ -1,9 +1,17 @@
|
|
|
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 from '../../../styles/styled-components';
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
export const TooltipWrapper = styled.div `
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
gap: 16px;
|
|
6
|
+
max-width: 300px;
|
|
7
|
+
`;
|
|
8
|
+
export const TooltipContentWrapper = styled.div `
|
|
9
|
+
max-height: 400px;
|
|
10
|
+
white-space: pre-wrap;
|
|
11
|
+
overflow-y: auto;
|
|
12
|
+
`;
|
|
13
|
+
export const TooltipButtonsWrapper = styled.div `
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
gap: 8px;
|
|
17
|
+
`;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export const ERRORS_NOT_FOUND_TEXT = 'Ошибок не найдено';
|
|
2
|
+
export const COPY_BUTTON_TEXT = 'Скопировать';
|
|
@@ -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 React from 'react';
|
|
13
2
|
import { AIActionsDropdown } from './AIActionsDropdown/AIActionsDropdown';
|
|
14
3
|
import { MarkdownDropdown } from './MarkdownDropdown/MarkdownDropdown';
|
|
@@ -28,57 +17,55 @@ import { setMarkdown } from '../MarkdownHelpers/markdownHelpers';
|
|
|
28
17
|
import { markdownHelpHeaders, markdownHelpLists, markdownHelpOther, markdownHelpText } from '../MarkdownHelpItems';
|
|
29
18
|
import { MarkdownTids } from '../MarkdownTids';
|
|
30
19
|
import { ViewMode } from '../types';
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return (React.createElement(MarkdownActionsWrapper, __assign({}, horizontalPaddings, { width: width, fullscreen: fullscreen }),
|
|
20
|
+
export const MarkdownActions = ({ textAreaRef, selectionStart, selectionEnd, loadingFile, onOpenFileDialog, onClickFullscreen, fullscreen, viewMode, onChangeViewMode, horizontalPaddings, hasFilesApi, width, showActionHints, showShortKeys, hideOptions, onSelectEmoji, isSplitViewAvailable, disableFullscreen, AIApi, }) => {
|
|
21
|
+
const isPreviewMode = viewMode === ViewMode.Preview;
|
|
22
|
+
return (React.createElement(MarkdownActionsWrapper, { ...horizontalPaddings, width: width, fullscreen: fullscreen },
|
|
35
23
|
React.createElement(ButtonsWrapper, { fullscreen: fullscreen },
|
|
36
24
|
React.createElement(ActionsLeftWrapper, null,
|
|
37
|
-
!
|
|
38
|
-
React.createElement(MarkdownCombination, { showShortKey: showShortKeys, format: helper.format, text: helper.node })))
|
|
39
|
-
markdownHelpText.map(
|
|
25
|
+
!hideOptions?.heading && (React.createElement(MarkdownDropdown, { dataTid: MarkdownTids.HeadingDropdown, showActionHint: showActionHints, hintPos: "top left", caption: "H", hintText: "\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A", disabled: isPreviewMode }, markdownHelpHeaders.map((helper, idx) => (React.createElement(MarkdownMenuItem, { key: idx, "data-tid": helper.tid, onClick: (event) => handleMarkdownItemClick(event, helper.format) },
|
|
26
|
+
React.createElement(MarkdownCombination, { showShortKey: showShortKeys, format: helper.format, text: helper.node })))))),
|
|
27
|
+
markdownHelpText.map((helper, idx) => {
|
|
40
28
|
if (isHiddenOptions(helper.format))
|
|
41
29
|
return null;
|
|
42
|
-
return (React.createElement(MarkdownFormatButton, { key: idx, showActionHint: showActionHints, showShortKey: showShortKeys, disabled: isPreviewMode, format: helper.format, dataTid: helper.tid, hintText: helper.node, icon: helper.icon, text: helper.text, onClick:
|
|
30
|
+
return (React.createElement(MarkdownFormatButton, { key: idx, showActionHint: showActionHints, showShortKey: showShortKeys, disabled: isPreviewMode, format: helper.format, dataTid: helper.tid, hintText: helper.node, icon: helper.icon, text: helper.text, onClick: event => handleMarkdownItemClick(event, helper.format) }));
|
|
43
31
|
}),
|
|
44
|
-
markdownHelpLists.map(
|
|
32
|
+
markdownHelpLists.map((helper, idx) => {
|
|
45
33
|
if (isHiddenOptions(helper.format))
|
|
46
34
|
return null;
|
|
47
|
-
return (React.createElement(MarkdownFormatButton, { key: idx, showActionHint: showActionHints, showShortKey: showShortKeys, disabled: isPreviewMode, format: helper.format, dataTid: helper.tid, hintText: helper.node, icon: helper.icon, text: helper.text, onClick:
|
|
35
|
+
return (React.createElement(MarkdownFormatButton, { key: idx, showActionHint: showActionHints, showShortKey: showShortKeys, disabled: isPreviewMode, format: helper.format, dataTid: helper.tid, hintText: helper.node, icon: helper.icon, text: helper.text, onClick: event => handleMarkdownItemClick(event, helper.format) }));
|
|
48
36
|
}),
|
|
49
|
-
markdownHelpOther.map(
|
|
37
|
+
markdownHelpOther.map((helper, idx) => {
|
|
50
38
|
if (isHiddenOptions(helper.format))
|
|
51
39
|
return null;
|
|
52
|
-
return (React.createElement(MarkdownFormatButton, { key: idx, showActionHint: showActionHints, showShortKey: showShortKeys, disabled: isPreviewMode, format: helper.format, dataTid: helper.tid, hintText: helper.node, icon: helper.icon, text: helper.text, onClick:
|
|
40
|
+
return (React.createElement(MarkdownFormatButton, { key: idx, showActionHint: showActionHints, showShortKey: showShortKeys, disabled: isPreviewMode, format: helper.format, dataTid: helper.tid, hintText: helper.node, icon: helper.icon, text: helper.text, onClick: event => handleMarkdownItemClick(event, helper.format) }));
|
|
53
41
|
}),
|
|
54
|
-
hasFilesApi && !
|
|
55
|
-
!
|
|
56
|
-
!
|
|
42
|
+
hasFilesApi && !hideOptions?.file && (React.createElement(MarkdownFormatButton, { dataTid: MarkdownTids.AttachFile, hintText: "\u041F\u0440\u0438\u043A\u0440\u0435\u043F\u0438\u0442\u044C \u0444\u0430\u0439\u043B", showActionHint: showActionHints, showShortKey: showShortKeys, 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 })),
|
|
43
|
+
!hideOptions?.emoji && (React.createElement(EmojiDropdown, { showActionHint: showActionHints, showShortKey: showShortKeys, isPreviewMode: isPreviewMode, onSelect: onSelectEmoji })),
|
|
44
|
+
!hideOptions?.AI && !!AIApi && (React.createElement(AIActionsDropdown, { showActionHint: showActionHints, textareaRef: textAreaRef, isPreviewMode: isPreviewMode, api: AIApi }))),
|
|
57
45
|
React.createElement(ActionsRightWrapper, null,
|
|
58
|
-
!
|
|
59
|
-
!
|
|
60
|
-
!
|
|
46
|
+
!hideOptions?.help && (React.createElement(MarkdownFormatButton, { showActionHint: showActionHints, dataTid: MarkdownTids.Help, hintText: "\u0414\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u0430\u0446\u0438\u044F Markdown", icon: React.createElement(DocIcon, null), text: "\u0414\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u0430\u0446\u0438\u044F Markdown", href: COMMONMARK_HELP_URL })),
|
|
47
|
+
!hideOptions?.viewMode && renderViewModeButton(),
|
|
48
|
+
!hideOptions?.screenMode && !disableFullscreen && (React.createElement(MarkdownFormatButton, { showActionHint: showActionHints, dataTid: MarkdownTids.FullscreenToggle, hintText: fullscreen ? 'Свернуть' : 'Развернуть', icon: fullscreen ? React.createElement(Collapse, null) : React.createElement(Expand, null), text: fullscreen ? 'Свернуть' : ' Развернуть', onClick: onClickFullscreen }))))));
|
|
61
49
|
function renderViewModeButton() {
|
|
62
50
|
return (React.createElement(ViewModeButtonsWrapper, null,
|
|
63
|
-
viewMode !== ViewMode.Split && fullscreen && isSplitViewAvailable && (React.createElement(MarkdownFormatButton, { dataTid: MarkdownTids.SplitView, icon: React.createElement(SplitView, null), hintText: "\u0421\u043F\u043B\u0438\u0442", text: "\u0421\u043F\u043B\u0438\u0442", showActionHint: showActionHints, showShortKey: showShortKeys, onClick:
|
|
64
|
-
viewMode !== ViewMode.Edit && (React.createElement(MarkdownFormatButton, { dataTid: MarkdownTids.EditView, icon: React.createElement(ToolPencil, null), hintText: "\u0420\u0435\u0434\u0430\u043A\u0442\u043E\u0440", text: "\u0420\u0435\u0434\u0430\u043A\u0442\u043E\u0440", showActionHint: showActionHints, showShortKey: showShortKeys, onClick:
|
|
65
|
-
viewMode !== ViewMode.Preview && (React.createElement(MarkdownFormatButton, { dataTid: MarkdownTids.PreviewView, icon: React.createElement(EyeOpen, null), hintText: "\u041F\u0440\u0435\u0432\u044C\u044E", text: "\u041F\u0440\u0435\u0432\u044C\u044E", showActionHint: showActionHints, showShortKey: showShortKeys, onClick:
|
|
51
|
+
viewMode !== ViewMode.Split && fullscreen && isSplitViewAvailable && (React.createElement(MarkdownFormatButton, { dataTid: MarkdownTids.SplitView, icon: React.createElement(SplitView, null), hintText: "\u0421\u043F\u043B\u0438\u0442", text: "\u0421\u043F\u043B\u0438\u0442", showActionHint: showActionHints, showShortKey: showShortKeys, onClick: () => onChangeViewMode(ViewMode.Split) })),
|
|
52
|
+
viewMode !== ViewMode.Edit && (React.createElement(MarkdownFormatButton, { dataTid: MarkdownTids.EditView, icon: React.createElement(ToolPencil, null), hintText: "\u0420\u0435\u0434\u0430\u043A\u0442\u043E\u0440", text: "\u0420\u0435\u0434\u0430\u043A\u0442\u043E\u0440", showActionHint: showActionHints, showShortKey: showShortKeys, onClick: () => onChangeViewMode(ViewMode.Edit) })),
|
|
53
|
+
viewMode !== ViewMode.Preview && (React.createElement(MarkdownFormatButton, { dataTid: MarkdownTids.PreviewView, icon: React.createElement(EyeOpen, null), hintText: "\u041F\u0440\u0435\u0432\u044C\u044E", text: "\u041F\u0440\u0435\u0432\u044C\u044E", showActionHint: showActionHints, showShortKey: showShortKeys, onClick: () => onChangeViewMode(ViewMode.Preview) }))));
|
|
66
54
|
}
|
|
67
55
|
function handleMarkdownItemClick(event, format) {
|
|
68
|
-
var _a;
|
|
69
56
|
if (!isNaN(Number(selectionStart)) && !isNaN(Number(selectionEnd))) {
|
|
70
57
|
event.stopPropagation();
|
|
71
58
|
event.preventDefault();
|
|
72
|
-
if (textAreaRef
|
|
59
|
+
if (textAreaRef?.current) {
|
|
73
60
|
textAreaRef.current.focus();
|
|
74
|
-
|
|
61
|
+
const htmlTextArea = textAreaRef.current.node;
|
|
75
62
|
htmlTextArea.selectionStart = Number(selectionStart);
|
|
76
63
|
htmlTextArea.selectionEnd = Number(selectionEnd);
|
|
77
|
-
setMarkdown(htmlTextArea,
|
|
64
|
+
setMarkdown(htmlTextArea, htmlTextArea.value ?? '', format, Number(selectionStart), selectionEnd);
|
|
78
65
|
}
|
|
79
66
|
}
|
|
80
67
|
}
|
|
81
68
|
function isHiddenOptions(format) {
|
|
82
|
-
return hideOptions
|
|
69
|
+
return hideOptions?.[format];
|
|
83
70
|
}
|
|
84
71
|
};
|
|
@@ -2,11 +2,7 @@ import { Dropdown } from '@skbkontur/react-ui';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { Wrapper } from './MarkdownDropdown.styled';
|
|
4
4
|
import { MarkdownFormatButton } from '../../MarkdownHelpers/MarkdownFormatButton';
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
React.createElement(Dropdown, { disablePortal: true, disabled: disabled, caption: caption, menuWidth: menuWidth !== null && menuWidth !== void 0 ? menuWidth : 300, _renderButton: function (_a) {
|
|
9
|
-
var onClick = _a.onClick;
|
|
10
|
-
return (React.createElement(MarkdownFormatButton, { showText: true, dataTid: dataTid, hintPos: hintPos, showActionHint: showActionHint, showHintWhenDisabled: showHintWhenDisabled, disabled: disabled, hintText: hintText, icon: icon, text: caption, onClick: function () { return onClick(); } }));
|
|
11
|
-
}, onOpen: onOpen }, children)));
|
|
5
|
+
export const MarkdownDropdown = ({ dataTid, icon, disabled, children, caption, onOpen, menuWidth, hintText, showActionHint, showHintWhenDisabled, hintPos, }) => {
|
|
6
|
+
return (React.createElement(Wrapper, { onMouseDown: e => e.preventDefault() },
|
|
7
|
+
React.createElement(Dropdown, { disablePortal: true, disabled: disabled, caption: caption, menuWidth: menuWidth ?? 300, _renderButton: ({ onClick }) => (React.createElement(MarkdownFormatButton, { showText: true, dataTid: dataTid, hintPos: hintPos, showActionHint: showActionHint, showHintWhenDisabled: showHintWhenDisabled, disabled: disabled, hintText: hintText, icon: icon, text: caption, onClick: () => onClick() })), onOpen: onOpen }, children)));
|
|
12
8
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
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 from '../../../styles/styled-components';
|
|
6
|
-
export
|
|
7
|
-
|
|
2
|
+
export const Wrapper = styled.div `
|
|
3
|
+
display: flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
|
|
6
|
+
button {
|
|
7
|
+
font-size: ${p => p.theme.elementsFontSize};
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
@@ -1,41 +1,19 @@
|
|
|
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
1
|
import { Textarea } from '@skbkontur/react-ui';
|
|
24
2
|
import { ValidationWrapper } from '@skbkontur/react-ui-validations';
|
|
25
3
|
import React from 'react';
|
|
26
4
|
import { useDropzone } from 'react-dropzone';
|
|
27
5
|
import { createMarkdownHelpKeyDownHandler } from './MarkdownHelpers/markdownHelpers';
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
6
|
+
export const MarkdownEditor = props => {
|
|
7
|
+
const { resize = 'none', width = '100%', autoResize = true, showLengthCounter: propsShowLengthCounter = true, textareaRef, validationInfo, renderMessage, withValidationWrapper, ...rest } = props;
|
|
8
|
+
const { getInputProps } = useDropzone();
|
|
31
9
|
return withValidationWrapper ? (React.createElement(ValidationWrapper, { validationInfo: validationInfo, renderMessage: renderMessage }, renderTextarea())) : (renderTextarea());
|
|
32
10
|
function renderTextarea() {
|
|
33
|
-
return (React.createElement(Textarea,
|
|
11
|
+
return (React.createElement(Textarea, { ref: textareaRef, id: "MarkdownTextArea", ...rest, ...getInputProps, resize: resize, width: width, showLengthCounter: showLengthCounter(), autoResize: autoResize, onKeyDown: createMarkdownHelpKeyDownHandler(props.value || '', textareaRef, props.onKeyDown) }));
|
|
34
12
|
}
|
|
35
13
|
function showLengthCounter() {
|
|
36
14
|
if (propsShowLengthCounter) {
|
|
37
|
-
|
|
38
|
-
return Number(maxLength) - Number(value
|
|
15
|
+
const { value, maxLength } = rest;
|
|
16
|
+
return Number(maxLength) - Number(value?.length) <= 500;
|
|
39
17
|
}
|
|
40
18
|
return false;
|
|
41
19
|
}
|