@uiw/react-md-editor 3.18.1 → 3.18.3
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/README.md +75 -8
- package/dist/mdeditor.css +0 -1
- package/dist/mdeditor.js +182 -282
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/commands/bold.js +3 -2
- package/esm/commands/bold.js.map +3 -2
- package/esm/commands/code.js +6 -4
- package/esm/commands/code.js.map +3 -2
- package/esm/commands/comment.js +21 -1
- package/esm/commands/comment.js.map +7 -3
- package/esm/commands/fullscreen.js +4 -3
- package/esm/commands/fullscreen.js.map +3 -2
- package/esm/commands/hr.js +3 -2
- package/esm/commands/hr.js.map +3 -2
- package/esm/commands/image.js +4 -3
- package/esm/commands/image.js.map +3 -2
- package/esm/commands/index.d.ts +9 -9
- package/esm/commands/index.js +19 -13
- package/esm/commands/index.js.map +18 -15
- package/esm/commands/italic.js +3 -2
- package/esm/commands/italic.js.map +3 -2
- package/esm/commands/link.js +4 -3
- package/esm/commands/link.js.map +3 -2
- package/esm/commands/list.js +10 -7
- package/esm/commands/list.js.map +3 -2
- package/esm/commands/preview.js +9 -6
- package/esm/commands/preview.js.map +3 -2
- package/esm/commands/quote.js +2 -2
- package/esm/commands/quote.js.map +2 -2
- package/esm/commands/strikeThrough.js +3 -2
- package/esm/commands/strikeThrough.js.map +3 -2
- package/esm/commands/title.js +2 -2
- package/esm/commands/title.js.map +2 -2
- package/esm/commands/title1.js +3 -2
- package/esm/commands/title1.js.map +3 -2
- package/esm/commands/title2.js +3 -2
- package/esm/commands/title2.js.map +3 -2
- package/esm/commands/title3.js +3 -2
- package/esm/commands/title3.js.map +3 -2
- package/esm/commands/title4.js +3 -2
- package/esm/commands/title4.js.map +3 -2
- package/esm/commands/title5.js +3 -2
- package/esm/commands/title5.js.map +3 -2
- package/esm/commands/title6.js +3 -2
- package/esm/commands/title6.js.map +3 -2
- package/lib/commands/bold.js +3 -2
- package/lib/commands/bold.js.map +3 -2
- package/lib/commands/code.js +6 -4
- package/lib/commands/code.js.map +3 -2
- package/lib/commands/comment.js +21 -1
- package/lib/commands/comment.js.map +7 -3
- package/lib/commands/fullscreen.js +4 -3
- package/lib/commands/fullscreen.js.map +3 -2
- package/lib/commands/hr.js +3 -2
- package/lib/commands/hr.js.map +3 -2
- package/lib/commands/image.js +4 -3
- package/lib/commands/image.js.map +3 -2
- package/lib/commands/index.d.ts +9 -9
- package/lib/commands/index.js +25 -18
- package/lib/commands/index.js.map +12 -2
- package/lib/commands/italic.js +3 -2
- package/lib/commands/italic.js.map +3 -2
- package/lib/commands/link.js +4 -3
- package/lib/commands/link.js.map +3 -2
- package/lib/commands/list.js +10 -7
- package/lib/commands/list.js.map +3 -2
- package/lib/commands/preview.js +9 -6
- package/lib/commands/preview.js.map +3 -2
- package/lib/commands/quote.js +2 -2
- package/lib/commands/quote.js.map +2 -2
- package/lib/commands/strikeThrough.js +3 -2
- package/lib/commands/strikeThrough.js.map +3 -2
- package/lib/commands/title.js +2 -2
- package/lib/commands/title.js.map +2 -2
- package/lib/commands/title1.js +3 -2
- package/lib/commands/title1.js.map +3 -2
- package/lib/commands/title2.js +3 -2
- package/lib/commands/title2.js.map +3 -2
- package/lib/commands/title3.js +3 -2
- package/lib/commands/title3.js.map +3 -2
- package/lib/commands/title4.js +3 -2
- package/lib/commands/title4.js.map +3 -2
- package/lib/commands/title5.js +3 -2
- package/lib/commands/title5.js.map +3 -2
- package/lib/commands/title6.js +3 -2
- package/lib/commands/title6.js.map +3 -2
- package/package.json +1 -1
- package/src/__test__/commands.test.tsx +26 -26
- package/src/commands/bold.tsx +2 -1
- package/src/commands/code.tsx +4 -2
- package/src/commands/comment.tsx +8 -0
- package/src/commands/fullscreen.tsx +3 -2
- package/src/commands/hr.tsx +2 -1
- package/src/commands/image.tsx +3 -2
- package/src/commands/index.ts +17 -13
- package/src/commands/italic.tsx +2 -1
- package/src/commands/link.tsx +3 -2
- package/src/commands/list.tsx +10 -4
- package/src/commands/preview.tsx +6 -3
- package/src/commands/quote.tsx +1 -1
- package/src/commands/strikeThrough.tsx +5 -1
- package/src/commands/title.tsx +2 -2
- package/src/commands/title1.tsx +2 -1
- package/src/commands/title2.tsx +2 -1
- package/src/commands/title3.tsx +2 -1
- package/src/commands/title4.tsx +2 -1
- package/src/commands/title5.tsx +2 -1
- package/src/commands/title6.tsx +2 -1
|
@@ -21,7 +21,7 @@ it('MDEditor commands bold', async () => {
|
|
|
21
21
|
);
|
|
22
22
|
};
|
|
23
23
|
render(<MyComponent />);
|
|
24
|
-
const btn = screen.getByTitle('Add bold text');
|
|
24
|
+
const btn = screen.getByTitle('Add bold text (ctrl + b)');
|
|
25
25
|
btn.focus();
|
|
26
26
|
fireEvent(
|
|
27
27
|
btn,
|
|
@@ -48,7 +48,7 @@ it('MDEditor commands italic', async () => {
|
|
|
48
48
|
);
|
|
49
49
|
};
|
|
50
50
|
render(<MyComponent />);
|
|
51
|
-
const btn = screen.getByTitle('Add italic text');
|
|
51
|
+
const btn = screen.getByTitle('Add italic text (ctrl + i)');
|
|
52
52
|
btn.focus();
|
|
53
53
|
fireEvent(
|
|
54
54
|
btn,
|
|
@@ -66,7 +66,7 @@ it('MDEditor commands code', async () => {
|
|
|
66
66
|
render(<MDEditor value={`He llo \nWold!`} textareaProps={{ title: 'test' }} onChange={handleChange} />);
|
|
67
67
|
const input = screen.getByTitle<HTMLInputElement>('test');
|
|
68
68
|
input.setSelectionRange(0, 5);
|
|
69
|
-
const btn = screen.getByLabelText('Insert code');
|
|
69
|
+
const btn = screen.getByLabelText('Insert code (ctrl + j)');
|
|
70
70
|
fireEvent(
|
|
71
71
|
btn,
|
|
72
72
|
new MouseEvent('click', {
|
|
@@ -82,7 +82,7 @@ it('MDEditor commands selectOptions code', async () => {
|
|
|
82
82
|
render(<MDEditor value={`Hello\nWold!`} textareaProps={{ title: 'test' }} onChange={handleChange} />);
|
|
83
83
|
const input = screen.getByTitle<HTMLInputElement>('test');
|
|
84
84
|
input.setSelectionRange(0, 11);
|
|
85
|
-
const btn = screen.getByLabelText('Insert code');
|
|
85
|
+
const btn = screen.getByLabelText('Insert code (ctrl + j)');
|
|
86
86
|
fireEvent(
|
|
87
87
|
btn,
|
|
88
88
|
new MouseEvent('click', {
|
|
@@ -115,7 +115,7 @@ it('MDEditor commands quote', async () => {
|
|
|
115
115
|
);
|
|
116
116
|
};
|
|
117
117
|
render(<MyComponent />);
|
|
118
|
-
const btn = screen.getByLabelText('Insert a quote');
|
|
118
|
+
const btn = screen.getByLabelText('Insert a quote (ctrl + q)');
|
|
119
119
|
btn.focus();
|
|
120
120
|
fireEvent(
|
|
121
121
|
btn,
|
|
@@ -142,7 +142,7 @@ it('MDEditor commands HR', async () => {
|
|
|
142
142
|
);
|
|
143
143
|
};
|
|
144
144
|
render(<MyComponent />);
|
|
145
|
-
const btn = screen.getByLabelText('Insert HR');
|
|
145
|
+
const btn = screen.getByLabelText('Insert HR (ctrl + h)');
|
|
146
146
|
btn.focus();
|
|
147
147
|
fireEvent(
|
|
148
148
|
btn,
|
|
@@ -169,7 +169,7 @@ it('MDEditor commands strikethrough text', async () => {
|
|
|
169
169
|
);
|
|
170
170
|
};
|
|
171
171
|
render(<MyComponent />);
|
|
172
|
-
const btn = screen.getByLabelText('Add strikethrough text');
|
|
172
|
+
const btn = screen.getByLabelText('Add strikethrough text (ctrl + shift + x)');
|
|
173
173
|
btn.focus();
|
|
174
174
|
fireEvent(
|
|
175
175
|
btn,
|
|
@@ -196,7 +196,7 @@ it('MDEditor commands link', async () => {
|
|
|
196
196
|
);
|
|
197
197
|
};
|
|
198
198
|
render(<MyComponent />);
|
|
199
|
-
const btn = screen.getByLabelText('Add a link');
|
|
199
|
+
const btn = screen.getByLabelText('Add a link (ctrl + l)');
|
|
200
200
|
btn.focus();
|
|
201
201
|
fireEvent(
|
|
202
202
|
btn,
|
|
@@ -223,7 +223,7 @@ it('MDEditor commands image', async () => {
|
|
|
223
223
|
);
|
|
224
224
|
};
|
|
225
225
|
render(<MyComponent />);
|
|
226
|
-
const btn = screen.getByLabelText('Add image');
|
|
226
|
+
const btn = screen.getByLabelText('Add image (ctrl + k)');
|
|
227
227
|
btn.focus();
|
|
228
228
|
fireEvent(
|
|
229
229
|
btn,
|
|
@@ -250,7 +250,7 @@ it("MDEditor commands image === ''", async () => {
|
|
|
250
250
|
);
|
|
251
251
|
};
|
|
252
252
|
render(<MyComponent />);
|
|
253
|
-
const btn = screen.getByLabelText('Add image');
|
|
253
|
+
const btn = screen.getByLabelText('Add image (ctrl + k)');
|
|
254
254
|
btn.focus();
|
|
255
255
|
fireEvent(
|
|
256
256
|
btn,
|
|
@@ -277,7 +277,7 @@ it('MDEditor commands Add unordered list', async () => {
|
|
|
277
277
|
);
|
|
278
278
|
};
|
|
279
279
|
render(<MyComponent />);
|
|
280
|
-
const btn = screen.getByLabelText('Add unordered list');
|
|
280
|
+
const btn = screen.getByLabelText('Add unordered list (ctrl + shift + u)');
|
|
281
281
|
btn.focus();
|
|
282
282
|
fireEvent(
|
|
283
283
|
btn,
|
|
@@ -293,7 +293,7 @@ it('MDEditor commands Add unordered list', async () => {
|
|
|
293
293
|
it('MDEditor commands Add ordered list', async () => {
|
|
294
294
|
const handleChange = jest.fn((value) => value);
|
|
295
295
|
render(<MDEditor value="title" textareaProps={{ title: 'test' }} onChange={handleChange} />);
|
|
296
|
-
const btn = screen.getByLabelText('Add ordered list');
|
|
296
|
+
const btn = screen.getByLabelText('Add ordered list (ctrl + shift + o)');
|
|
297
297
|
fireEvent(
|
|
298
298
|
btn,
|
|
299
299
|
new MouseEvent('click', {
|
|
@@ -318,7 +318,7 @@ it('MDEditor commands Add checked list', async () => {
|
|
|
318
318
|
);
|
|
319
319
|
};
|
|
320
320
|
render(<MyComponent />);
|
|
321
|
-
const btn = screen.getByLabelText('Add checked list');
|
|
321
|
+
const btn = screen.getByLabelText('Add checked list (ctrl + shift + c)');
|
|
322
322
|
|
|
323
323
|
btn.focus();
|
|
324
324
|
fireEvent(
|
|
@@ -335,7 +335,7 @@ it('MDEditor commands Add checked list', async () => {
|
|
|
335
335
|
it('MDEditor commands fullscreen', async () => {
|
|
336
336
|
const handleChange = jest.fn((value) => value);
|
|
337
337
|
await render(<MDEditor value="title" textareaProps={{ title: 'test' }} onChange={handleChange} />);
|
|
338
|
-
const btn = screen.getByLabelText('fullscreen');
|
|
338
|
+
const btn = screen.getByLabelText('Toggle fullscreen (ctrl + 0)');
|
|
339
339
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
340
340
|
expect(document.body.style).toMatchObject({
|
|
341
341
|
overflow: 'hidden',
|
|
@@ -365,7 +365,7 @@ it('MDEditor commands comment `ctrlcmd+/`', async () => {
|
|
|
365
365
|
it('MDEditor commands title1 value === undefined', async () => {
|
|
366
366
|
const handleChange = jest.fn((value) => value);
|
|
367
367
|
render(<MDEditor onChange={handleChange} commands={[commands.title1]} />);
|
|
368
|
-
const btn = screen.getByLabelText('Insert
|
|
368
|
+
const btn = screen.getByLabelText('Insert title1 (ctrl + 1)');
|
|
369
369
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
370
370
|
expect(handleChange).toHaveReturnedWith('# ');
|
|
371
371
|
});
|
|
@@ -380,7 +380,7 @@ it('MDEditor commands title1 value === test', async () => {
|
|
|
380
380
|
commands={[commands.title1]}
|
|
381
381
|
/>,
|
|
382
382
|
);
|
|
383
|
-
const btn = screen.getByLabelText('Insert
|
|
383
|
+
const btn = screen.getByLabelText('Insert title1 (ctrl + 1)');
|
|
384
384
|
const input = screen.getByTitle<HTMLTextAreaElement>('textarea');
|
|
385
385
|
input.setSelectionRange(2, 2);
|
|
386
386
|
|
|
@@ -393,7 +393,7 @@ it('MDEditor commands title2 value === undefined', async () => {
|
|
|
393
393
|
render(<MDEditor onChange={handleChange} textareaProps={{ title: 'test' }} commands={[commands.title2]} />);
|
|
394
394
|
const input = screen.getByTitle<HTMLInputElement>('test');
|
|
395
395
|
input.setSelectionRange(0, 0);
|
|
396
|
-
const btn = screen.getByLabelText('Insert title2');
|
|
396
|
+
const btn = screen.getByLabelText('Insert title2 (ctrl + 2)');
|
|
397
397
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
398
398
|
input.setSelectionRange(0, 0);
|
|
399
399
|
expect(handleChange).toHaveReturnedWith('## ');
|
|
@@ -406,7 +406,7 @@ it('MDEditor commands title2 value === test', async () => {
|
|
|
406
406
|
);
|
|
407
407
|
const input = screen.getByTitle<HTMLInputElement>('test');
|
|
408
408
|
input.setSelectionRange(2, 2);
|
|
409
|
-
const btn = screen.getByLabelText('Insert title2');
|
|
409
|
+
const btn = screen.getByLabelText('Insert title2 (ctrl + 2)');
|
|
410
410
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
411
411
|
expect(handleChange).toHaveReturnedWith('## test');
|
|
412
412
|
});
|
|
@@ -414,7 +414,7 @@ it('MDEditor commands title2 value === test', async () => {
|
|
|
414
414
|
it('MDEditor commands title3 value === undefined', async () => {
|
|
415
415
|
const handleChange = jest.fn((value) => value);
|
|
416
416
|
render(<MDEditor onChange={handleChange} commands={[commands.title3]} />);
|
|
417
|
-
const btn = screen.getByLabelText('Insert title3');
|
|
417
|
+
const btn = screen.getByLabelText('Insert title3 (ctrl + 3)');
|
|
418
418
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
419
419
|
expect(handleChange).toHaveReturnedWith('### ');
|
|
420
420
|
});
|
|
@@ -429,7 +429,7 @@ it('MDEditor commands title3 value === test', async () => {
|
|
|
429
429
|
commands={[commands.title3]}
|
|
430
430
|
/>,
|
|
431
431
|
);
|
|
432
|
-
const btn = screen.getByLabelText('Insert title3');
|
|
432
|
+
const btn = screen.getByLabelText('Insert title3 (ctrl + 3)');
|
|
433
433
|
const input = screen.getByTitle<HTMLInputElement>('textarea');
|
|
434
434
|
input.setSelectionRange(2, 2);
|
|
435
435
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
@@ -439,7 +439,7 @@ it('MDEditor commands title3 value === test', async () => {
|
|
|
439
439
|
it('MDEditor commands title4 value === undefined', async () => {
|
|
440
440
|
const handleChange = jest.fn((value) => value);
|
|
441
441
|
render(<MDEditor onChange={handleChange} commands={[commands.title4]} />);
|
|
442
|
-
const btn = screen.getByLabelText('Insert title4');
|
|
442
|
+
const btn = screen.getByLabelText('Insert title4 (ctrl + 4)');
|
|
443
443
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
444
444
|
expect(handleChange).toHaveReturnedWith('#### ');
|
|
445
445
|
});
|
|
@@ -454,7 +454,7 @@ it('MDEditor commands title4 value === test', async () => {
|
|
|
454
454
|
commands={[commands.title4]}
|
|
455
455
|
/>,
|
|
456
456
|
);
|
|
457
|
-
const btn = screen.getByLabelText('Insert title4');
|
|
457
|
+
const btn = screen.getByLabelText('Insert title4 (ctrl + 4)');
|
|
458
458
|
const input = screen.getByTitle('textarea');
|
|
459
459
|
(input as any).setSelectionRange(2, 2);
|
|
460
460
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
@@ -464,7 +464,7 @@ it('MDEditor commands title4 value === test', async () => {
|
|
|
464
464
|
it('MDEditor commands title5 value === undefined', async () => {
|
|
465
465
|
const handleChange = jest.fn((value) => value);
|
|
466
466
|
render(<MDEditor onChange={handleChange} commands={[commands.title5]} />);
|
|
467
|
-
const btn = screen.getByLabelText('Insert title5');
|
|
467
|
+
const btn = screen.getByLabelText('Insert title5 (ctrl + 5)');
|
|
468
468
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
469
469
|
expect(handleChange).toHaveReturnedWith('##### ');
|
|
470
470
|
});
|
|
@@ -479,7 +479,7 @@ it('MDEditor commands title5 value === test', async () => {
|
|
|
479
479
|
commands={[commands.title5]}
|
|
480
480
|
/>,
|
|
481
481
|
);
|
|
482
|
-
const btn = screen.getByLabelText('Insert title5');
|
|
482
|
+
const btn = screen.getByLabelText('Insert title5 (ctrl + 5)');
|
|
483
483
|
const input = screen.getByTitle<HTMLInputElement>('textarea');
|
|
484
484
|
input.setSelectionRange(2, 2);
|
|
485
485
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
@@ -489,7 +489,7 @@ it('MDEditor commands title5 value === test', async () => {
|
|
|
489
489
|
it('MDEditor commands title6 value === undefined', async () => {
|
|
490
490
|
const handleChange = jest.fn((value) => value);
|
|
491
491
|
render(<MDEditor onChange={handleChange} commands={[commands.title6]} />);
|
|
492
|
-
const btn = screen.getByLabelText('Insert title6');
|
|
492
|
+
const btn = screen.getByLabelText('Insert title6 (ctrl + 6)');
|
|
493
493
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
494
494
|
expect(handleChange).toHaveReturnedWith('###### ');
|
|
495
495
|
});
|
|
@@ -504,7 +504,7 @@ it('MDEditor commands title6 value === test', async () => {
|
|
|
504
504
|
commands={[commands.title6]}
|
|
505
505
|
/>,
|
|
506
506
|
);
|
|
507
|
-
const btn = screen.getByLabelText('Insert title6');
|
|
507
|
+
const btn = screen.getByLabelText('Insert title6 (ctrl + 6)');
|
|
508
508
|
const input = screen.getByTitle('textarea');
|
|
509
509
|
(input as any).setSelectionRange(2, 2);
|
|
510
510
|
fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
|
package/src/commands/bold.tsx
CHANGED
|
@@ -6,7 +6,8 @@ export const bold: ICommand = {
|
|
|
6
6
|
name: 'bold',
|
|
7
7
|
keyCommand: 'bold',
|
|
8
8
|
shortcuts: 'ctrlcmd+b',
|
|
9
|
-
|
|
9
|
+
value: '**',
|
|
10
|
+
buttonProps: { 'aria-label': 'Add bold text (ctrl + b)', title: 'Add bold text (ctrl + b)' },
|
|
10
11
|
icon: (
|
|
11
12
|
<svg role="img" width="12" height="12" viewBox="0 0 384 512">
|
|
12
13
|
<path
|
package/src/commands/code.tsx
CHANGED
|
@@ -10,7 +10,8 @@ export const code: ICommand = {
|
|
|
10
10
|
name: 'code',
|
|
11
11
|
keyCommand: 'code',
|
|
12
12
|
shortcuts: 'ctrlcmd+j',
|
|
13
|
-
|
|
13
|
+
value: '``',
|
|
14
|
+
buttonProps: { 'aria-label': 'Insert code (ctrl + j)', title: 'Insert code (ctrl + j)' },
|
|
14
15
|
icon: (
|
|
15
16
|
<svg width="12" height="12" role="img" viewBox="0 0 640 512">
|
|
16
17
|
<path
|
|
@@ -60,6 +61,7 @@ export const codeBlock: ICommand = {
|
|
|
60
61
|
name: 'codeBlock',
|
|
61
62
|
keyCommand: 'codeBlock',
|
|
62
63
|
shortcuts: 'ctrlcmd+shift+j',
|
|
64
|
+
value: '```\n```',
|
|
63
65
|
icon: (
|
|
64
66
|
<svg width="12" height="12" role="img" viewBox="0 0 156 156">
|
|
65
67
|
<path
|
|
@@ -68,7 +70,7 @@ export const codeBlock: ICommand = {
|
|
|
68
70
|
/>
|
|
69
71
|
</svg>
|
|
70
72
|
),
|
|
71
|
-
buttonProps: { 'aria-label': 'Insert Code Block', title: 'Insert Code Block' },
|
|
73
|
+
buttonProps: { 'aria-label': 'Insert Code Block (ctrl + shift + j)', title: 'Insert Code Block (ctrl + shift +j)' },
|
|
72
74
|
execute: (tate: TextState, api: TextAreaTextApi) => {
|
|
73
75
|
// Adjust the selection to encompass the whole word if the caret is inside one
|
|
74
76
|
const newSelectionRange = selectWord({ text: tate.text, selection: tate.selection });
|
package/src/commands/comment.tsx
CHANGED
|
@@ -5,6 +5,8 @@ export const comment: ICommand = {
|
|
|
5
5
|
name: 'comment',
|
|
6
6
|
keyCommand: 'comment',
|
|
7
7
|
shortcuts: 'ctrlcmd+/',
|
|
8
|
+
value: '<!-- -->',
|
|
9
|
+
buttonProps: { 'aria-label': 'Insert comment (ctrl + /)', title: 'Insert comment (ctrl + /)' },
|
|
8
10
|
execute: (state: TextState, api: TextAreaTextApi) => {
|
|
9
11
|
// Adjust the selection to encompass the whole word if the caret is inside one
|
|
10
12
|
const newSelectionRange = selectWord({ text: state.text, selection: state.selection });
|
|
@@ -17,4 +19,10 @@ export const comment: ICommand = {
|
|
|
17
19
|
end: state2.selection.end - 4,
|
|
18
20
|
});
|
|
19
21
|
},
|
|
22
|
+
icon: (
|
|
23
|
+
<svg role="img" viewBox="0 0 512 512" width="12" height="12">
|
|
24
|
+
<path fill="currentColor" d="M281 72H231oLuLFozwYpLrBi5VTa8sg7fDqKkeyD81V172H281V72Z" />
|
|
25
|
+
<path fill="currentColor" d="M287.817 501H213.333L298.667 334H438.857C438.857 334 438.857 333.021 438.857 308.308V187.875V74.6028C438.857 64.3818 438.857 67.2814 438.857 62.625C438.857 61.7594 439.31 62.625 426.667 62.625H256H73.1429C73.1429 65.4903 73.1429 77.3378 73.1429 79.8845V187.875V308.308C73.1429 311.005 73.1429 334 73.1429 334C73.1429 334 113.826 334 106.667 334H149.333H237.714V385.385H73.1429C53.7442 385.385 35.14 377.264 21.423 362.809C7.7061 348.355 0 328.75 0 308.308V77.0769C0 56.6349 7.7061 37.03 21.423 22.5753C35.14 8.12058 53.7442 0 73.1429 0H438.857C458.256 0 476.86 8.12058 490.577 22.5753C504.294 37.03 512 56.6349 512 77.0769V308.308C512 328.75 504.294 348.355 490.577 362.809C476.86 377.264 458.256 385.385 438.857 385.385H350.354L287.817 501Z" />
|
|
26
|
+
</svg>
|
|
27
|
+
)
|
|
20
28
|
};
|
|
@@ -5,8 +5,9 @@ import { ContextStore, ExecuteCommandState } from '../Context';
|
|
|
5
5
|
export const fullscreen: ICommand = {
|
|
6
6
|
name: 'fullscreen',
|
|
7
7
|
keyCommand: 'fullscreen',
|
|
8
|
-
shortcuts: '
|
|
9
|
-
|
|
8
|
+
shortcuts: 'ctrlcmd+0',
|
|
9
|
+
value: 'fullscreen',
|
|
10
|
+
buttonProps: { 'aria-label': 'Toggle fullscreen (ctrl + 0)', title: 'Toggle fullscreen (ctrl+ 0)' },
|
|
10
11
|
icon: (
|
|
11
12
|
<svg width="12" height="12" viewBox="0 0 520 520">
|
|
12
13
|
<path
|
package/src/commands/hr.tsx
CHANGED
|
@@ -5,7 +5,8 @@ export const hr: ICommand = {
|
|
|
5
5
|
name: 'hr',
|
|
6
6
|
keyCommand: 'hr',
|
|
7
7
|
shortcuts: 'ctrlcmd+h',
|
|
8
|
-
|
|
8
|
+
value: '----------',
|
|
9
|
+
buttonProps: { 'aria-label': 'Insert HR (ctrl + h)', title: 'Insert HR (ctrl + h)' },
|
|
9
10
|
icon: (
|
|
10
11
|
<svg width="12" height="12" viewBox="0 0 175 175">
|
|
11
12
|
<path
|
package/src/commands/image.tsx
CHANGED
|
@@ -5,8 +5,9 @@ import { selectWord } from '../utils/markdownUtils';
|
|
|
5
5
|
export const image: ICommand = {
|
|
6
6
|
name: 'image',
|
|
7
7
|
keyCommand: 'image',
|
|
8
|
-
shortcuts: 'ctrlcmd+
|
|
9
|
-
|
|
8
|
+
shortcuts: 'ctrlcmd+k',
|
|
9
|
+
value: '![image]()',
|
|
10
|
+
buttonProps: { 'aria-label': 'Add image (ctrl + k)', title: 'Add image (ctrl + k)' },
|
|
10
11
|
icon: (
|
|
11
12
|
<svg width="12" height="12" viewBox="0 0 20 20">
|
|
12
13
|
<path
|
package/src/commands/index.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ContextStore, ExecuteCommandState } from '../Context';
|
|
3
|
+
import { insertTextAtPosition } from '../utils/InsertTextAtPosition';
|
|
2
4
|
import { bold } from './bold';
|
|
3
5
|
import { code, codeBlock } from './code';
|
|
6
|
+
import { comment } from './comment';
|
|
7
|
+
import { divider } from './divider';
|
|
8
|
+
import { fullscreen } from './fullscreen';
|
|
9
|
+
import { group } from './group';
|
|
10
|
+
import { hr } from './hr';
|
|
11
|
+
import { image } from './image';
|
|
4
12
|
import { italic } from './italic';
|
|
5
13
|
import { link } from './link';
|
|
6
|
-
import {
|
|
14
|
+
import { checkedListCommand, orderedListCommand, unorderedListCommand } from './list';
|
|
15
|
+
import { codeEdit, codeLive, codePreview } from './preview';
|
|
7
16
|
import { quote } from './quote';
|
|
8
|
-
import {
|
|
17
|
+
import { strikethrough } from './strikeThrough';
|
|
9
18
|
import { title } from './title';
|
|
10
19
|
import { title1 } from './title1';
|
|
11
20
|
import { title2 } from './title2';
|
|
@@ -13,15 +22,6 @@ import { title3 } from './title3';
|
|
|
13
22
|
import { title4 } from './title4';
|
|
14
23
|
import { title5 } from './title5';
|
|
15
24
|
import { title6 } from './title6';
|
|
16
|
-
import { comment } from './comment';
|
|
17
|
-
import { group } from './group';
|
|
18
|
-
import { divider } from './divider';
|
|
19
|
-
import { codePreview, codeEdit, codeLive } from './preview';
|
|
20
|
-
import { fullscreen } from './fullscreen';
|
|
21
|
-
import { image } from './image';
|
|
22
|
-
import { strikethrough } from './strikeThrough';
|
|
23
|
-
import { insertTextAtPosition } from '../utils/InsertTextAtPosition';
|
|
24
|
-
import { ContextStore, ExecuteCommandState } from '../Context';
|
|
25
25
|
|
|
26
26
|
export interface CommandOrchestrator {
|
|
27
27
|
executeCommand(command: ICommand): void;
|
|
@@ -84,7 +84,11 @@ const getCommands: () => ICommand[] = () => [
|
|
|
84
84
|
italic,
|
|
85
85
|
strikethrough,
|
|
86
86
|
hr,
|
|
87
|
-
|
|
87
|
+
group([title1, title2, title3, title4, title5, title6], {
|
|
88
|
+
name: "title",
|
|
89
|
+
groupName: "title",
|
|
90
|
+
buttonProps: { "aria-label": "Insert title", title: "Insert title" },
|
|
91
|
+
}),
|
|
88
92
|
divider,
|
|
89
93
|
link,
|
|
90
94
|
quote,
|
|
@@ -163,7 +167,6 @@ class TextAreaCommandOrchestrator implements CommandOrchestrator {
|
|
|
163
167
|
}
|
|
164
168
|
|
|
165
169
|
export {
|
|
166
|
-
// Toolbars.
|
|
167
170
|
title,
|
|
168
171
|
title1,
|
|
169
172
|
title2,
|
|
@@ -196,3 +199,4 @@ export {
|
|
|
196
199
|
TextAreaCommandOrchestrator,
|
|
197
200
|
TextAreaTextApi,
|
|
198
201
|
};
|
|
202
|
+
|
package/src/commands/italic.tsx
CHANGED
|
@@ -6,7 +6,8 @@ export const italic: ICommand = {
|
|
|
6
6
|
name: 'italic',
|
|
7
7
|
keyCommand: 'italic',
|
|
8
8
|
shortcuts: 'ctrlcmd+i',
|
|
9
|
-
|
|
9
|
+
value: '* *',
|
|
10
|
+
buttonProps: { 'aria-label': 'Add italic text (ctrl + i)', title: 'Add italic text (ctrl + i)' },
|
|
10
11
|
icon: (
|
|
11
12
|
<svg data-name="italic" width="12" height="12" role="img" viewBox="0 0 320 512">
|
|
12
13
|
<path
|
package/src/commands/link.tsx
CHANGED
|
@@ -5,8 +5,9 @@ import { selectWord } from '../utils/markdownUtils';
|
|
|
5
5
|
export const link: ICommand = {
|
|
6
6
|
name: 'link',
|
|
7
7
|
keyCommand: 'link',
|
|
8
|
-
shortcuts: 'ctrlcmd+
|
|
9
|
-
|
|
8
|
+
shortcuts: 'ctrlcmd+l',
|
|
9
|
+
value: '[](url)',
|
|
10
|
+
buttonProps: { 'aria-label': 'Add a link (ctrl + l)', title: 'Add a link (ctrl + l)' },
|
|
10
11
|
icon: (
|
|
11
12
|
<svg data-name="italic" width="12" height="12" role="img" viewBox="0 0 520 520">
|
|
12
13
|
<path
|
package/src/commands/list.tsx
CHANGED
|
@@ -66,8 +66,12 @@ export const makeList = (state: TextState, api: TextAreaTextApi, insertBefore: s
|
|
|
66
66
|
export const unorderedListCommand: ICommand = {
|
|
67
67
|
name: 'unordered-list',
|
|
68
68
|
keyCommand: 'list',
|
|
69
|
-
shortcuts: 'ctrl+shift+
|
|
70
|
-
|
|
69
|
+
shortcuts: 'ctrl+shift+u',
|
|
70
|
+
value: '- ',
|
|
71
|
+
buttonProps: {
|
|
72
|
+
'aria-label': 'Add unordered list (ctrl + shift + u)',
|
|
73
|
+
title: 'Add unordered list (ctrl + shift + u)',
|
|
74
|
+
},
|
|
71
75
|
icon: (
|
|
72
76
|
<svg data-name="unordered-list" width="12" height="12" viewBox="0 0 512 512">
|
|
73
77
|
<path
|
|
@@ -85,7 +89,8 @@ export const orderedListCommand: ICommand = {
|
|
|
85
89
|
name: 'ordered-list',
|
|
86
90
|
keyCommand: 'list',
|
|
87
91
|
shortcuts: 'ctrl+shift+o',
|
|
88
|
-
|
|
92
|
+
value: '1. ',
|
|
93
|
+
buttonProps: { 'aria-label': 'Add ordered list (ctrl + shift + o)', title: 'Add ordered list (ctrl + shift + o)' },
|
|
89
94
|
icon: (
|
|
90
95
|
<svg data-name="ordered-list" width="12" height="12" role="img" viewBox="0 0 512 512">
|
|
91
96
|
<path
|
|
@@ -103,7 +108,8 @@ export const checkedListCommand: ICommand = {
|
|
|
103
108
|
name: 'checked-list',
|
|
104
109
|
keyCommand: 'list',
|
|
105
110
|
shortcuts: 'ctrl+shift+c',
|
|
106
|
-
|
|
111
|
+
value: '- [x] ',
|
|
112
|
+
buttonProps: { 'aria-label': 'Add checked list (ctrl + shift + c)', title: 'Add checked list (ctrl + shift + c)' },
|
|
107
113
|
icon: (
|
|
108
114
|
<svg data-name="checked-list" width="12" height="12" role="img" viewBox="0 0 512 512">
|
|
109
115
|
<path
|
package/src/commands/preview.tsx
CHANGED
|
@@ -5,7 +5,8 @@ export const codePreview: ICommand = {
|
|
|
5
5
|
name: 'preview',
|
|
6
6
|
keyCommand: 'preview',
|
|
7
7
|
value: 'preview',
|
|
8
|
-
|
|
8
|
+
shortcuts: 'ctrlcmd+9',
|
|
9
|
+
buttonProps: { 'aria-label': 'Preview code (ctrl + 9)', title: 'Preview code (ctrl + 9)' },
|
|
9
10
|
icon: (
|
|
10
11
|
<svg width="12" height="12" viewBox="0 0 520 520">
|
|
11
12
|
<polygon
|
|
@@ -25,7 +26,8 @@ export const codeEdit: ICommand = {
|
|
|
25
26
|
name: 'edit',
|
|
26
27
|
keyCommand: 'preview',
|
|
27
28
|
value: 'edit',
|
|
28
|
-
|
|
29
|
+
shortcuts: 'ctrlcmd+7',
|
|
30
|
+
buttonProps: { 'aria-label': 'Edit code (ctrl + 7)', title: 'Edit code (ctrl + 7)' },
|
|
29
31
|
icon: (
|
|
30
32
|
<svg width="12" height="12" viewBox="0 0 520 520">
|
|
31
33
|
<polygon fill="currentColor" points="0 71.293 0 122 319 122 319 397 0 397 0 449.707 372 449.413 372 71.293" />
|
|
@@ -42,7 +44,8 @@ export const codeLive: ICommand = {
|
|
|
42
44
|
name: 'live',
|
|
43
45
|
keyCommand: 'preview',
|
|
44
46
|
value: 'live',
|
|
45
|
-
|
|
47
|
+
shortcuts: 'ctrlcmd+8',
|
|
48
|
+
buttonProps: { 'aria-label': 'Live code (ctrl + 8)', title: 'Live code (ctrl + 8)' },
|
|
46
49
|
icon: (
|
|
47
50
|
<svg width="12" height="12" viewBox="0 0 520 520">
|
|
48
51
|
<polygon fill="currentColor" points="0 71.293 0 122 179 122 179 397 0 397 0 449.707 232 449.413 232 71.293" />
|
package/src/commands/quote.tsx
CHANGED
|
@@ -10,7 +10,7 @@ export const quote: ICommand = {
|
|
|
10
10
|
name: 'quote',
|
|
11
11
|
keyCommand: 'quote',
|
|
12
12
|
shortcuts: 'ctrlcmd+q',
|
|
13
|
-
buttonProps: { 'aria-label': 'Insert a quote', title: 'Insert a quote' },
|
|
13
|
+
buttonProps: { 'aria-label': 'Insert a quote (ctrl + q)', title: 'Insert a quote (ctrl + q)' },
|
|
14
14
|
icon: (
|
|
15
15
|
<svg width="12" height="12" viewBox="0 0 520 520">
|
|
16
16
|
<path
|
|
@@ -6,7 +6,11 @@ export const strikethrough: ICommand = {
|
|
|
6
6
|
name: 'strikethrough',
|
|
7
7
|
keyCommand: 'strikethrough',
|
|
8
8
|
shortcuts: 'ctrl+shift+x',
|
|
9
|
-
buttonProps: {
|
|
9
|
+
buttonProps: {
|
|
10
|
+
'aria-label': 'Add strikethrough text (ctrl + shift + x)',
|
|
11
|
+
title: 'Add strikethrough text (ctrl + shift + x)',
|
|
12
|
+
},
|
|
13
|
+
value: '~~',
|
|
10
14
|
icon: (
|
|
11
15
|
<svg data-name="strikethrough" width="12" height="12" role="img" viewBox="0 0 512 512">
|
|
12
16
|
<path
|
package/src/commands/title.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ICommand } from './';
|
|
3
|
-
import {
|
|
3
|
+
import { title1 } from './title1';
|
|
4
4
|
|
|
5
5
|
export const title: ICommand = {
|
|
6
|
-
...
|
|
6
|
+
...title1,
|
|
7
7
|
icon: (
|
|
8
8
|
<svg width="12" height="12" viewBox="0 0 520 520">
|
|
9
9
|
<path
|
package/src/commands/title1.tsx
CHANGED
|
@@ -6,7 +6,8 @@ export const title1: ICommand = {
|
|
|
6
6
|
name: 'title1',
|
|
7
7
|
keyCommand: 'title1',
|
|
8
8
|
shortcuts: 'ctrlcmd+1',
|
|
9
|
-
|
|
9
|
+
value: 'title1',
|
|
10
|
+
buttonProps: { 'aria-label': 'Insert title1 (ctrl + 1)', title: 'Insert title1 (ctrl + 1)' },
|
|
10
11
|
icon: <div style={{ fontSize: 18, textAlign: 'left' }}>Title 1</div>,
|
|
11
12
|
execute: (state: TextState, api: TextAreaTextApi) => {
|
|
12
13
|
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
package/src/commands/title2.tsx
CHANGED
|
@@ -6,7 +6,8 @@ export const title2: ICommand = {
|
|
|
6
6
|
name: 'title2',
|
|
7
7
|
keyCommand: 'title2',
|
|
8
8
|
shortcuts: 'ctrlcmd+2',
|
|
9
|
-
|
|
9
|
+
value: 'title2',
|
|
10
|
+
buttonProps: { 'aria-label': 'Insert title2 (ctrl + 2)', title: 'Insert title2 (ctrl + 2)' },
|
|
10
11
|
icon: <div style={{ fontSize: 16, textAlign: 'left' }}>Title 2</div>,
|
|
11
12
|
execute: (state: TextState, api: TextAreaTextApi) => {
|
|
12
13
|
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
package/src/commands/title3.tsx
CHANGED
|
@@ -6,7 +6,8 @@ export const title3: ICommand = {
|
|
|
6
6
|
name: 'title3',
|
|
7
7
|
keyCommand: 'title3',
|
|
8
8
|
shortcuts: 'ctrlcmd+3',
|
|
9
|
-
|
|
9
|
+
value: 'title3',
|
|
10
|
+
buttonProps: { 'aria-label': 'Insert title3 (ctrl + 3)', title: 'Insert title3 (ctrl + 3)' },
|
|
10
11
|
icon: <div style={{ fontSize: 15, textAlign: 'left' }}>Title 3</div>,
|
|
11
12
|
execute: (state: TextState, api: TextAreaTextApi) => {
|
|
12
13
|
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
package/src/commands/title4.tsx
CHANGED
|
@@ -6,7 +6,8 @@ export const title4: ICommand = {
|
|
|
6
6
|
name: 'title4',
|
|
7
7
|
keyCommand: 'title4',
|
|
8
8
|
shortcuts: 'ctrlcmd+4',
|
|
9
|
-
|
|
9
|
+
value: 'title4',
|
|
10
|
+
buttonProps: { 'aria-label': 'Insert title4 (ctrl + 4)', title: 'Insert title4 (ctrl + 4)' },
|
|
10
11
|
icon: <div style={{ fontSize: 14, textAlign: 'left' }}>Title 4</div>,
|
|
11
12
|
execute: (state: TextState, api: TextAreaTextApi) => {
|
|
12
13
|
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
package/src/commands/title5.tsx
CHANGED
|
@@ -6,7 +6,8 @@ export const title5: ICommand = {
|
|
|
6
6
|
name: 'title5',
|
|
7
7
|
keyCommand: 'title5',
|
|
8
8
|
shortcuts: 'ctrlcmd+5',
|
|
9
|
-
|
|
9
|
+
value: 'title5',
|
|
10
|
+
buttonProps: { 'aria-label': 'Insert title5 (ctrl + 5)', title: 'Insert title5 (ctrl + 5)' },
|
|
10
11
|
icon: <div style={{ fontSize: 12, textAlign: 'left' }}>Title 5</div>,
|
|
11
12
|
execute: (state: TextState, api: TextAreaTextApi) => {
|
|
12
13
|
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
package/src/commands/title6.tsx
CHANGED
|
@@ -6,7 +6,8 @@ export const title6: ICommand = {
|
|
|
6
6
|
name: 'title6',
|
|
7
7
|
keyCommand: 'title6',
|
|
8
8
|
shortcuts: 'ctrlcmd+6',
|
|
9
|
-
|
|
9
|
+
value: 'title6',
|
|
10
|
+
buttonProps: { 'aria-label': 'Insert title6 (ctrl + 6)', title: 'Insert title6 (ctrl + 6)' },
|
|
10
11
|
icon: <div style={{ fontSize: 12, textAlign: 'left' }}>Title 6</div>,
|
|
11
12
|
execute: (state: TextState, api: TextAreaTextApi) => {
|
|
12
13
|
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|