@uiw/react-md-editor 3.18.0 → 3.18.2

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 (109) hide show
  1. package/README.md +75 -8
  2. package/dist/mdeditor.css +0 -1
  3. package/dist/mdeditor.js +125 -225
  4. package/dist/mdeditor.min.css +1 -1
  5. package/dist/mdeditor.min.js +1 -1
  6. package/esm/Editor.d.ts +4 -5
  7. package/esm/Editor.js +20 -15
  8. package/esm/Editor.js.map +7 -3
  9. package/esm/commands/bold.js +3 -2
  10. package/esm/commands/bold.js.map +3 -2
  11. package/esm/commands/code.js +6 -4
  12. package/esm/commands/code.js.map +3 -2
  13. package/esm/commands/comment.js +5 -0
  14. package/esm/commands/comment.js.map +5 -2
  15. package/esm/commands/fullscreen.js +4 -3
  16. package/esm/commands/fullscreen.js.map +3 -2
  17. package/esm/commands/hr.js +3 -2
  18. package/esm/commands/hr.js.map +3 -2
  19. package/esm/commands/image.js +4 -3
  20. package/esm/commands/image.js.map +3 -2
  21. package/esm/commands/italic.js +3 -2
  22. package/esm/commands/italic.js.map +3 -2
  23. package/esm/commands/link.js +4 -3
  24. package/esm/commands/link.js.map +3 -2
  25. package/esm/commands/list.js +10 -7
  26. package/esm/commands/list.js.map +3 -2
  27. package/esm/commands/preview.js +9 -6
  28. package/esm/commands/preview.js.map +3 -2
  29. package/esm/commands/quote.js +2 -2
  30. package/esm/commands/quote.js.map +2 -2
  31. package/esm/commands/strikeThrough.js +3 -2
  32. package/esm/commands/strikeThrough.js.map +3 -2
  33. package/esm/commands/title.js +2 -2
  34. package/esm/commands/title.js.map +2 -2
  35. package/esm/commands/title1.js +3 -2
  36. package/esm/commands/title1.js.map +3 -2
  37. package/esm/commands/title2.js +3 -2
  38. package/esm/commands/title2.js.map +3 -2
  39. package/esm/commands/title3.js +3 -2
  40. package/esm/commands/title3.js.map +3 -2
  41. package/esm/commands/title4.js +3 -2
  42. package/esm/commands/title4.js.map +3 -2
  43. package/esm/commands/title5.js +3 -2
  44. package/esm/commands/title5.js.map +3 -2
  45. package/esm/commands/title6.js +3 -2
  46. package/esm/commands/title6.js.map +3 -2
  47. package/lib/Editor.d.ts +4 -5
  48. package/lib/Editor.js +26 -19
  49. package/lib/Editor.js.map +7 -3
  50. package/lib/commands/bold.js +3 -2
  51. package/lib/commands/bold.js.map +3 -2
  52. package/lib/commands/code.js +6 -4
  53. package/lib/commands/code.js.map +3 -2
  54. package/lib/commands/comment.js +5 -0
  55. package/lib/commands/comment.js.map +5 -2
  56. package/lib/commands/fullscreen.js +4 -3
  57. package/lib/commands/fullscreen.js.map +3 -2
  58. package/lib/commands/hr.js +3 -2
  59. package/lib/commands/hr.js.map +3 -2
  60. package/lib/commands/image.js +4 -3
  61. package/lib/commands/image.js.map +3 -2
  62. package/lib/commands/italic.js +3 -2
  63. package/lib/commands/italic.js.map +3 -2
  64. package/lib/commands/link.js +4 -3
  65. package/lib/commands/link.js.map +3 -2
  66. package/lib/commands/list.js +10 -7
  67. package/lib/commands/list.js.map +3 -2
  68. package/lib/commands/preview.js +9 -6
  69. package/lib/commands/preview.js.map +3 -2
  70. package/lib/commands/quote.js +2 -2
  71. package/lib/commands/quote.js.map +2 -2
  72. package/lib/commands/strikeThrough.js +3 -2
  73. package/lib/commands/strikeThrough.js.map +3 -2
  74. package/lib/commands/title.js +2 -2
  75. package/lib/commands/title.js.map +2 -2
  76. package/lib/commands/title1.js +3 -2
  77. package/lib/commands/title1.js.map +3 -2
  78. package/lib/commands/title2.js +3 -2
  79. package/lib/commands/title2.js.map +3 -2
  80. package/lib/commands/title3.js +3 -2
  81. package/lib/commands/title3.js.map +3 -2
  82. package/lib/commands/title4.js +3 -2
  83. package/lib/commands/title4.js.map +3 -2
  84. package/lib/commands/title5.js +3 -2
  85. package/lib/commands/title5.js.map +3 -2
  86. package/lib/commands/title6.js +3 -2
  87. package/lib/commands/title6.js.map +3 -2
  88. package/package.json +1 -1
  89. package/src/Editor.tsx +14 -28
  90. package/src/__test__/commands.test.tsx +26 -26
  91. package/src/commands/bold.tsx +2 -1
  92. package/src/commands/code.tsx +4 -2
  93. package/src/commands/comment.tsx +2 -0
  94. package/src/commands/fullscreen.tsx +3 -2
  95. package/src/commands/hr.tsx +2 -1
  96. package/src/commands/image.tsx +3 -2
  97. package/src/commands/italic.tsx +2 -1
  98. package/src/commands/link.tsx +3 -2
  99. package/src/commands/list.tsx +10 -4
  100. package/src/commands/preview.tsx +6 -3
  101. package/src/commands/quote.tsx +1 -1
  102. package/src/commands/strikeThrough.tsx +5 -1
  103. package/src/commands/title.tsx +2 -2
  104. package/src/commands/title1.tsx +2 -1
  105. package/src/commands/title2.tsx +2 -1
  106. package/src/commands/title3.tsx +2 -1
  107. package/src/commands/title4.tsx +2 -1
  108. package/src/commands/title5.tsx +2 -1
  109. package/src/commands/title6.tsx +2 -1
package/src/Editor.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle, CSSProperties } from 'react';
1
+ import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle, CSSProperties, PropsWithRef } from 'react';
2
2
  import MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';
3
3
  import TextArea, { ITextAreaProps } from './components/TextArea';
4
4
  import Toolbar from './components/Toolbar';
@@ -298,14 +298,11 @@ const InternalMDEditor = (
298
298
  };
299
299
 
300
300
  const previewClassName = `${prefixCls}-preview ${previewOptions.className || ''}`;
301
+ const handlePreviewScroll = (e: React.UIEvent<HTMLDivElement, UIEvent>) => handleScroll(e, 'preview');
301
302
  let mdPreview = useMemo(
302
303
  () => (
303
304
  <div ref={previewRef} className={previewClassName}>
304
- <MarkdownPreview
305
- {...previewOptions}
306
- onScroll={(e) => handleScroll(e, 'preview')}
307
- source={state.markdown || ''}
308
- />
305
+ <MarkdownPreview {...previewOptions} onScroll={handlePreviewScroll} source={state.markdown || ''} />
309
306
  </div>
310
307
  ),
311
308
  [previewClassName, previewOptions, state.markdown],
@@ -313,26 +310,19 @@ const InternalMDEditor = (
313
310
  const preview = components?.preview && components?.preview(state.markdown || '', state, dispatch);
314
311
  if (preview && React.isValidElement(preview)) {
315
312
  mdPreview = (
316
- <div className={previewClassName} ref={previewRef} onScroll={(e) => handleScroll(e, 'preview')}>
313
+ <div className={previewClassName} ref={previewRef} onScroll={handlePreviewScroll}>
317
314
  {preview}
318
315
  </div>
319
316
  );
320
317
  }
321
318
 
319
+ const containerStyle = { ...other.style, height: state.height || '100%' };
320
+ const containerClick = () => dispatch({ barPopup: { ...setGroupPopFalse(state.barPopup) } });
321
+ const dragBarChange = (newHeight: number) => dispatch({ height: newHeight });
322
+
322
323
  return (
323
324
  <EditorContext.Provider value={{ ...state, dispatch }}>
324
- <div
325
- ref={container}
326
- className={cls}
327
- {...other}
328
- onClick={() => {
329
- dispatch({ barPopup: { ...setGroupPopFalse(state.barPopup) } });
330
- }}
331
- style={{
332
- ...other.style,
333
- height: state.height || '100%',
334
- }}
335
- >
325
+ <div ref={container} className={cls} {...other} onClick={containerClick} style={containerStyle}>
336
326
  {!hideToolbar && !toolbarBottom && (
337
327
  <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
338
328
  )}
@@ -361,9 +351,7 @@ const InternalMDEditor = (
361
351
  height={state.height as number}
362
352
  maxHeight={maxHeight!}
363
353
  minHeight={minHeight!}
364
- onChange={(newHeight) => {
365
- dispatch({ height: newHeight });
366
- }}
354
+ onChange={dragBarChange}
367
355
  />
368
356
  )}
369
357
  {!hideToolbar && toolbarBottom && (
@@ -374,12 +362,10 @@ const InternalMDEditor = (
374
362
  );
375
363
  };
376
364
 
377
- const mdEditor = React.forwardRef<ContextStore, MDEditorProps>(InternalMDEditor);
365
+ type Editor = React.FC<PropsWithRef<MDEditorProps>> & { Markdown: typeof MarkdownPreview };
378
366
 
379
- type MDEditor = typeof mdEditor & {
380
- Markdown: typeof MarkdownPreview;
381
- };
367
+ const mdEditor: Editor = React.forwardRef(InternalMDEditor) as unknown as Editor;
382
368
 
383
- (mdEditor as MDEditor).Markdown = MarkdownPreview;
369
+ mdEditor.Markdown = MarkdownPreview;
384
370
 
385
- export default mdEditor as MDEditor;
371
+ export default mdEditor;
@@ -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 title 1');
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 title 1');
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 }));
@@ -6,7 +6,8 @@ export const bold: ICommand = {
6
6
  name: 'bold',
7
7
  keyCommand: 'bold',
8
8
  shortcuts: 'ctrlcmd+b',
9
- buttonProps: { 'aria-label': 'Add bold text', title: 'Add bold text' },
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
@@ -10,7 +10,8 @@ export const code: ICommand = {
10
10
  name: 'code',
11
11
  keyCommand: 'code',
12
12
  shortcuts: 'ctrlcmd+j',
13
- buttonProps: { 'aria-label': 'Insert code', title: 'Insert code' },
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 });
@@ -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 });
@@ -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: 'escape',
9
- buttonProps: { 'aria-label': 'fullscreen', title: 'fullscreen' },
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
@@ -5,7 +5,8 @@ export const hr: ICommand = {
5
5
  name: 'hr',
6
6
  keyCommand: 'hr',
7
7
  shortcuts: 'ctrlcmd+h',
8
- buttonProps: { 'aria-label': 'Insert HR', title: 'Insert HR' },
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
@@ -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+i',
9
- buttonProps: { 'aria-label': 'Add image', title: 'Add image' },
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
@@ -6,7 +6,8 @@ export const italic: ICommand = {
6
6
  name: 'italic',
7
7
  keyCommand: 'italic',
8
8
  shortcuts: 'ctrlcmd+i',
9
- buttonProps: { 'aria-label': 'Add italic text', title: 'Add italic text' },
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
@@ -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+k',
9
- buttonProps: { 'aria-label': 'Add a link', title: 'Add a link' },
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
@@ -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+l',
70
- buttonProps: { 'aria-label': 'Add unordered list', title: 'Add unordered list' },
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
- buttonProps: { 'aria-label': 'Add ordered list', title: 'Add ordered list' },
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
- buttonProps: { 'aria-label': 'Add checked list', title: 'Add checked list' },
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
@@ -5,7 +5,8 @@ export const codePreview: ICommand = {
5
5
  name: 'preview',
6
6
  keyCommand: 'preview',
7
7
  value: 'preview',
8
- buttonProps: { 'aria-label': 'Preview code', title: 'Preview code' },
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
- buttonProps: { 'aria-label': 'Edit code', title: 'Edit code' },
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
- buttonProps: { 'aria-label': 'Live code', title: 'Live code' },
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" />
@@ -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: { 'aria-label': 'Add strikethrough text', title: 'Add strikethrough text' },
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
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
2
  import { ICommand } from './';
3
- import { title2 } from './title2';
3
+ import { title1 } from './title1';
4
4
 
5
5
  export const title: ICommand = {
6
- ...title2,
6
+ ...title1,
7
7
  icon: (
8
8
  <svg width="12" height="12" viewBox="0 0 520 520">
9
9
  <path
@@ -6,7 +6,8 @@ export const title1: ICommand = {
6
6
  name: 'title1',
7
7
  keyCommand: 'title1',
8
8
  shortcuts: 'ctrlcmd+1',
9
- buttonProps: { 'aria-label': 'Insert title 1', title: 'Insert title 1' },
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)) {
@@ -6,7 +6,8 @@ export const title2: ICommand = {
6
6
  name: 'title2',
7
7
  keyCommand: 'title2',
8
8
  shortcuts: 'ctrlcmd+2',
9
- buttonProps: { 'aria-label': 'Insert title2', title: 'Insert title 2' },
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)) {
@@ -6,7 +6,8 @@ export const title3: ICommand = {
6
6
  name: 'title3',
7
7
  keyCommand: 'title3',
8
8
  shortcuts: 'ctrlcmd+3',
9
- buttonProps: { 'aria-label': 'Insert title3', title: 'Insert title 3' },
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)) {
@@ -6,7 +6,8 @@ export const title4: ICommand = {
6
6
  name: 'title4',
7
7
  keyCommand: 'title4',
8
8
  shortcuts: 'ctrlcmd+4',
9
- buttonProps: { 'aria-label': 'Insert title4', title: 'Insert title 4' },
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)) {
@@ -6,7 +6,8 @@ export const title5: ICommand = {
6
6
  name: 'title5',
7
7
  keyCommand: 'title5',
8
8
  shortcuts: 'ctrlcmd+5',
9
- buttonProps: { 'aria-label': 'Insert title5', title: 'Insert title 5' },
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)) {
@@ -6,7 +6,8 @@ export const title6: ICommand = {
6
6
  name: 'title6',
7
7
  keyCommand: 'title6',
8
8
  shortcuts: 'ctrlcmd+6',
9
- buttonProps: { 'aria-label': 'Insert title6', title: 'Insert title 6' },
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)) {