|
11 | 11 |
|
12 | 12 | ## Description |
13 | 13 |
|
14 | | -The `TextEditorPluginSlot` is rendered inside the Text Editor modal window for HTML XBlocks. |
| 14 | +The `TextEditorPluginSlot` is rendered inside the Text Editor modal window for HTML XBlocks. |
| 15 | +By default, the slot is **empty**. |
15 | 16 | It is intended as a generic extension point that can host **any React component** – for example: |
16 | 17 |
|
17 | 18 | - **Contextual helpers** (tips, validation messages, writing guides) |
18 | 19 | - **Content utilities** (templates, reusable snippets, glossary insert tools) |
19 | 20 | - **Integrations** (linking to external systems, analytics, metadata editors) |
20 | 21 |
|
21 | | -By default, the slot is **empty**. Widgets are attached via `env.config.jsx` using the |
22 | | -`@openedx/frontend-plugin-framework`. |
23 | | - |
24 | | -The only prop your component receives from the slot is: |
25 | | - |
26 | | -- `blockType` – the current editor block type (for this slot it will typically be `html`). |
27 | | - |
28 | 22 | Your component is responsible for interacting with the editor (if needed) using Redux state, |
29 | 23 | DOM APIs, or other utilities provided by `frontend-app-authoring`. |
30 | 24 |
|
| 25 | +#### Interacting with Editor State |
| 26 | + |
| 27 | +```jsx |
| 28 | +import { useSelector } from 'react-redux'; |
| 29 | +import { selectors } from 'CourseAuthoring/editors/data/redux'; |
| 30 | + |
| 31 | +const MyComponent = ({ blockType }) => { |
| 32 | + // Read editor state |
| 33 | + const showRawEditor = useSelector(selectors.app.showRawEditor); |
| 34 | + const blockValue = useSelector(selectors.app.blockValue); |
| 35 | + |
| 36 | + // Update CodeMirror (raw editor) |
| 37 | + const updateRawContent = (content) => { |
| 38 | + const cm = document.querySelector('.CodeMirror')?.CodeMirror; |
| 39 | + if (cm?.dispatch) { |
| 40 | + cm.dispatch(cm.state.update({ |
| 41 | + changes: { from: 0, to: cm.state.doc.length, insert: content } |
| 42 | + })); |
| 43 | + } |
| 44 | + }; |
| 45 | + |
| 46 | + return <button onClick={() => showRawEditor ? updateRawContent('<p>New content</p>') : updateContent('<p>New content</p>')}> |
| 47 | + Update Editor |
| 48 | + </button>; |
| 49 | +}; |
| 50 | +``` |
| 51 | +
|
31 | 52 | ## Examples |
32 | 53 |
|
33 | 54 | ### Default content |
|
0 commit comments