(editor: Editable)
| 5 | import { Translation } from 'react-i18next' |
| 6 | |
| 7 | export const createContextMenuItems = (editor: Editable) => { |
| 8 | const { selection } = editor |
| 9 | let isDisabled = !selection || Range.isCollapsed(selection) |
| 10 | if (isDisabled) { |
| 11 | const voidNode = Editor.above(editor, { |
| 12 | match: n => Editor.isVoid(editor, n), |
| 13 | }) |
| 14 | if (voidNode) isDisabled = false |
| 15 | } |
| 16 | |
| 17 | const items: ContextMenuItem[] = [ |
| 18 | { |
| 19 | key: 'cut', |
| 20 | icon: <Icon name="cut" />, |
| 21 | title: <Translation>{t => t('playground.editor.base.cut')}</Translation>, |
| 22 | rightText: Hotkey.format('mod+x'), |
| 23 | disabled: isDisabled, |
| 24 | onSelect() { |
| 25 | editor.cut() |
| 26 | }, |
| 27 | }, |
| 28 | { |
| 29 | key: 'copy', |
| 30 | icon: <Icon name="copy" />, |
| 31 | title: <Translation>{t => t('playground.editor.base.copy')}</Translation>, |
| 32 | rightText: Hotkey.format('mod+c'), |
| 33 | disabled: isDisabled, |
| 34 | onSelect() { |
| 35 | editor.copy() |
| 36 | }, |
| 37 | }, |
| 38 | { |
| 39 | key: 'paste', |
| 40 | icon: <Icon name="paste" />, |
| 41 | title: <Translation>{t => t('playground.editor.base.paste')}</Translation>, |
| 42 | rightText: Hotkey.format('mod+v'), |
| 43 | disabled: !selection, |
| 44 | onSelect() { |
| 45 | editor.insertFromClipboard() |
| 46 | }, |
| 47 | }, |
| 48 | { |
| 49 | key: 'paste-text', |
| 50 | icon: <Icon name="pasteText" />, |
| 51 | title: <Translation>{t => t('playground.editor.base.paste-text')}</Translation>, |
| 52 | rightText: Hotkey.format('mod+shift+v'), |
| 53 | disabled: !selection, |
| 54 | onSelect() { |
| 55 | editor.insertTextFromClipboard() |
| 56 | }, |
| 57 | }, |
| 58 | ] |
| 59 | const grid = Grid.above(editor) |
| 60 | if (grid) { |
| 61 | items.push( |
| 62 | { |
| 63 | type: 'separator', |
| 64 | }, |
no outgoing calls
no test coverage detected
searching dependent graphs…