@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.
Files changed (61) hide show
  1. package/package.json +2 -2
  2. package/src/Markdown/Emoji/Emoji.logic.js +4 -4
  3. package/src/Markdown/Emoji/Emoji.styled.js +14 -21
  4. package/src/Markdown/Emoji/EmojiDropdown.js +6 -11
  5. package/src/Markdown/Emoji/helpers.js +4 -4
  6. package/src/Markdown/Files/Files.logic.js +46 -108
  7. package/src/Markdown/Markdown.creevey.js +73 -221
  8. package/src/Markdown/Markdown.js +62 -86
  9. package/src/Markdown/Markdown.styled.js +251 -90
  10. package/src/Markdown/MarkdownActions/AIActionsDropdown/AIActionsDropdown.js +45 -111
  11. package/src/Markdown/MarkdownActions/AIActionsDropdown/AIActionsDropdown.styled.js +16 -8
  12. package/src/Markdown/MarkdownActions/AIActionsDropdown/constants.js +2 -2
  13. package/src/Markdown/MarkdownActions/MarkdownActions.js +24 -37
  14. package/src/Markdown/MarkdownActions/MarkdownDropdown/MarkdownDropdown.js +3 -7
  15. package/src/Markdown/MarkdownActions/MarkdownDropdown/MarkdownDropdown.styled.js +8 -6
  16. package/src/Markdown/MarkdownEditor.js +6 -28
  17. package/src/Markdown/MarkdownHelpItems.js +61 -63
  18. package/src/Markdown/MarkdownHelpers/EmptyPreview.js +1 -1
  19. package/src/Markdown/MarkdownHelpers/MarkdownFormatButton.js +6 -7
  20. package/src/Markdown/MarkdownHelpers/constants.js +2 -2
  21. package/src/Markdown/MarkdownHelpers/markdownHelpers.d.ts +1 -0
  22. package/src/Markdown/MarkdownHelpers/markdownHelpers.js +50 -47
  23. package/src/Markdown/MarkdownHelpers/markdownListEnterHelpers.d.ts +2 -0
  24. package/src/Markdown/MarkdownHelpers/markdownListEnterHelpers.js +45 -0
  25. package/src/Markdown/MarkdownHelpers/markdownMentionHelpers.js +12 -12
  26. package/src/Markdown/MarkdownHelpers/markdownTextareaHelpers.js +34 -36
  27. package/src/Markdown/MarkdownMention.js +18 -64
  28. package/src/Markdown/constants.js +6 -6
  29. package/src/Markdown/utils/guid.js +13 -18
  30. package/src/Markdown/utils/htmlToMd.js +2 -2
  31. package/src/Markdown/utils/onInsertText.d.ts +1 -0
  32. package/src/Markdown/utils/onInsertText.js +3 -0
  33. package/src/Markdown/utils/saveFile.js +4 -4
  34. package/src/MarkdownCombination/MarkdownCombination.js +8 -9
  35. package/src/MarkdownCombination/MarkdownCombination.styled.js +7 -6
  36. package/src/MarkdownIcons/AttachLink.js +2 -2
  37. package/src/MarkdownIcons/AttachPaperclip.js +2 -2
  38. package/src/MarkdownIcons/CheckboxCheckedIcon.js +2 -2
  39. package/src/MarkdownIcons/CheckboxUncheckedIcon.js +2 -2
  40. package/src/MarkdownIcons/CheckedList.js +2 -2
  41. package/src/MarkdownIcons/Collapse.js +2 -2
  42. package/src/MarkdownIcons/Copy.js +1 -1
  43. package/src/MarkdownIcons/DocIcon.js +2 -2
  44. package/src/MarkdownIcons/EmojiFace.js +2 -2
  45. package/src/MarkdownIcons/EmptyPrviewArrow.js +1 -1
  46. package/src/MarkdownIcons/Expand.js +2 -2
  47. package/src/MarkdownIcons/EyeOpen.js +2 -2
  48. package/src/MarkdownIcons/List.js +2 -2
  49. package/src/MarkdownIcons/MarkdownIcons.styled.js +3 -6
  50. package/src/MarkdownIcons/NatureFxSparkleA2.js +1 -1
  51. package/src/MarkdownIcons/NumberedList.js +2 -2
  52. package/src/MarkdownIcons/SplitView.js +1 -1
  53. package/src/MarkdownIcons/Table.js +2 -2
  54. package/src/MarkdownIcons/ToolPencil.js +2 -2
  55. package/src/MarkdownViewer/Helpers/MarkdownImage.js +1 -2
  56. package/src/MarkdownViewer/Helpers/MarkdownLink.js +1 -4
  57. package/src/MarkdownViewer/Helpers/MarkdownTable.js +1 -2
  58. package/src/MarkdownViewer/MarkdownViewer.js +18 -26
  59. package/src/MarkdownViewer/MarkdownViewer.styles.js +163 -19
  60. package/src/styles/styled-components.js +1 -1
  61. 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 var AIActionsDropdown = function (_a) {
49
- var _b, _c, _d, _e;
50
- var textareaRef = _a.textareaRef, isPreviewMode = _a.isPreviewMode, showActionHint = _a.showActionHint, api = _a.api;
51
- var _f = useState(), processedText = _f[0], setProcessedText = _f[1];
52
- var _g = useState(RequestStatus.Default), requestStatus = _g[0], setRequestStatus = _g[1];
53
- var tooltipRef = useRef(null);
54
- var taskIdRef = useRef(new Guid());
55
- var availableMethods = api.availableMethods, onSendMessage = api.onSendMessage;
56
- var htmlTextArea = (_b = textareaRef === null || textareaRef === void 0 ? void 0 : textareaRef.current) === null || _b === void 0 ? void 0 : _b.node;
57
- var selectionStart = (_c = htmlTextArea === null || htmlTextArea === void 0 ? void 0 : htmlTextArea.selectionStart) !== null && _c !== void 0 ? _c : 0;
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(function () {
63
- var _a;
25
+ useEffect(() => {
64
26
  if (processedText)
65
- (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.show();
27
+ tooltipRef.current?.show();
66
28
  }, [processedText]);
67
- var value = (_e = htmlTextArea === null || htmlTextArea === void 0 ? void 0 : htmlTextArea.value.substring(Number(selectionStart), selectionEnd !== null && selectionEnd !== void 0 ? selectionEnd : undefined)) !== null && _e !== void 0 ? _e : '';
68
- var isEmptySelected = selectionEnd === selectionStart;
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(function (_a) {
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: function (e) { return e.preventDefault(); }, onClick: handleCopyText }))))));
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
- var _a;
86
- return __awaiter(this, void 0, void 0, function () {
87
- var taskId, response, e_1;
88
- return __generator(this, function (_b) {
89
- switch (_b.label) {
90
- case 0:
91
- taskId = taskIdRef.current.generate();
92
- _b.label = 1;
93
- case 1:
94
- _b.trys.push([1, 3, , 4]);
95
- (_a = tooltipRef === null || tooltipRef === void 0 ? void 0 : tooltipRef.current) === null || _a === void 0 ? void 0 : _a.show();
96
- setRequestStatus(RequestStatus.isFetching);
97
- return [4 /*yield*/, onSendMessage(value, method)];
98
- case 2:
99
- response = _b.sent();
100
- /* Игнорируем ответ, если это не последний запрос Например, закрыли тултип и отправили новый запрос */
101
- if (response && taskId === taskIdRef.current.generated) {
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
- return __awaiter(this, void 0, void 0, function () {
120
- return __generator(this, function (_a) {
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 (!(textareaRef === null || textareaRef === void 0 ? void 0 : textareaRef.current))
67
+ if (!textareaRef?.current)
133
68
  return null;
134
69
  textareaRef.current.focus();
135
- var valueLength = value.length;
136
- var spaceInStartCount = valueLength - value.trimStart().length;
137
- var spaceInEndCount = valueLength - value.trimEnd().length;
138
- htmlTextArea === null || htmlTextArea === void 0 ? void 0 : htmlTextArea.setSelectionRange(selectionStart + spaceInStartCount, selectionEnd - spaceInEndCount);
139
- document.execCommand('insertText', false, processedText);
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
- (_a = tooltipRef === null || tooltipRef === void 0 ? void 0 : tooltipRef.current) === null || _a === void 0 ? void 0 : _a.hide();
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 var TooltipWrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n gap: 16px;\n max-width: 300px;\n"], ["\n display: flex;\n flex-direction: column;\n gap: 16px;\n max-width: 300px;\n"])));
7
- export var TooltipContentWrapper = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n max-height: 400px;\n white-space: pre-wrap;\n overflow-y: auto;\n"], ["\n max-height: 400px;\n white-space: pre-wrap;\n overflow-y: auto;\n"])));
8
- export var TooltipButtonsWrapper = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n gap: 8px;\n"], ["\n display: flex;\n align-items: center;\n gap: 8px;\n"])));
9
- var templateObject_1, templateObject_2, templateObject_3;
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 var ERRORS_NOT_FOUND_TEXT = 'Ошибок не найдено';
2
- export var COPY_BUTTON_TEXT = 'Скопировать';
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 var MarkdownActions = function (_a) {
32
- 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, width = _a.width, showActionHints = _a.showActionHints, showShortKeys = _a.showShortKeys, hideOptions = _a.hideOptions, onSelectEmoji = _a.onSelectEmoji, isSplitViewAvailable = _a.isSplitViewAvailable, disableFullscreen = _a.disableFullscreen, AIApi = _a.AIApi;
33
- var isPreviewMode = viewMode === ViewMode.Preview;
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
- !(hideOptions === null || hideOptions === void 0 ? void 0 : 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(function (helper, idx) { return (React.createElement(MarkdownMenuItem, { key: idx, "data-tid": helper.tid, onClick: function (event) { return handleMarkdownItemClick(event, helper.format); } },
38
- React.createElement(MarkdownCombination, { showShortKey: showShortKeys, format: helper.format, text: helper.node }))); }))),
39
- markdownHelpText.map(function (helper, idx) {
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: function (event) { return handleMarkdownItemClick(event, helper.format); } }));
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(function (helper, idx) {
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: function (event) { return handleMarkdownItemClick(event, helper.format); } }));
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(function (helper, idx) {
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: function (event) { return handleMarkdownItemClick(event, helper.format); } }));
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 && !(hideOptions === null || hideOptions === void 0 ? void 0 : 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 })),
55
- !(hideOptions === null || hideOptions === void 0 ? void 0 : hideOptions.emoji) && (React.createElement(EmojiDropdown, { showActionHint: showActionHints, showShortKey: showShortKeys, isPreviewMode: isPreviewMode, onSelect: onSelectEmoji })),
56
- !(hideOptions === null || hideOptions === void 0 ? void 0 : hideOptions.AI) && !!AIApi && (React.createElement(AIActionsDropdown, { showActionHint: showActionHints, textareaRef: textAreaRef, isPreviewMode: isPreviewMode, api: AIApi }))),
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
- !(hideOptions === null || hideOptions === void 0 ? void 0 : 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 })),
59
- !(hideOptions === null || hideOptions === void 0 ? void 0 : hideOptions.viewMode) && renderViewModeButton(),
60
- !(hideOptions === null || hideOptions === void 0 ? void 0 : 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 }))))));
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: function () { return onChangeViewMode(ViewMode.Split); } })),
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: function () { return onChangeViewMode(ViewMode.Edit); } })),
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: function () { return onChangeViewMode(ViewMode.Preview); } }))));
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 === null || textAreaRef === void 0 ? void 0 : textAreaRef.current) {
59
+ if (textAreaRef?.current) {
73
60
  textAreaRef.current.focus();
74
- var htmlTextArea = textAreaRef.current.node;
61
+ const htmlTextArea = textAreaRef.current.node;
75
62
  htmlTextArea.selectionStart = Number(selectionStart);
76
63
  htmlTextArea.selectionEnd = Number(selectionEnd);
77
- setMarkdown(htmlTextArea, (_a = htmlTextArea.value) !== null && _a !== void 0 ? _a : '', format, Number(selectionStart), selectionEnd);
64
+ setMarkdown(htmlTextArea, htmlTextArea.value ?? '', format, Number(selectionStart), selectionEnd);
78
65
  }
79
66
  }
80
67
  }
81
68
  function isHiddenOptions(format) {
82
- return hideOptions === null || hideOptions === void 0 ? void 0 : hideOptions[format];
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 var MarkdownDropdown = function (_a) {
6
- var dataTid = _a.dataTid, icon = _a.icon, disabled = _a.disabled, children = _a.children, caption = _a.caption, onOpen = _a.onOpen, menuWidth = _a.menuWidth, hintText = _a.hintText, showActionHint = _a.showActionHint, showHintWhenDisabled = _a.showHintWhenDisabled, hintPos = _a.hintPos;
7
- return (React.createElement(Wrapper, { onMouseDown: function (e) { return e.preventDefault(); } },
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 var Wrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n\n button {\n font-size: ", ";\n }\n"], ["\n display: flex;\n align-items: center;\n\n button {\n font-size: ", ";\n }\n"])), function (p) { return p.theme.elementsFontSize; });
7
- var templateObject_1;
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 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, renderMessage = props.renderMessage, withValidationWrapper = props.withValidationWrapper, rest = __rest(props, ["resize", "width", "autoResize", "showLengthCounter", "textareaRef", "validationInfo", "renderMessage", "withValidationWrapper"]);
30
- var getInputProps = useDropzone().getInputProps;
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, __assign({ ref: textareaRef, id: "MarkdownTextArea" }, rest, getInputProps, { resize: resize, width: width, showLengthCounter: showLengthCounter(), autoResize: autoResize, onKeyDown: createMarkdownHelpKeyDownHandler(props.value || '', textareaRef, props.onKeyDown) })));
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
- var value = rest.value, maxLength = rest.maxLength;
38
- return Number(maxLength) - Number(value === null || value === void 0 ? void 0 : value.length) <= 500;
15
+ const { value, maxLength } = rest;
16
+ return Number(maxLength) - Number(value?.length) <= 500;
39
17
  }
40
18
  return false;
41
19
  }