|
1 | 1 | <script> |
| 2 | + import { handleDec, handleBlockquote } from './editor.js' |
2 | 3 | export let cm; |
3 | | -
|
4 | | - function handleDec(e, decorator) { |
5 | | - e.preventDefault() |
6 | | -
|
7 | | - if (cm.somethingSelected()) { |
8 | | - cm.replaceSelection(decorator + cm.getSelection() + decorator); |
9 | | - } else { |
10 | | - const { anchor, head } = cm.findWordAt(cm.getCursor()); |
11 | | - const word = cm.getRange(anchor, head); |
12 | | - cm.replaceRange(decorator + word + decorator, anchor, head); |
13 | | - } |
14 | | - cm.focus(); |
15 | | - } |
16 | | - function handleBold(e) { |
17 | | - return handleDec(e, '**'); |
18 | | - } |
19 | | - function handleItalic(e) { |
20 | | - return handleDec(e, '*'); |
21 | | - } |
22 | | - function handleStrikethrough(e) { |
23 | | - return handleDec(e, '~~'); |
24 | | - } |
25 | | - function handleBlockquote() {} |
26 | 4 | </script> |
27 | 5 |
|
28 | 6 | <style> |
|
48 | 26 | </style> |
49 | 27 |
|
50 | 28 | <div> |
51 | | - <span on:click={handleBold}><svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z"/></svg></span> |
52 | | - <span on:click={handleItalic}><svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z"/></svg></span> |
53 | | - <span on:click={handleStrikethrough}><svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z"/></svg></span> |
54 | | - <span on:click={handleBlockquote}><svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z"/></svg></span> |
| 29 | + <span on:click={() => handleDec(cm, '**')}><svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z"/></svg></span> |
| 30 | + <span on:click={() => handleDec(cm, '*')}><svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z"/></svg></span> |
| 31 | + <span on:click={() => handleDec(cm, '~~')}><svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z"/></svg></span> |
| 32 | + <span on:click={() => handleBlockquote(cm)}><svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z"/></svg></span> |
55 | 33 | </div> |
0 commit comments