code.gitea.io/gitea@v1.21.7/web_src/js/features/comp/EasyMDEToolbarActions.js (about) 1 import {svg} from '../../svg.js'; 2 3 export function easyMDEToolbarActions(EasyMDE, editor) { 4 const actions = { 5 '|': '|', 6 'heading-1': { 7 action: EasyMDE.toggleHeading1, 8 icon: svg('octicon-heading'), 9 title: 'Heading 1', 10 }, 11 'heading-2': { 12 action: EasyMDE.toggleHeading2, 13 icon: svg('octicon-heading'), 14 title: 'Heading 2', 15 }, 16 'heading-3': { 17 action: EasyMDE.toggleHeading3, 18 icon: svg('octicon-heading'), 19 title: 'Heading 3', 20 }, 21 'heading-smaller': { 22 action: EasyMDE.toggleHeadingSmaller, 23 icon: svg('octicon-heading'), 24 title: 'Decrease Heading', 25 }, 26 'heading-bigger': { 27 action: EasyMDE.toggleHeadingBigger, 28 icon: svg('octicon-heading'), 29 title: 'Increase Heading', 30 }, 31 'bold': { 32 action: EasyMDE.toggleBold, 33 icon: svg('octicon-bold'), 34 title: 'Bold', 35 }, 36 'italic': { 37 action: EasyMDE.toggleItalic, 38 icon: svg('octicon-italic'), 39 title: 'Italic', 40 }, 41 'strikethrough': { 42 action: EasyMDE.toggleStrikethrough, 43 icon: svg('octicon-strikethrough'), 44 title: 'Strikethrough', 45 }, 46 'quote': { 47 action: EasyMDE.toggleBlockquote, 48 icon: svg('octicon-quote'), 49 title: 'Quote', 50 }, 51 'code': { 52 action: EasyMDE.toggleCodeBlock, 53 icon: svg('octicon-code'), 54 title: 'Code', 55 }, 56 'link': { 57 action: EasyMDE.drawLink, 58 icon: svg('octicon-link'), 59 title: 'Link', 60 }, 61 'unordered-list': { 62 action: EasyMDE.toggleUnorderedList, 63 icon: svg('octicon-list-unordered'), 64 title: 'Unordered List', 65 }, 66 'ordered-list': { 67 action: EasyMDE.toggleOrderedList, 68 icon: svg('octicon-list-ordered'), 69 title: 'Ordered List', 70 }, 71 'image': { 72 action: EasyMDE.drawImage, 73 icon: svg('octicon-image'), 74 title: 'Image', 75 }, 76 'table': { 77 action: EasyMDE.drawTable, 78 icon: svg('octicon-table'), 79 title: 'Table', 80 }, 81 'horizontal-rule': { 82 action: EasyMDE.drawHorizontalRule, 83 icon: svg('octicon-horizontal-rule'), 84 title: 'Horizontal Rule', 85 }, 86 'preview': { 87 action: EasyMDE.togglePreview, 88 icon: svg('octicon-eye'), 89 title: 'Preview', 90 }, 91 'fullscreen': { 92 action: EasyMDE.toggleFullScreen, 93 icon: svg('octicon-screen-full'), 94 title: 'Fullscreen', 95 }, 96 'side-by-side': { 97 action: EasyMDE.toggleSideBySide, 98 icon: svg('octicon-columns'), 99 title: 'Side by Side', 100 }, 101 102 // gitea's custom actions 103 'gitea-checkbox-empty': { 104 action(e) { 105 const cm = e.codemirror; 106 cm.replaceSelection(`\n- [ ] ${cm.getSelection()}`); 107 cm.focus(); 108 }, 109 icon: svg('gitea-empty-checkbox'), 110 title: 'Add Checkbox (empty)', 111 }, 112 'gitea-checkbox-checked': { 113 action(e) { 114 const cm = e.codemirror; 115 cm.replaceSelection(`\n- [x] ${cm.getSelection()}`); 116 cm.focus(); 117 }, 118 icon: svg('octicon-checkbox'), 119 title: 'Add Checkbox (checked)', 120 }, 121 'gitea-switch-to-textarea': { 122 action: () => { 123 editor.userPreferredEditor = 'textarea'; 124 editor.switchToTextarea(); 125 }, 126 icon: svg('octicon-arrow-switch'), 127 title: 'Revert to simple textarea', 128 }, 129 'gitea-code-inline': { 130 action(e) { 131 const cm = e.codemirror; 132 const selection = cm.getSelection(); 133 cm.replaceSelection(`\`${selection}\``); 134 if (!selection) { 135 const cursorPos = cm.getCursor(); 136 cm.setCursor(cursorPos.line, cursorPos.ch - 1); 137 } 138 cm.focus(); 139 }, 140 icon: svg('octicon-chevron-right'), 141 title: 'Add Inline Code', 142 } 143 }; 144 145 for (const [key, value] of Object.entries(actions)) { 146 if (typeof value !== 'string') { 147 value.name = key; 148 } 149 } 150 151 return actions; 152 }