@gravity-ui/markdown-editor 14.4.0 → 14.5.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/build/cjs/bundle/Editor.js +1 -0
- package/build/cjs/bundle/config/markup.d.ts +41 -17
- package/build/cjs/bundle/config/markup.js +413 -308
- package/build/cjs/bundle/config/wysiwyg.d.ts +29 -18
- package/build/cjs/bundle/config/wysiwyg.js +526 -310
- package/build/cjs/bundle/sticky/sticky.css +1 -1
- package/build/cjs/bundle/types.d.ts +2 -0
- package/build/cjs/extensions/behavior/Clipboard/utils.d.ts +1 -0
- package/build/cjs/extensions/behavior/Clipboard/utils.js +1 -0
- package/build/cjs/extensions/markdown/CodeBlock/handle-paste.js +5 -17
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/const.d.ts +12 -0
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/const.js +21 -2
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/index.d.ts +8 -1
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/index.js +29 -5
- package/build/cjs/markup/codemirror/create.d.ts +1 -0
- package/build/cjs/markup/codemirror/create.js +41 -4
- package/build/cjs/markup/codemirror/html-to-markdown/converters.d.ts +111 -0
- package/build/cjs/markup/codemirror/html-to-markdown/converters.js +214 -0
- package/build/cjs/markup/codemirror/html-to-markdown/handlers.d.ts +104 -0
- package/build/cjs/markup/codemirror/html-to-markdown/handlers.js +233 -0
- package/build/cjs/markup/codemirror/html-to-markdown/helpers.d.ts +1 -0
- package/build/cjs/markup/codemirror/html-to-markdown/helpers.js +21 -0
- package/build/cjs/markup/commands/inline.js +18 -8
- package/build/cjs/utils/clipboard.d.ts +14 -0
- package/build/cjs/utils/clipboard.js +36 -1
- package/build/cjs/version.js +1 -1
- package/build/esm/bundle/Editor.js +1 -0
- package/build/esm/bundle/config/markup.d.ts +41 -17
- package/build/esm/bundle/config/markup.js +411 -307
- package/build/esm/bundle/config/wysiwyg.d.ts +29 -18
- package/build/esm/bundle/config/wysiwyg.js +499 -284
- package/build/esm/bundle/sticky/sticky.css +1 -1
- package/build/esm/bundle/types.d.ts +2 -0
- package/build/esm/extensions/behavior/Clipboard/utils.d.ts +1 -0
- package/build/esm/extensions/behavior/Clipboard/utils.js +1 -0
- package/build/esm/extensions/markdown/CodeBlock/handle-paste.js +2 -14
- package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/const.d.ts +12 -0
- package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/const.js +21 -2
- package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/index.d.ts +8 -1
- package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/index.js +29 -6
- package/build/esm/markup/codemirror/create.d.ts +1 -0
- package/build/esm/markup/codemirror/create.js +40 -3
- package/build/esm/markup/codemirror/html-to-markdown/converters.d.ts +111 -0
- package/build/esm/markup/codemirror/html-to-markdown/converters.js +210 -0
- package/build/esm/markup/codemirror/html-to-markdown/handlers.d.ts +104 -0
- package/build/esm/markup/codemirror/html-to-markdown/handlers.js +215 -0
- package/build/esm/markup/codemirror/html-to-markdown/helpers.d.ts +1 -0
- package/build/esm/markup/codemirror/html-to-markdown/helpers.js +17 -0
- package/build/esm/markup/commands/inline.js +18 -8
- package/build/esm/utils/clipboard.d.ts +14 -0
- package/build/esm/utils/clipboard.js +32 -0
- package/build/esm/version.js +1 -1
- package/build/styles.css +1 -1
- package/package.json +9 -7
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { HTMLNodeVisitor } from './converters';
|
|
2
|
+
/**
|
|
3
|
+
* Base handler class implementing the Chain of Responsibility pattern for HTML node processing.
|
|
4
|
+
* Each concrete handler decides whether it can process a node or should pass it to the next handler.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class NodeHandler {
|
|
7
|
+
protected next: NodeHandler | null;
|
|
8
|
+
/**
|
|
9
|
+
* Sets up the next handler in the chain
|
|
10
|
+
*/
|
|
11
|
+
setNext(handler: NodeHandler): NodeHandler;
|
|
12
|
+
/**
|
|
13
|
+
* Process the given node or delegate to the next handler
|
|
14
|
+
*/
|
|
15
|
+
abstract handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
16
|
+
/**
|
|
17
|
+
* Delegates processing to the next handler in the chain
|
|
18
|
+
*/
|
|
19
|
+
protected handleNext(node: Node, visitor: HTMLNodeVisitor): string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Handles text nodes, converting them to markdown text
|
|
23
|
+
*/
|
|
24
|
+
export declare class TextNodeHandler extends NodeHandler {
|
|
25
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Handles anchor elements, converting them to markdown links
|
|
29
|
+
*/
|
|
30
|
+
export declare class LinkHandler extends NodeHandler {
|
|
31
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Handles header elements (h1-h6), converting them to markdown headers
|
|
35
|
+
*/
|
|
36
|
+
export declare class HeaderHandler extends NodeHandler {
|
|
37
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Handles paragraph elements, converting them to markdown paragraphs
|
|
41
|
+
*/
|
|
42
|
+
export declare class ParagraphHandler extends NodeHandler {
|
|
43
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Handles text formatting elements (b, strong, i, em), converting them to markdown formatting
|
|
47
|
+
*/
|
|
48
|
+
export declare class FormattingHandler extends NodeHandler {
|
|
49
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Handles code elements, converting them to markdown code blocks or inline code
|
|
53
|
+
*/
|
|
54
|
+
export declare class CodeHandler extends NodeHandler {
|
|
55
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Fallback handler for any HTML elements not handled by other specific handlers
|
|
59
|
+
*/
|
|
60
|
+
export declare class GenericHandler extends NodeHandler {
|
|
61
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Handles ordered list elements, converting them to markdown ordered lists
|
|
65
|
+
*/
|
|
66
|
+
export declare class OrderedListHandler extends NodeHandler {
|
|
67
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Handles unordered list elements, converting them to markdown unordered lists
|
|
71
|
+
*/
|
|
72
|
+
export declare class UnorderedListHandler extends NodeHandler {
|
|
73
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Handles div elements, converting them to markdown paragraphs
|
|
77
|
+
*/
|
|
78
|
+
export declare class DivHandler extends NodeHandler {
|
|
79
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Handles br elements, converting them to markdown newlines
|
|
83
|
+
*/
|
|
84
|
+
export declare class BrHandler extends NodeHandler {
|
|
85
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Handles table row elements, converting them to markdown table rows
|
|
89
|
+
*/
|
|
90
|
+
export declare class TableRowHandler extends NodeHandler {
|
|
91
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Handles table elements, converting them to markdown tables
|
|
95
|
+
*/
|
|
96
|
+
export declare class TableHandler extends NodeHandler {
|
|
97
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Handles image elements, converting them to markdown images
|
|
101
|
+
*/
|
|
102
|
+
export declare class ImageHandler extends NodeHandler {
|
|
103
|
+
handle(node: Node, visitor: HTMLNodeVisitor): string;
|
|
104
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImageHandler = exports.TableHandler = exports.TableRowHandler = exports.BrHandler = exports.DivHandler = exports.UnorderedListHandler = exports.OrderedListHandler = exports.GenericHandler = exports.CodeHandler = exports.FormattingHandler = exports.ParagraphHandler = exports.HeaderHandler = exports.LinkHandler = exports.TextNodeHandler = exports.NodeHandler = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base handler class implementing the Chain of Responsibility pattern for HTML node processing.
|
|
6
|
+
* Each concrete handler decides whether it can process a node or should pass it to the next handler.
|
|
7
|
+
*/
|
|
8
|
+
class NodeHandler {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.next = null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Sets up the next handler in the chain
|
|
14
|
+
*/
|
|
15
|
+
setNext(handler) {
|
|
16
|
+
this.next = handler;
|
|
17
|
+
return handler;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Delegates processing to the next handler in the chain
|
|
21
|
+
*/
|
|
22
|
+
handleNext(node, visitor) {
|
|
23
|
+
if (this.next) {
|
|
24
|
+
return this.next.handle(node, visitor);
|
|
25
|
+
}
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.NodeHandler = NodeHandler;
|
|
30
|
+
/**
|
|
31
|
+
* Handles text nodes, converting them to markdown text
|
|
32
|
+
*/
|
|
33
|
+
class TextNodeHandler extends NodeHandler {
|
|
34
|
+
handle(node, visitor) {
|
|
35
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
36
|
+
return visitor.visitText(node);
|
|
37
|
+
}
|
|
38
|
+
return this.handleNext(node, visitor);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.TextNodeHandler = TextNodeHandler;
|
|
42
|
+
/**
|
|
43
|
+
* Handles anchor elements, converting them to markdown links
|
|
44
|
+
*/
|
|
45
|
+
class LinkHandler extends NodeHandler {
|
|
46
|
+
handle(node, visitor) {
|
|
47
|
+
if (node.nodeType === Node.ELEMENT_NODE &&
|
|
48
|
+
node.tagName.toLowerCase() === 'a') {
|
|
49
|
+
return visitor.visitLink(node);
|
|
50
|
+
}
|
|
51
|
+
return this.handleNext(node, visitor);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.LinkHandler = LinkHandler;
|
|
55
|
+
/**
|
|
56
|
+
* Handles header elements (h1-h6), converting them to markdown headers
|
|
57
|
+
*/
|
|
58
|
+
class HeaderHandler extends NodeHandler {
|
|
59
|
+
handle(node, visitor) {
|
|
60
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
61
|
+
return this.handleNext(node, visitor);
|
|
62
|
+
}
|
|
63
|
+
const tagName = node.tagName.toLowerCase();
|
|
64
|
+
const headerMatch = tagName.match(/^h([1-6])$/);
|
|
65
|
+
if (headerMatch) {
|
|
66
|
+
const headerLevel = parseInt(headerMatch[1], 10);
|
|
67
|
+
return visitor.visitHeader(node, headerLevel);
|
|
68
|
+
}
|
|
69
|
+
return this.handleNext(node, visitor);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.HeaderHandler = HeaderHandler;
|
|
73
|
+
/**
|
|
74
|
+
* Handles paragraph elements, converting them to markdown paragraphs
|
|
75
|
+
*/
|
|
76
|
+
class ParagraphHandler extends NodeHandler {
|
|
77
|
+
handle(node, visitor) {
|
|
78
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
79
|
+
return this.handleNext(node, visitor);
|
|
80
|
+
}
|
|
81
|
+
if (node.tagName.toLowerCase() === 'p') {
|
|
82
|
+
return visitor.visitParagraph(node);
|
|
83
|
+
}
|
|
84
|
+
return this.handleNext(node, visitor);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.ParagraphHandler = ParagraphHandler;
|
|
88
|
+
/**
|
|
89
|
+
* Handles text formatting elements (b, strong, i, em), converting them to markdown formatting
|
|
90
|
+
*/
|
|
91
|
+
class FormattingHandler extends NodeHandler {
|
|
92
|
+
handle(node, visitor) {
|
|
93
|
+
var _a;
|
|
94
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
95
|
+
return this.handleNext(node, visitor);
|
|
96
|
+
}
|
|
97
|
+
const element = node;
|
|
98
|
+
const tagName = element.tagName.toLowerCase();
|
|
99
|
+
const formattingTags = ['b', 'strong', 'i', 'em', 'span'];
|
|
100
|
+
if (formattingTags.includes(tagName) &&
|
|
101
|
+
!['a', 'code', 'pre'].includes(((_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase()) || '')) {
|
|
102
|
+
return visitor.visitFormatting(element);
|
|
103
|
+
}
|
|
104
|
+
return this.handleNext(node, visitor);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.FormattingHandler = FormattingHandler;
|
|
108
|
+
/**
|
|
109
|
+
* Handles code elements, converting them to markdown code blocks or inline code
|
|
110
|
+
*/
|
|
111
|
+
class CodeHandler extends NodeHandler {
|
|
112
|
+
handle(node, visitor) {
|
|
113
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
114
|
+
return this.handleNext(node, visitor);
|
|
115
|
+
}
|
|
116
|
+
if (node.tagName.toLowerCase() === 'code' ||
|
|
117
|
+
node.tagName.toLowerCase() === 'pre') {
|
|
118
|
+
return visitor.visitCode(node);
|
|
119
|
+
}
|
|
120
|
+
return this.handleNext(node, visitor);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.CodeHandler = CodeHandler;
|
|
124
|
+
/**
|
|
125
|
+
* Fallback handler for any HTML elements not handled by other specific handlers
|
|
126
|
+
*/
|
|
127
|
+
class GenericHandler extends NodeHandler {
|
|
128
|
+
handle(node, visitor) {
|
|
129
|
+
return visitor.visitGeneric(node);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.GenericHandler = GenericHandler;
|
|
133
|
+
/**
|
|
134
|
+
* Handles ordered list elements, converting them to markdown ordered lists
|
|
135
|
+
*/
|
|
136
|
+
class OrderedListHandler extends NodeHandler {
|
|
137
|
+
handle(node, visitor) {
|
|
138
|
+
if (node.nodeType === Node.ELEMENT_NODE &&
|
|
139
|
+
node.tagName.toLowerCase() === 'ol') {
|
|
140
|
+
const items = Array.from(node.childNodes)
|
|
141
|
+
.filter((child) => child.nodeType === Node.ELEMENT_NODE &&
|
|
142
|
+
child.tagName.toLowerCase() === 'li')
|
|
143
|
+
.map((item, index) => `${index + 1}. ${visitor.visitGeneric(item)}`)
|
|
144
|
+
.join('\n');
|
|
145
|
+
return items + '\n';
|
|
146
|
+
}
|
|
147
|
+
return this.handleNext(node, visitor);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.OrderedListHandler = OrderedListHandler;
|
|
151
|
+
/**
|
|
152
|
+
* Handles unordered list elements, converting them to markdown unordered lists
|
|
153
|
+
*/
|
|
154
|
+
class UnorderedListHandler extends NodeHandler {
|
|
155
|
+
handle(node, visitor) {
|
|
156
|
+
if (node.nodeType === Node.ELEMENT_NODE &&
|
|
157
|
+
node.tagName.toLowerCase() === 'ul') {
|
|
158
|
+
const items = Array.from(node.childNodes)
|
|
159
|
+
.filter((child) => child.nodeType === Node.ELEMENT_NODE &&
|
|
160
|
+
child.tagName.toLowerCase() === 'li')
|
|
161
|
+
.map((item) => `- ${visitor.visitGeneric(item)}`)
|
|
162
|
+
.join('\n');
|
|
163
|
+
return items + '\n';
|
|
164
|
+
}
|
|
165
|
+
return this.handleNext(node, visitor);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.UnorderedListHandler = UnorderedListHandler;
|
|
169
|
+
/**
|
|
170
|
+
* Handles div elements, converting them to markdown paragraphs
|
|
171
|
+
*/
|
|
172
|
+
class DivHandler extends NodeHandler {
|
|
173
|
+
handle(node, visitor) {
|
|
174
|
+
if (node.nodeType === Node.ELEMENT_NODE &&
|
|
175
|
+
node.tagName.toLowerCase() === 'div') {
|
|
176
|
+
return visitor.visitDiv(node);
|
|
177
|
+
}
|
|
178
|
+
return this.handleNext(node, visitor);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.DivHandler = DivHandler;
|
|
182
|
+
/**
|
|
183
|
+
* Handles br elements, converting them to markdown newlines
|
|
184
|
+
*/
|
|
185
|
+
class BrHandler extends NodeHandler {
|
|
186
|
+
handle(node, visitor) {
|
|
187
|
+
if (node.nodeType === Node.ELEMENT_NODE &&
|
|
188
|
+
node.tagName.toLowerCase() === 'br') {
|
|
189
|
+
return visitor.visitBr();
|
|
190
|
+
}
|
|
191
|
+
return this.handleNext(node, visitor);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.BrHandler = BrHandler;
|
|
195
|
+
/**
|
|
196
|
+
* Handles table row elements, converting them to markdown table rows
|
|
197
|
+
*/
|
|
198
|
+
class TableRowHandler extends NodeHandler {
|
|
199
|
+
handle(node, visitor) {
|
|
200
|
+
if (node.nodeType === Node.ELEMENT_NODE &&
|
|
201
|
+
node.tagName.toLowerCase() === 'tr') {
|
|
202
|
+
return visitor.visitTableRow(node);
|
|
203
|
+
}
|
|
204
|
+
return this.handleNext(node, visitor);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.TableRowHandler = TableRowHandler;
|
|
208
|
+
/**
|
|
209
|
+
* Handles table elements, converting them to markdown tables
|
|
210
|
+
*/
|
|
211
|
+
class TableHandler extends NodeHandler {
|
|
212
|
+
handle(node, visitor) {
|
|
213
|
+
if (node.nodeType === Node.ELEMENT_NODE &&
|
|
214
|
+
node.tagName.toLowerCase() === 'table') {
|
|
215
|
+
return visitor.visitTable(node);
|
|
216
|
+
}
|
|
217
|
+
return this.handleNext(node, visitor);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.TableHandler = TableHandler;
|
|
221
|
+
/**
|
|
222
|
+
* Handles image elements, converting them to markdown images
|
|
223
|
+
*/
|
|
224
|
+
class ImageHandler extends NodeHandler {
|
|
225
|
+
handle(node, visitor) {
|
|
226
|
+
if (node.nodeType === Node.ELEMENT_NODE &&
|
|
227
|
+
node.tagName.toLowerCase() === 'img') {
|
|
228
|
+
return visitor.visitImage(node);
|
|
229
|
+
}
|
|
230
|
+
return this.handleNext(node, visitor);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.ImageHandler = ImageHandler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function applyFormatting(text: string, element: HTMLElement): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyFormatting = void 0;
|
|
4
|
+
function applyFormatting(text, element) {
|
|
5
|
+
// Check for italic formatting (either through tags or CSS)
|
|
6
|
+
const hasItalic = element.tagName.toLowerCase() === 'i' ||
|
|
7
|
+
element.tagName.toLowerCase() === 'em' ||
|
|
8
|
+
element.style.fontStyle === 'italic';
|
|
9
|
+
// Check for bold formatting (either through tags or CSS font-weight)
|
|
10
|
+
const hasBold = element.tagName.toLowerCase() === 'b' ||
|
|
11
|
+
element.tagName.toLowerCase() === 'strong' ||
|
|
12
|
+
parseInt(element.style.fontWeight, 10) >= 600;
|
|
13
|
+
// Apply markdown formatting in specific order
|
|
14
|
+
let formatted = text;
|
|
15
|
+
if (hasItalic)
|
|
16
|
+
formatted = `*${formatted}*`; // Wrap in single asterisks for italic
|
|
17
|
+
if (hasBold)
|
|
18
|
+
formatted = `**${formatted}**`; // Wrap in double asterisks for bold
|
|
19
|
+
return formatted;
|
|
20
|
+
}
|
|
21
|
+
exports.applyFormatting = applyFormatting;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.insertFiles = exports.insertImages = exports.insertAnchor = exports.insertLink = void 0;
|
|
4
4
|
const autocomplete_1 = require("@codemirror/autocomplete");
|
|
5
|
+
const codemirror_1 = require("../codemirror");
|
|
5
6
|
const defaultLinkSnippet = (0, autocomplete_1.snippet)(`[#{2:link}](#{1:url} "#{3:title}")`);
|
|
6
7
|
const insertLink = ({ state, dispatch }) => {
|
|
7
8
|
const { from, to, empty } = state.selection.main;
|
|
@@ -47,16 +48,25 @@ function insertImages(images) {
|
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
exports.insertImages = insertImages;
|
|
51
|
+
const fileToCurlySyntax = (file) => {
|
|
52
|
+
const attrsStr = Object.entries(file)
|
|
53
|
+
.map(([key, value]) => `${key}="${value.replace('"', '')}"`)
|
|
54
|
+
.join(' ');
|
|
55
|
+
return `{% file ${attrsStr} %}`;
|
|
56
|
+
};
|
|
57
|
+
const fileToDirectiveSyntax = (file) => {
|
|
58
|
+
const { src, name, type } = file;
|
|
59
|
+
let markup = `:file[${name}](${src})`;
|
|
60
|
+
if (type)
|
|
61
|
+
markup += `{type="${type}"}`;
|
|
62
|
+
return markup;
|
|
63
|
+
};
|
|
50
64
|
const insertFiles = (files) => {
|
|
51
65
|
return ({ state, dispatch }) => {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
.join(' ');
|
|
57
|
-
return `{% file ${attrsStr} %}`;
|
|
58
|
-
})
|
|
59
|
-
.join(' ');
|
|
66
|
+
const serializer = state.facet(codemirror_1.DirectiveSyntaxFacet).shouldInsertDirectiveMarkup('yfmFile')
|
|
67
|
+
? fileToDirectiveSyntax
|
|
68
|
+
: fileToCurlySyntax;
|
|
69
|
+
const markup = files.map(serializer).join(' ');
|
|
60
70
|
const tr = state.changeByRange((range) => {
|
|
61
71
|
const changes = state.changes({ from: range.from, to: range.to, insert: markup });
|
|
62
72
|
return { changes, range: range.map(changes) };
|
|
@@ -3,6 +3,7 @@ export declare enum DataTransferType {
|
|
|
3
3
|
Text = "text/plain",
|
|
4
4
|
Html = "text/html",
|
|
5
5
|
Yfm = "text/yfm",
|
|
6
|
+
Rtf = "text/rtf",
|
|
6
7
|
UriList = "text/uri-list",
|
|
7
8
|
VSCodeData = "vscode-editor-data",
|
|
8
9
|
Files = "Files"
|
|
@@ -10,3 +11,16 @@ export declare enum DataTransferType {
|
|
|
10
11
|
export declare function isFilesOnly({ types }: DataTransfer): boolean;
|
|
11
12
|
export declare function isFilesFromHtml({ types }: DataTransfer): boolean;
|
|
12
13
|
export declare function isImageFile(file: File): boolean;
|
|
14
|
+
export declare function isVSCode(data: DataTransfer): boolean;
|
|
15
|
+
export declare type VSCodeData = {
|
|
16
|
+
version: number;
|
|
17
|
+
isFromEmptySelection: boolean;
|
|
18
|
+
multicursorText: null | string;
|
|
19
|
+
mode: string;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
};
|
|
22
|
+
export declare function tryParseVSCodeData(data: DataTransfer): VSCodeData | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if HTML conversion should be skipped based on clipboard contents.
|
|
25
|
+
*/
|
|
26
|
+
export declare function shouldSkipHtmlConversion(clipboardData: DataTransfer): boolean;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isImageFile = exports.isFilesFromHtml = exports.isFilesOnly = exports.DataTransferType = void 0;
|
|
3
|
+
exports.shouldSkipHtmlConversion = exports.tryParseVSCodeData = exports.isVSCode = exports.isImageFile = exports.isFilesFromHtml = exports.isFilesOnly = exports.DataTransferType = void 0;
|
|
4
4
|
/** Сontains all data formats known to us */
|
|
5
5
|
var DataTransferType;
|
|
6
6
|
(function (DataTransferType) {
|
|
7
7
|
DataTransferType["Text"] = "text/plain";
|
|
8
8
|
DataTransferType["Html"] = "text/html";
|
|
9
9
|
DataTransferType["Yfm"] = "text/yfm";
|
|
10
|
+
DataTransferType["Rtf"] = "text/rtf";
|
|
10
11
|
DataTransferType["UriList"] = "text/uri-list";
|
|
11
12
|
DataTransferType["VSCodeData"] = "vscode-editor-data";
|
|
12
13
|
DataTransferType["Files"] = "Files";
|
|
@@ -25,3 +26,37 @@ function isImageFile(file) {
|
|
|
25
26
|
return file.type.startsWith('image/');
|
|
26
27
|
}
|
|
27
28
|
exports.isImageFile = isImageFile;
|
|
29
|
+
function isVSCode(data) {
|
|
30
|
+
return data.types.includes(DataTransferType.VSCodeData);
|
|
31
|
+
}
|
|
32
|
+
exports.isVSCode = isVSCode;
|
|
33
|
+
function tryParseVSCodeData(data) {
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(data.getData(DataTransferType.VSCodeData));
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
console.error(e);
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.tryParseVSCodeData = tryParseVSCodeData;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if HTML conversion should be skipped based on clipboard contents.
|
|
45
|
+
*/
|
|
46
|
+
function shouldSkipHtmlConversion(clipboardData) {
|
|
47
|
+
const hasHtml = clipboardData.types.includes(DataTransferType.Html);
|
|
48
|
+
// If there's no HTML content, skip conversion
|
|
49
|
+
if (!hasHtml)
|
|
50
|
+
return true;
|
|
51
|
+
// Check for standard HTML clipboard (text/plain + text/html)
|
|
52
|
+
if (clipboardData.types.length === 2)
|
|
53
|
+
return false;
|
|
54
|
+
// Check for WebStorm/Safari case (includes RTF)
|
|
55
|
+
if (clipboardData.types.length === 3) {
|
|
56
|
+
const rtf = clipboardData.getData(DataTransferType.Rtf);
|
|
57
|
+
return rtf.indexOf('\fmodern JetBrains') > 0;
|
|
58
|
+
}
|
|
59
|
+
// Skip conversion for any other cases
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
exports.shouldSkipHtmlConversion = shouldSkipHtmlConversion;
|
package/build/cjs/version.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
/** During build process, the current version will be injected here */
|
|
5
|
-
exports.VERSION = typeof '14.
|
|
5
|
+
exports.VERSION = typeof '14.5.0' !== 'undefined' ? '14.5.0' : 'unknown';
|
|
@@ -168,6 +168,7 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
168
168
|
uploadHandler: this.fileUploadHandler,
|
|
169
169
|
parseInsertedUrlAsImage: this.parseInsertedUrlAsImage,
|
|
170
170
|
needImageDimensions: this.needToSetDimensionsForUploadedImages,
|
|
171
|
+
parseHtmlOnPaste: __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").parseHtmlOnPaste,
|
|
171
172
|
enableNewImageSizeCalculation: this.enableNewImageSizeCalculation,
|
|
172
173
|
extensions: __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").extensions,
|
|
173
174
|
disabledExtensions: __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").disabledExtensions,
|
|
@@ -2,7 +2,7 @@ import { CodeEditor } from '../../markup/editor';
|
|
|
2
2
|
import { ToolbarData } from '../../toolbar/Toolbar';
|
|
3
3
|
import { ToolbarGroupData } from '../../toolbar/ToolbarGroup';
|
|
4
4
|
import { ToolbarListButtonData } from '../../toolbar/ToolbarListButton';
|
|
5
|
-
import { ToolbarButtonPopupData, ToolbarItemData, ToolbarListItemData, ToolbarReactComponentData, ToolbarSingleItemData } from '../../toolbar/types';
|
|
5
|
+
import { ToolbarButtonPopupData, ToolbarItemData, ToolbarListButtonItemData, ToolbarListItemData, ToolbarReactComponentData, ToolbarSingleItemData } from '../../toolbar/types';
|
|
6
6
|
import type { MarkdownEditorPreset } from '../types';
|
|
7
7
|
export declare type MToolbarData = ToolbarData<CodeEditor>;
|
|
8
8
|
export declare type MToolbarItemData = ToolbarItemData<CodeEditor>;
|
|
@@ -12,37 +12,61 @@ export declare type MToolbarReactComponentData = ToolbarReactComponentData<CodeE
|
|
|
12
12
|
export declare type MToolbarListButtonData = ToolbarListButtonData<CodeEditor>;
|
|
13
13
|
export declare type MToolbarListItemData = ToolbarListItemData<CodeEditor>;
|
|
14
14
|
export declare type MToolbarButtonPopupData = ToolbarButtonPopupData<CodeEditor>;
|
|
15
|
-
export declare const
|
|
16
|
-
|
|
15
|
+
export declare const mUndoItemData: MToolbarSingleItemData;
|
|
16
|
+
export declare const mRedoItemData: MToolbarSingleItemData;
|
|
17
17
|
export declare const mBoldItemData: MToolbarSingleItemData;
|
|
18
18
|
export declare const mItalicItemData: MToolbarSingleItemData;
|
|
19
19
|
export declare const mUnderlineItemData: MToolbarSingleItemData;
|
|
20
20
|
export declare const mStrikethroughItemData: MToolbarSingleItemData;
|
|
21
21
|
export declare const mMonospaceItemData: MToolbarSingleItemData;
|
|
22
22
|
export declare const mMarkedItemData: MToolbarSingleItemData;
|
|
23
|
-
export declare const mBiusGroupConfig: MToolbarGroupData;
|
|
24
|
-
export declare const mHeadingListConfig: MToolbarListButtonData;
|
|
25
|
-
export declare const mListsListConfig: MToolbarListButtonData;
|
|
26
23
|
export declare const mCheckboxButton: MToolbarSingleItemData;
|
|
27
|
-
export declare const
|
|
24
|
+
export declare const mCheckboxItemData: MToolbarSingleItemData;
|
|
28
25
|
export declare const mLinkButton: MToolbarSingleItemData;
|
|
29
|
-
export declare const
|
|
26
|
+
export declare const mLinkItemData: MToolbarSingleItemData;
|
|
30
27
|
export declare const mQuoteButton: MToolbarSingleItemData;
|
|
28
|
+
export declare const mQuoteItemData: MToolbarSingleItemData;
|
|
31
29
|
export declare const mCutButton: MToolbarSingleItemData;
|
|
30
|
+
export declare const mCutItemData: MToolbarSingleItemData;
|
|
31
|
+
export declare const mNoteButton: MToolbarSingleItemData;
|
|
32
|
+
export declare const mNoteItemData: MToolbarSingleItemData;
|
|
32
33
|
export declare const mTableButton: MToolbarSingleItemData;
|
|
33
|
-
export declare const
|
|
34
|
-
export declare const
|
|
35
|
-
export declare const mMathListConfig: MToolbarListButtonData;
|
|
36
|
-
export declare const mMathListItem: MToolbarListItemData;
|
|
37
|
-
export declare const mMermaidButton: MToolbarSingleItemData;
|
|
38
|
-
export declare const mYfmHtmlBlockButton: MToolbarSingleItemData;
|
|
34
|
+
export declare const mTableItemData: MToolbarSingleItemData;
|
|
35
|
+
export declare const mCodeItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
39
36
|
export declare const mImagePopupData: MToolbarButtonPopupData;
|
|
37
|
+
export declare const mImageItemData: MToolbarButtonPopupData;
|
|
40
38
|
export declare const mFilePopupData: MToolbarButtonPopupData;
|
|
41
|
-
|
|
42
|
-
export declare const
|
|
39
|
+
export declare const mFileItemData: MToolbarButtonPopupData;
|
|
40
|
+
export declare const mTabsItemData: MToolbarSingleItemData;
|
|
41
|
+
export declare const mMathInlineItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
42
|
+
export declare const mMathBlockItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
43
|
+
export declare const mYfmHtmlBlockButton: MToolbarSingleItemData;
|
|
44
|
+
export declare const mYfmHtmlBlockItemData: MToolbarSingleItemData;
|
|
45
|
+
export declare const mMermaidButton: MToolbarSingleItemData;
|
|
46
|
+
export declare const mMermaidItemData: MToolbarSingleItemData;
|
|
47
|
+
export declare const mCodeblockItemData: MToolbarItemData;
|
|
48
|
+
export declare const mCodeBlockItemData: MToolbarItemData;
|
|
43
49
|
export declare const mHruleItemData: MToolbarSingleItemData;
|
|
44
50
|
export declare const mEmojiItemData: MToolbarSingleItemData;
|
|
45
|
-
export declare const
|
|
51
|
+
export declare const mMathListItem: MToolbarListItemData;
|
|
52
|
+
export declare const mHeading1ItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
53
|
+
export declare const mHeading2ItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
54
|
+
export declare const mHeading3ItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
55
|
+
export declare const mHeading4ItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
56
|
+
export declare const mHeading5ItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
57
|
+
export declare const mHeading6ItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
58
|
+
export declare const mBulletListItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
59
|
+
export declare const mOrderedListItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
60
|
+
export declare const mSinkListItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
61
|
+
export declare const mLiftListItemData: ToolbarListButtonItemData<CodeEditor>;
|
|
62
|
+
export declare const mHeadingListConfig: MToolbarListButtonData;
|
|
63
|
+
export declare const mListsListConfig: MToolbarListButtonData;
|
|
64
|
+
export declare const mListMoveListConfig: MToolbarListButtonData;
|
|
65
|
+
export declare const mCodeListConfig: MToolbarListButtonData;
|
|
66
|
+
export declare const mMathListConfig: MToolbarListButtonData;
|
|
46
67
|
export declare const mHiddenData: MToolbarSingleItemData[];
|
|
68
|
+
export declare const mHistoryGroupConfig: MToolbarGroupData;
|
|
69
|
+
export declare const mBiusGroupConfig: MToolbarGroupData;
|
|
70
|
+
export declare const mToolbarConfig: MToolbarData;
|
|
47
71
|
export declare const mToolbarConfigByPreset: Record<MarkdownEditorPreset, MToolbarData>;
|
|
48
72
|
export declare const mHiddenDataByPreset: Record<MarkdownEditorPreset, MToolbarItemData[]>;
|