| @@ -1,5 +1,6 @@ | ||
| 1 | -import '../../editor' | |
| 1 | +import { __ } from '@wordpress/i18n' | |
| 2 | +import '../../entries/editor' | |
| 2 | 3 | |
| 3 | 4 | const parseSelect = (select: HTMLSelectElement) => select.options[select.selectedIndex].value |
| 4 | 5 | const parseCheckbox = (checkbox: HTMLInputElement) => checkbox.checked |
| 5 | 6 | const parseNumber = (input: HTMLInputElement) => parseInt(input.value, 10) |
| @@ -7,10 +8,14 @@ | ||
| 7 | 8 | const initialiseCodeMirror = () => { |
| 8 | 9 | const { codeEditor } = window.wp |
| 9 | 10 | const textarea = document.getElementById('code_snippets_editor_preview') |
| 10 | 11 | |
| 11 | - if (textarea) { | |
| 12 | + if (textarea && codeEditor) { | |
| 12 | 13 | window.code_snippets_editor_preview = codeEditor.initialize(textarea) |
| 14 | + | |
| 15 | + // CodeMirror's own input is unlabelled; name it so the preview reads as what it is. | |
| 16 | + window.code_snippets_editor_preview.codemirror.getInputField().setAttribute('aria-label', __('Code editor preview', 'code-snippets')) | |
| 17 | + | |
| 13 | 18 | return window.code_snippets_editor_preview.codemirror |
| 14 | 19 | } |
| 15 | 20 | |
| 16 | 21 | console.error('Could not initialise CodeMirror on textarea.', textarea) |