@skbkontur/markdown 1.7.0 → 1.8.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 +1 -1
- package/src/Markdown/MarkdownHelpItems.d.ts +4 -1
- package/src/Markdown/MarkdownHelpItems.js +12 -10
- package/src/Markdown/MarkdownHelpers/MarkdownCombination.js +13 -6
- package/src/Markdown/MarkdownHelpers/MarkdownFormatButton.js +1 -1
- package/src/Markdown/MarkdownHelpers/markdownHelpers.js +4 -4
package/package.json
CHANGED
|
@@ -4,7 +4,10 @@ import { RefItem } from './types';
|
|
|
4
4
|
export declare const eventKeyCodeToMarkdownFormat: {
|
|
5
5
|
[key: number]: MarkdownFormat;
|
|
6
6
|
};
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const markdownFormatToShortKeyLong: Partial<{
|
|
8
|
+
[key in MarkdownFormat]: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const markdownFormatToShortKeyShort: Partial<{
|
|
8
11
|
[key in MarkdownFormat]: string;
|
|
9
12
|
}>;
|
|
10
13
|
export interface MarkdownHelpItem {
|
|
@@ -7,7 +7,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
7
7
|
}
|
|
8
8
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
9
|
};
|
|
10
|
-
var _a;
|
|
10
|
+
var _a, _b;
|
|
11
11
|
import React from 'react';
|
|
12
12
|
import { MarkdownSymbolWrapper } from './Markdown.styled';
|
|
13
13
|
import { MarkdownFormat } from './MarkdownFormat';
|
|
@@ -27,30 +27,32 @@ export var eventKeyCodeToMarkdownFormat = {
|
|
|
27
27
|
52: MarkdownFormat.h4,
|
|
28
28
|
66: MarkdownFormat.bold,
|
|
29
29
|
73: MarkdownFormat.italic,
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
83: MarkdownFormat.crossed,
|
|
31
|
+
75: MarkdownFormat.ref,
|
|
32
32
|
76: MarkdownFormat.list,
|
|
33
33
|
68: MarkdownFormat.checkedList,
|
|
34
34
|
78: MarkdownFormat.numberedList,
|
|
35
|
-
|
|
35
|
+
67: MarkdownFormat.codeBlock,
|
|
36
36
|
81: MarkdownFormat.quote,
|
|
37
37
|
80: MarkdownFormat.image,
|
|
38
38
|
};
|
|
39
|
-
export var
|
|
39
|
+
export var markdownFormatToShortKeyLong = (_a = {},
|
|
40
40
|
_a[MarkdownFormat.h2] = '2',
|
|
41
41
|
_a[MarkdownFormat.h3] = '3',
|
|
42
42
|
_a[MarkdownFormat.h4] = '4',
|
|
43
|
-
_a[MarkdownFormat.
|
|
44
|
-
_a[MarkdownFormat.italic] = 'I',
|
|
45
|
-
_a[MarkdownFormat.crossed] = 'R',
|
|
46
|
-
_a[MarkdownFormat.ref] = 'U',
|
|
43
|
+
_a[MarkdownFormat.crossed] = 'S',
|
|
47
44
|
_a[MarkdownFormat.list] = 'L',
|
|
48
45
|
_a[MarkdownFormat.checkedList] = 'D',
|
|
49
46
|
_a[MarkdownFormat.numberedList] = 'N',
|
|
50
|
-
_a[MarkdownFormat.codeBlock] = '
|
|
47
|
+
_a[MarkdownFormat.codeBlock] = 'C',
|
|
51
48
|
_a[MarkdownFormat.quote] = 'Q',
|
|
52
49
|
_a[MarkdownFormat.image] = 'P',
|
|
53
50
|
_a);
|
|
51
|
+
export var markdownFormatToShortKeyShort = (_b = {},
|
|
52
|
+
_b[MarkdownFormat.bold] = 'B',
|
|
53
|
+
_b[MarkdownFormat.italic] = 'I',
|
|
54
|
+
_b[MarkdownFormat.ref] = 'K',
|
|
55
|
+
_b);
|
|
54
56
|
function reverseString(text) {
|
|
55
57
|
return text.split('').reverse().join('');
|
|
56
58
|
}
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { HintContentWrapper } from '../Markdown.styled';
|
|
3
|
-
import {
|
|
3
|
+
import { markdownFormatToShortKeyLong, markdownFormatToShortKeyShort } from '../MarkdownHelpItems';
|
|
4
4
|
import { isMacintosh } from '../utils/isMacintosh';
|
|
5
5
|
export var MarkdownCombination = function (_a) {
|
|
6
6
|
var format = _a.format, text = _a.text;
|
|
7
|
-
var
|
|
7
|
+
var shortKeyLong = markdownFormatToShortKeyLong[format];
|
|
8
|
+
var shortKeyShort = markdownFormatToShortKeyShort[format];
|
|
9
|
+
var shortKey = shortKeyLong || shortKeyShort;
|
|
8
10
|
return (React.createElement(HintContentWrapper, null,
|
|
9
11
|
React.createElement("span", null, text),
|
|
10
|
-
!!shortKey && (
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
!!shortKey && renderHint()));
|
|
13
|
+
function renderHint() {
|
|
14
|
+
var ctrlKey = isMacintosh() ? '⌘' : 'CTRL';
|
|
15
|
+
var extraKey = shortKeyLong ? '+SHIFT' : '';
|
|
16
|
+
return (React.createElement("span", null,
|
|
17
|
+
ctrlKey,
|
|
18
|
+
extraKey,
|
|
13
19
|
"+",
|
|
14
|
-
|
|
20
|
+
shortKey));
|
|
21
|
+
}
|
|
15
22
|
};
|
|
@@ -4,7 +4,7 @@ import { MarkdownCombination } from './MarkdownCombination';
|
|
|
4
4
|
import { MarkdownButtonIcon, MarkdownButtonWrapper, VisuallyHidden } from '../Markdown.styled';
|
|
5
5
|
export var MarkdownFormatButton = function (_a) {
|
|
6
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:
|
|
7
|
+
return (React.createElement(Hint, { manual: disabled, text: format ? React.createElement(MarkdownCombination, { format: format, text: hintText }) : hintText, pos: "top center", maxWidth: 360 },
|
|
8
8
|
React.createElement(MarkdownButtonWrapper, { borderless: true, disabled: disabled, onClick: onClick },
|
|
9
9
|
React.createElement(MarkdownButtonIcon, null, icon),
|
|
10
10
|
React.createElement(VisuallyHidden, null, text))));
|
|
@@ -2,7 +2,7 @@ import { useEffect } from 'react';
|
|
|
2
2
|
import { getPastedHtml } from './markdownTextareaHelpers';
|
|
3
3
|
import { useFileLogic } from '../Files/Files.logic';
|
|
4
4
|
import { MarkdownFormat } from '../MarkdownFormat';
|
|
5
|
-
import { checkSpaceSymbol, eventKeyCodeToMarkdownFormat, markdownHelpFiles, markdownHelpItems, } from '../MarkdownHelpItems';
|
|
5
|
+
import { checkSpaceSymbol, eventKeyCodeToMarkdownFormat, markdownFormatToShortKeyLong, markdownHelpFiles, markdownHelpItems, } from '../MarkdownHelpItems';
|
|
6
6
|
var italic = MarkdownFormat.italic, bold = MarkdownFormat.bold, crossed = MarkdownFormat.crossed, codeBlock = MarkdownFormat.codeBlock, ref = MarkdownFormat.ref, file = MarkdownFormat.file, image = MarkdownFormat.image;
|
|
7
7
|
var betweenTextFormats = [italic, bold, crossed, codeBlock, file, image];
|
|
8
8
|
var specialFormats = [ref];
|
|
@@ -59,12 +59,12 @@ export function setTextareaCursor(format, prevCommentPartLength, nextCommentPart
|
|
|
59
59
|
}
|
|
60
60
|
export function createMarkdownHelpKeyDownHandler(text, ref, callback) {
|
|
61
61
|
return function (event) {
|
|
62
|
-
if (!(ref === null || ref === void 0 ? void 0 : ref.current))
|
|
62
|
+
if (!(ref === null || ref === void 0 ? void 0 : ref.current))
|
|
63
63
|
return;
|
|
64
|
-
}
|
|
65
64
|
var textareaNode = ref.current.node;
|
|
66
65
|
var format = eventKeyCodeToMarkdownFormat[event.keyCode];
|
|
67
|
-
|
|
66
|
+
var isLong = markdownFormatToShortKeyLong[format];
|
|
67
|
+
if ((event.metaKey || event.ctrlKey) && (isLong ? event.shiftKey : true) && format) {
|
|
68
68
|
var markdownHelpItem = markdownHelpItems.find(function (item) { return item.format === format; });
|
|
69
69
|
if (markdownHelpItem && textareaNode) {
|
|
70
70
|
event.stopPropagation();
|