@skbkontur/markdown 1.0.8 → 1.0.9
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skbkontur/markdown",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -46,6 +46,10 @@
|
|
|
46
46
|
"react-dom": ">=16.9"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"@babel/core": "7.18.0",
|
|
50
|
+
"@babel/plugin-syntax-jsx": "7.21.4",
|
|
51
|
+
"@babel/preset-env": "7.21.4",
|
|
52
|
+
"@babel/preset-typescript": "7.21.4",
|
|
49
53
|
"@skbkontur/react-ui": "^4.14.0",
|
|
50
54
|
"@skbkontur/react-ui-validations": "^1.12.0",
|
|
51
55
|
"@storybook/addon-a11y": "6.5.16",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
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
|
+
import { story, kind, test } from 'creevey';
|
|
38
|
+
kind('Markdown', function () {
|
|
39
|
+
story('WithActions', function (_a) {
|
|
40
|
+
var setStoryParameters = _a.setStoryParameters;
|
|
41
|
+
setStoryParameters({ skip: !!process.env.STORYBOOK_TEAMCITY_VERSION });
|
|
42
|
+
test('withPreview', function () {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
+
var buttons, idle, preview;
|
|
46
|
+
return __generator(this, function (_c) {
|
|
47
|
+
switch (_c.label) {
|
|
48
|
+
case 0: return [4 /*yield*/, this.browser.findElements({ css: 'button[class*="react-ui"]' })];
|
|
49
|
+
case 1:
|
|
50
|
+
buttons = _c.sent();
|
|
51
|
+
return [4 /*yield*/, ((_a = this.captureElement) === null || _a === void 0 ? void 0 : _a.takeScreenshot())];
|
|
52
|
+
case 2:
|
|
53
|
+
idle = _c.sent();
|
|
54
|
+
return [4 /*yield*/, this.browser
|
|
55
|
+
.actions()
|
|
56
|
+
.click(buttons[buttons.length - 2])
|
|
57
|
+
.perform()];
|
|
58
|
+
case 3:
|
|
59
|
+
_c.sent();
|
|
60
|
+
return [4 /*yield*/, ((_b = this.captureElement) === null || _b === void 0 ? void 0 : _b.takeScreenshot())];
|
|
61
|
+
case 4:
|
|
62
|
+
preview = _c.sent();
|
|
63
|
+
return [4 /*yield*/, this.expect({ idle: idle, preview: preview }).to.matchImages()];
|
|
64
|
+
case 5:
|
|
65
|
+
_c.sent();
|
|
66
|
+
return [2 /*return*/];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
story('Editable', function (_a) {
|
|
73
|
+
var setStoryParameters = _a.setStoryParameters;
|
|
74
|
+
setStoryParameters({ skip: !!process.env.STORYBOOK_TEAMCITY_VERSION });
|
|
75
|
+
test('markdownTests', function () {
|
|
76
|
+
var _a, _b, _c, _d, _e;
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var textarea, buttons, openedDropdown, newButtons, h1FromButton, h1FromKeyboard, boldFromButton, boldFromKeyboard;
|
|
79
|
+
return __generator(this, function (_f) {
|
|
80
|
+
switch (_f.label) {
|
|
81
|
+
case 0: return [4 /*yield*/, this.browser.findElement({ tagName: 'textarea' })];
|
|
82
|
+
case 1:
|
|
83
|
+
textarea = _f.sent();
|
|
84
|
+
return [4 /*yield*/, this.browser.findElements({ css: 'button[class*="react-ui"]' })];
|
|
85
|
+
case 2:
|
|
86
|
+
buttons = _f.sent();
|
|
87
|
+
return [4 /*yield*/, this.browser.actions().click(textarea).perform()];
|
|
88
|
+
case 3:
|
|
89
|
+
_f.sent();
|
|
90
|
+
return [4 /*yield*/, this.browser.actions().sendKeys('Заголовок').keyDown(this.keys.CONTROL).sendKeys('a').perform()];
|
|
91
|
+
case 4:
|
|
92
|
+
_f.sent();
|
|
93
|
+
return [4 /*yield*/, this.browser.actions().click(buttons[0]).perform()];
|
|
94
|
+
case 5:
|
|
95
|
+
_f.sent();
|
|
96
|
+
return [4 /*yield*/, ((_a = this.captureElement) === null || _a === void 0 ? void 0 : _a.takeScreenshot())];
|
|
97
|
+
case 6:
|
|
98
|
+
openedDropdown = _f.sent();
|
|
99
|
+
return [4 /*yield*/, this.browser.findElements({ css: 'button[class*="react-ui"]' })];
|
|
100
|
+
case 7:
|
|
101
|
+
newButtons = _f.sent();
|
|
102
|
+
return [4 /*yield*/, this.browser.actions().click(newButtons[1]).perform()];
|
|
103
|
+
case 8:
|
|
104
|
+
_f.sent();
|
|
105
|
+
return [4 /*yield*/, ((_b = this.captureElement) === null || _b === void 0 ? void 0 : _b.takeScreenshot())];
|
|
106
|
+
case 9:
|
|
107
|
+
h1FromButton = _f.sent();
|
|
108
|
+
return [4 /*yield*/, this.browser
|
|
109
|
+
.actions()
|
|
110
|
+
.keyDown(this.keys.CONTROL)
|
|
111
|
+
.sendKeys('a')
|
|
112
|
+
.sendKeys('Заголовок')
|
|
113
|
+
.keyDown(this.keys.CONTROL)
|
|
114
|
+
.sendKeys('a')
|
|
115
|
+
.keyDown(this.keys.CONTROL)
|
|
116
|
+
.keyDown(this.keys.ALT)
|
|
117
|
+
.sendKeys('1')
|
|
118
|
+
.perform()];
|
|
119
|
+
case 10:
|
|
120
|
+
_f.sent();
|
|
121
|
+
return [4 /*yield*/, ((_c = this.captureElement) === null || _c === void 0 ? void 0 : _c.takeScreenshot())];
|
|
122
|
+
case 11:
|
|
123
|
+
h1FromKeyboard = _f.sent();
|
|
124
|
+
return [4 /*yield*/, this.browser
|
|
125
|
+
.actions()
|
|
126
|
+
.keyDown(this.keys.CONTROL)
|
|
127
|
+
.sendKeys('a')
|
|
128
|
+
.sendKeys('Жирный')
|
|
129
|
+
.keyDown(this.keys.CONTROL)
|
|
130
|
+
.sendKeys('a')
|
|
131
|
+
.click(buttons[1])
|
|
132
|
+
.perform()];
|
|
133
|
+
case 12:
|
|
134
|
+
_f.sent();
|
|
135
|
+
return [4 /*yield*/, ((_d = this.captureElement) === null || _d === void 0 ? void 0 : _d.takeScreenshot())];
|
|
136
|
+
case 13:
|
|
137
|
+
boldFromButton = _f.sent();
|
|
138
|
+
return [4 /*yield*/, this.browser
|
|
139
|
+
.actions()
|
|
140
|
+
.keyDown(this.keys.CONTROL)
|
|
141
|
+
.sendKeys('a')
|
|
142
|
+
.sendKeys('Жирный')
|
|
143
|
+
.keyDown(this.keys.CONTROL)
|
|
144
|
+
.sendKeys('a')
|
|
145
|
+
.keyDown(this.keys.CONTROL)
|
|
146
|
+
.keyDown(this.keys.ALT)
|
|
147
|
+
.sendKeys('b')
|
|
148
|
+
.perform()];
|
|
149
|
+
case 14:
|
|
150
|
+
_f.sent();
|
|
151
|
+
return [4 /*yield*/, ((_e = this.captureElement) === null || _e === void 0 ? void 0 : _e.takeScreenshot())];
|
|
152
|
+
case 15:
|
|
153
|
+
boldFromKeyboard = _f.sent();
|
|
154
|
+
return [4 /*yield*/, this.expect({
|
|
155
|
+
openedDropdown: openedDropdown,
|
|
156
|
+
h1FromButton: h1FromButton,
|
|
157
|
+
h1FromKeyboard: h1FromKeyboard,
|
|
158
|
+
boldFromButton: boldFromButton,
|
|
159
|
+
boldFromKeyboard: boldFromKeyboard,
|
|
160
|
+
}).to.matchImages()];
|
|
161
|
+
case 16:
|
|
162
|
+
_f.sent();
|
|
163
|
+
return [2 /*return*/];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -12,8 +12,13 @@ export interface MarkdownHelpItem {
|
|
|
12
12
|
node: ReactNode;
|
|
13
13
|
text: string;
|
|
14
14
|
wrapContent: (content: string) => string;
|
|
15
|
+
checkLength?: number;
|
|
15
16
|
icon?: ReactNode;
|
|
16
17
|
}
|
|
18
|
+
export declare function checkSpaceSymbol(text: string, checkedLength?: number): {
|
|
19
|
+
value: string;
|
|
20
|
+
spaces: string;
|
|
21
|
+
};
|
|
17
22
|
export declare const markdownHelpHeaders: MarkdownHelpItem[];
|
|
18
23
|
export declare const markdownHelpText: MarkdownHelpItem[];
|
|
19
24
|
export declare const markdownHelpLists: MarkdownHelpItem[];
|
|
@@ -18,6 +18,8 @@ import { List } from '../MarkdownIcons/List';
|
|
|
18
18
|
import { NumberedList } from '../MarkdownIcons/NumberedList';
|
|
19
19
|
import { Table } from '../MarkdownIcons/Table';
|
|
20
20
|
var newLinesRegexp = /([\n\r]+)/g;
|
|
21
|
+
var spacesMatchRegexp = /\s/gm;
|
|
22
|
+
var spacesSplitRegexp = /(\s+)/;
|
|
21
23
|
export var eventKeyCodeToMarkdownFormat = {
|
|
22
24
|
50: MarkdownFormat.h2,
|
|
23
25
|
51: MarkdownFormat.h3,
|
|
@@ -48,6 +50,18 @@ export var markdownFormatToShortKey = (_a = {},
|
|
|
48
50
|
_a[MarkdownFormat.quote] = 'Q',
|
|
49
51
|
_a[MarkdownFormat.image] = 'P',
|
|
50
52
|
_a);
|
|
53
|
+
export function checkSpaceSymbol(text, checkedLength) {
|
|
54
|
+
var latestSymbolPos = text.length - 1;
|
|
55
|
+
var latestSymbol = text.charAt(latestSymbolPos);
|
|
56
|
+
if (latestSymbol.match(spacesMatchRegexp) && checkedLength) {
|
|
57
|
+
var substringText = text.split('').reverse().join('').split(spacesSplitRegexp);
|
|
58
|
+
var spaces = substringText[1];
|
|
59
|
+
var textWithoutSpaces = substringText[2];
|
|
60
|
+
var reversed = textWithoutSpaces.split('').reverse().join('');
|
|
61
|
+
return { value: reversed, spaces: spaces };
|
|
62
|
+
}
|
|
63
|
+
return { value: text, spaces: '' };
|
|
64
|
+
}
|
|
51
65
|
export var markdownHelpHeaders = [
|
|
52
66
|
{
|
|
53
67
|
format: MarkdownFormat.h2,
|
|
@@ -84,6 +98,7 @@ export var markdownHelpText = [
|
|
|
84
98
|
icon: React.createElement("strong", null, "B"),
|
|
85
99
|
wrapContent: function (content) { return "**".concat(content, "**"); },
|
|
86
100
|
text: 'Жирный',
|
|
101
|
+
checkLength: 2,
|
|
87
102
|
},
|
|
88
103
|
{
|
|
89
104
|
format: MarkdownFormat.italic,
|
|
@@ -94,6 +109,7 @@ export var markdownHelpText = [
|
|
|
94
109
|
icon: React.createElement("i", null, "I"),
|
|
95
110
|
wrapContent: function (content) { return "*".concat(content, "*"); },
|
|
96
111
|
text: 'Курсив',
|
|
112
|
+
checkLength: 1,
|
|
97
113
|
},
|
|
98
114
|
{
|
|
99
115
|
format: MarkdownFormat.crossed,
|
|
@@ -106,6 +122,7 @@ export var markdownHelpText = [
|
|
|
106
122
|
} }, "S")),
|
|
107
123
|
wrapContent: function (content) { return "~~".concat(content, "~~"); },
|
|
108
124
|
text: 'Зачеркнутый',
|
|
125
|
+
checkLength: 2,
|
|
109
126
|
},
|
|
110
127
|
{
|
|
111
128
|
format: MarkdownFormat.ref,
|
|
@@ -119,6 +136,7 @@ export var markdownHelpText = [
|
|
|
119
136
|
icon: React.createElement(AttachLink, null),
|
|
120
137
|
wrapContent: function (content) { return "[".concat(content, "]()"); },
|
|
121
138
|
text: 'Ссылка',
|
|
139
|
+
checkLength: 1,
|
|
122
140
|
},
|
|
123
141
|
];
|
|
124
142
|
export var markdownHelpLists = [
|
|
@@ -160,6 +178,7 @@ export var markdownHelpOther = [
|
|
|
160
178
|
icon: React.createElement("span", null, '</>'),
|
|
161
179
|
wrapContent: function (content) { return "`".concat(content, "`"); },
|
|
162
180
|
text: 'Блок кода',
|
|
181
|
+
checkLength: 1,
|
|
163
182
|
},
|
|
164
183
|
{
|
|
165
184
|
format: MarkdownFormat.quote,
|
|
@@ -2,17 +2,19 @@ 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 { eventKeyCodeToMarkdownFormat, markdownHelpFiles, markdownHelpItems } from '../MarkdownHelpItems';
|
|
5
|
+
import { checkSpaceSymbol, eventKeyCodeToMarkdownFormat, 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];
|
|
9
9
|
export function setMarkdown(textareaNode, text, format, selectionStart, selectionEnd) {
|
|
10
|
+
var _a;
|
|
10
11
|
var markdownHelpItem = markdownHelpItems.find(function (item) { return item.format === format; });
|
|
11
12
|
if (markdownHelpItem) {
|
|
12
13
|
var prevCommentPart = text.substring(selectionStart, selectionEnd !== null && selectionEnd !== void 0 ? selectionEnd : undefined);
|
|
13
|
-
var
|
|
14
|
+
var _b = checkSpaceSymbol(prevCommentPart, markdownHelpItem.checkLength), value = _b.value, spaces = _b.spaces;
|
|
15
|
+
var nextCommentPart = markdownHelpItem.wrapContent(value) + spaces;
|
|
14
16
|
document.execCommand('insertText', false, nextCommentPart);
|
|
15
|
-
setTextareaCursor(format, prevCommentPart.length, nextCommentPart.length, textareaNode, Number(selectionEnd));
|
|
17
|
+
setTextareaCursor(format, prevCommentPart.length, nextCommentPart.length, textareaNode, Number(selectionEnd) + ((_a = markdownHelpItem === null || markdownHelpItem === void 0 ? void 0 : markdownHelpItem.checkLength) !== null && _a !== void 0 ? _a : 0));
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
export function setMarkdownFiles(file, textarea, format, cursorPosition, fileApiUrl) {
|