Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ Private image storage for alt text (`ai.altText.allowPrivateOrigins`, config onl

## Editor field extras

- Markdown shortcuts (`editor/markdown-shortcuts*.{js,mjs}`), find and replace (`shared/find-replace.mjs` + `FindReplacePanel`, CSS Custom Highlight `mex-find`), shortcuts dialog (Ctrl/Cmd+/), focus mode, `BlockSelectionBar` (Editor.js `.ce-block--selected`), quality panel (`QualityPanel`, `useQualityIssues`) with preset violations, `lang`/`dir` from the content locale. The image tool is `MexImageTool` (`tools/alt-text.js`, subclass of `@editorjs/image` adding alt text, the decorative flag and the focal point control). Media tools (`tools/media.js`: `GalleryTool`, `VideoTool`, `AudioTool`; pure logic in `tools/media-logic.mjs`; focal point control `tools/focal-point.js`: disclosure button, click/tap on the preview, arrow keys 1 % / Shift 10 %, reset, polite live value) open the Strapi Media Library dialog through `openMediaLibrary({ multiple, allowedTypes: ['images'|'videos'|'audios'|'files'], accept(asset), onSelect(assets) })`; `EditorField` filters the picked assets with `accept` and returns focus to the trigger. They are offered only with `plugin::upload.read` (`config.permissions.mediaLibrary`, tool config `canBrowse`); without it they are hidden from the toolbox and existing blocks explain why no files can be chosen. Gallery: add (multiple), move earlier/later, remove, per-image alt (default: the file's Media Library alternative text; `requireAlt`/decorative as in the image block), caption, focal point, layout and columns. Video/audio: choose/replace, title, caption, loop (+ muted and poster for video), WebVTT tracks (kind, language defaulting to the content locale, label, one default).
- Markdown shortcuts (`editor/markdown-shortcuts*.{js,mjs}`), find and replace (`shared/find-replace.mjs` + `FindReplacePanel`, CSS Custom Highlight `mex-find`), shortcuts dialog (Ctrl/Cmd+Alt+/; Ctrl/Cmd+/ is the Editor.js block menu), focus mode, `BlockSelectionBar` (Editor.js `.ce-block--selected`), quality panel (`QualityPanel`, `useQualityIssues`) with preset violations, `lang`/`dir` from the content locale. The image tool is `MexImageTool` (`tools/alt-text.js`, subclass of `@editorjs/image` adding alt text, the decorative flag and the focal point control). Media tools (`tools/media.js`: `GalleryTool`, `VideoTool`, `AudioTool`; pure logic in `tools/media-logic.mjs`; focal point control `tools/focal-point.js`: disclosure button, click/tap on the preview, arrow keys 1 % / Shift 10 %, reset, polite live value) open the Strapi Media Library dialog through `openMediaLibrary({ multiple, allowedTypes: ['images'|'videos'|'audios'|'files'], accept(asset), onSelect(assets) })`; `EditorField` filters the picked assets with `accept` and returns focus to the trigger. They are offered only with `plugin::upload.read` (`config.permissions.mediaLibrary`, tool config `canBrowse`); without it they are hidden from the toolbox and existing blocks explain why no files can be chosen. Gallery: add (multiple), move earlier/later, remove, per-image alt (default: the file's Media Library alternative text; `requireAlt`/decorative as in the image block), caption, focal point, layout and columns. Video/audio: choose/replace, title, caption, loop (+ muted and poster for video), WebVTT tracks (kind, language defaulting to the content locale, label, one default).
- Field readiness and edits (`editor/input-tracking.mjs`): the field reports content to the form only after the person edited it (Editor.js also reports its normalisation of stored content on the first render). User input (`pointerdown`, `keydown`, `input`, `paste`, `drop`, capture phase on the holder) is tracked from before Editor.js renders, and edits made while Editor.js was starting are saved on `onReady`; after the Content Manager's create -> edit redirect several fields mount at once and text typed before the field's own effects ran used to stay out of the form (Save stayed disabled). The holder (`[data-testid="magic-editor-x"]`) carries `aria-busy="true"` while loading and `data-mex-ready="true"` once Editor.js is ready and every listener is attached; browser tests wait for `data-mex-ready` instead of sleeping.
- Editor styles (`editor/tools/styles.js`) are one global style rendered by the first mounted field only (`editor/style-owners.mjs`, `SharedEditorStyles`); one copy per field made styled-components rebuild every copy on each mount and unmount (seconds of blocked main thread on pages with several fields).
- `apply-remote.js`: default tune values count as "no tune" in `blockKey` (`shared/default-tunes.mjs`); more than 150 changed blocks (and a quarter of the document) are applied with one `render` instead of per-block updates (Editor.js notifies every block on each mutation).
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [Unreleased]

### Fixed (editor field: keyboard, typing speed, paste, live session)

- **Keyboard path to the block menu.** Ctrl/Cmd+/ opened the plugin's shortcut help, which blocked Editor.js' own shortcut for the block menu, and the **+** and block menu (⋮⋮) handles had no role, name or tab stop. Ctrl/Cmd+/ opens the block menu of the current block again; the shortcut help moved to **Ctrl/Cmd+Alt+/** (also More tools > Keyboard shortcuts). Both handles are buttons with names ("Add a block", "Open the block menu") that open with Enter or Space. The shortcut help and the README list the keyboard path.
- **Controls inside blocks were not reachable by keyboard.** Editor.js moves Tab and the arrow keys only between text inputs, so the audio and video Choose buttons, the person photo, the toggle's show/hide, the column style and layout, the button block's style and "new tab", and the inputs, select and switch of component blocks were skipped. Tab and Shift+Tab now stop on them in document order, the arrow keys stop on a control Editor.js would skip (not on selects), tools that use Tab themselves (lists, tables, code) keep it, and every control in a block shows a focus ring.
- **Typing lag in long documents.** Every keystroke sanitised the whole document with DOMPurify several times (form value, rendered key, draft fingerprint) and compared it in canonical JSON: about 150 ms per key at 2,000 blocks. The inline sanitiser and the canonical JSON of blocks are cached by input (same output, so the same security; the server still sanitises on save), Editor.js' save and the form update run in separate tasks, the field's panels update as a React transition, and the draft fingerprints are only computed after signing in again. At 2,000 blocks a keystroke now takes p95 about 40 ms with no task over 50 ms (see the PR for the measurements).
- **Bold from Word was lost on paste.** Word writes `<b style='mso-bidi-font-weight:normal'>` and the check for Google Docs' `<b style="font-weight:normal">` wrapper matched the text `font-weight:normal` inside the other property. Inline styles are now read by exact property name, everywhere in the HTML import.
- **"Discard changes" in the live session notice removed other people's text without asking.** It now asks first in a Strapi confirmation that says it affects everyone editing the field, then shows a notice with **Undo** (focused) that puts the previous text back for everyone. People in the same session get a notice that the field went back to the saved content, with **Restore my text**.

## [2.8.1](https://github.com/Schero94/Magic-Editor-X/compare/v2.8.0...v2.8.1) (2026-11-20)


Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ All screenshots use synthetic data (captured on Strapi 5.61.1 and 5.62.0; accept
| Version history | More tools > Version history, for a saved document | `access` and Content Manager read on the document; saving, naming and restoring need update. The Activity tab needs `audit.read`. |
| Find and replace | More tools > Find and replace, or Ctrl/Cmd+Shift+F in the editor | Everyone who can read the field; replacing needs update. |
| Quality checks | More tools > Quality checks (the number counts problems) | Everyone who can read the field; the link check needs `access`. |
| Keyboard shortcuts, focus mode | More tools > Keyboard shortcuts or Focus mode, or Ctrl/Cmd+/ | Everyone who can read the field. |
| Keyboard shortcuts, focus mode | More tools > Keyboard shortcuts or Focus mode, or Ctrl/Cmd+Alt+/ | Everyone who can read the field. |
| Field options | Content-Type Builder, Magic Editor X field, Basic and Advanced settings | Content-Type Builder access (development mode). |
| AI assistant | Inline toolbar (select text), or a block's menu, the block selection bar or Ctrl/Cmd+Shift+G for whole blocks | `access` and `ai.use`, when an administrator turned the assistant on. |
| AI for the whole field | More tools > AI for the whole field | `access` and `ai.use`, when the owner allowed whole-field AI actions and the field does not turn AI off. |
Expand Down Expand Up @@ -502,7 +502,7 @@ Changing a preset never changes stored content by itself. Turning `sanitizeOnSav
| More tools menu | The field toolbar shows undo, redo, **More tools** and full screen. More tools groups the other tools: **Review** (comments, version history, suggestions, quality checks), **Write** (suggest changes, AI for the whole field, check grammar, find and replace, insert template) and **View** (preview, focus mode, keyboard shortcuts). Entries appear only where they can work (permission, settings, field options); counts show in the menu, and a tool that changes the view (preview, focus mode) adds a visible way back to the bar. Keyboard shortcuts are unchanged. |
| Markdown shortcuts | At the start of an empty paragraph: `#` to `######` + Space (heading), `-`, `*` or `+` + Space (bulleted list), `1.` + Space (numbered list, other numbers set the start), `[]` or `[x]` + Space (checklist), `>` + Space (quote), ` ``` ` (optionally with a language) + Enter (code block), `---` + Enter (delimiter). While typing: `**bold**`, `__bold__`, `*italic*`, `_italic_`, `~~strike~~`, `` `code` ``. Never inside code, raw HTML or tables; only blocks and marks the field allows. |
| Find and replace | Magnifier button or Ctrl/Cmd+Shift+F. Searches every text block, list item, table cell, caption and code block; keeps formatting; match case, whole words, regular expressions (off by default, patterns up to 200 characters). Enter / Shift+Enter move between matches, the current match is highlighted. Replacements are normal edits (undo, collaboration). A match cannot span differently formatted text. |
| Keyboard shortcuts | Ctrl/Cmd+/ or More > Keyboard shortcuts: editor, block and inline tool shortcuts and the Markdown shortcuts of this field. |
| Keyboard shortcuts | Ctrl/Cmd+Alt+/ or More > Keyboard shortcuts: editor, block and inline tool shortcuts and the Markdown shortcuts of this field. Keyboard path to blocks: Ctrl/Cmd+/ opens the block menu of the current block (move, delete, convert), `/` or Tab in an empty block chooses a block type, Tab and the arrow keys reach the buttons and options inside blocks, and the **+** and block menu handles are buttons with names. |
| Focus mode | More > Focus mode: full screen, narrower text column, other blocks dimmed. Escape leaves. |
| Several selected blocks | Select across blocks (Shift+Arrow at a block edge, Ctrl/Cmd+A twice, or drag across blocks): move up or down, duplicate, copy as Markdown, delete, convert to text, heading, list or quote. |
| Counts | Blocks, words, characters and reading time (200 words per minute) in the toolbar, with the field's limits. |
Expand Down
100 changes: 90 additions & 10 deletions admin/src/components/EditorField/RoomNotice.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { useEffect, useRef } from 'react';
import { Box, Button, Flex, Typography } from '@strapi/design-system';
import styled from 'styled-components';
import { ConfirmAction } from '../ui/ConfirmAction';

/**
* In-field notice (2.7.4): the live collaboration room still held changes nobody saved (a room
* keeps them for `roomTtlMinutes`). The field shows them and marks the form as changed, so the
* Save button stores what is shown; this notice says so in one sentence. Discard brings the stored
* value back in the editor, the form and the room. Same placement and look as the draft notice.
*
* 2.7.8 (re-audit major 5): Discard affects everyone in the live session, so it asks first (Strapi
* ConfirmDialog that says so). Afterwards `RoomResetNotice` offers Undo to the person who
* discarded and tells the others in the room what happened, with a way to put their text back.
*/

const Bar = styled(Box)`
Expand All @@ -16,11 +22,12 @@ const Bar = styled(Box)`
/**
* @param {object} props - Props.
* @param {Function} props.t - Translator.
* @param {() => void} props.onDiscard - Restores the stored value.
* @param {() => Promise<void>} props.onDiscard - Restores the stored value (after confirmation).
* @param {boolean} props.disabled - The editor is read-only.
* @param {{ current: HTMLElement|null }} [props.fallbackFocusRef] - Focus after Discard (the notice is gone then).
* @returns {JSX.Element} Notice.
*/
export const RoomNotice = ({ t, onDiscard, disabled }) => (
export const RoomNotice = ({ t, onDiscard, disabled, fallbackFocusRef }) => (
<Bar
background="primary100"
paddingTop={2}
Expand All @@ -38,17 +45,90 @@ export const RoomNotice = ({ t, onDiscard, disabled }) => (
)}
</Typography>
</Box>
<Button
variant="tertiary"
size="S"
onClick={onDiscard}
<ConfirmAction
trigger={
<Button variant="tertiary" size="S" disabled={disabled} data-testid="mex-room-discard">
{t('editor.room.discard', 'Discard changes')}
</Button>
}
disabled={disabled}
data-testid="mex-room-discard"
>
{t('editor.room.discard', 'Discard changes')}
</Button>
title={t('editor.room.discardTitle', 'Discard the unsaved changes for everyone?')}
body={t(
'editor.room.discardBody',
'The saved content comes back in this field for everyone editing this entry right now. Their unsaved text in this field is removed too. You can undo this right after.'
)}
confirmLabel={t('editor.room.discardConfirm', 'Discard for everyone')}
onConfirm={onDiscard}
fallbackFocusRef={fallbackFocusRef}
/>
</Flex>
</Bar>
);

/**
* Notice after the unsaved changes of a live session were discarded (2.7.8).
* `kind: 'self'`: this person discarded them; Undo puts the previous text back for everyone.
* `kind: 'remote'`: someone else in the session did; Restore puts the previous text back.
* @param {object} props - Props.
* @param {Function} props.t - Translator.
* @param {'self'|'remote'} props.kind - Who discarded.
* @param {() => void} props.onUndo - Puts the previous text back.
* @param {() => void} props.onDismiss - Closes the notice.
* @param {boolean} [props.autoFocus] - Focus Undo on mount (after the confirmation closed).
* @param {{ current: HTMLElement|null }} [props.undoRef] - Ref of the Undo button.
* @param {boolean} [props.disabled] - The editor is read-only.
* @returns {JSX.Element} Notice.
*/
export const RoomResetNotice = ({
t,
kind,
onUndo,
onDismiss,
autoFocus = false,
undoRef,
disabled = false,
}) => {
const ownRef = useRef(null);
const ref = undoRef || ownRef;
useEffect(() => {
if (autoFocus && ref.current) ref.current.focus();
}, [autoFocus, ref]);
return (
<Bar
background="neutral100"
paddingTop={2}
paddingBottom={2}
paddingLeft={3}
paddingRight={3}
data-testid="mex-room-reset-notice"
>
<Flex gap={2} wrap="wrap" alignItems="center" justifyContent="space-between">
<Box minWidth={0} flex="1 1 24rem" role="status">
<Typography variant="omega" textColor="neutral800">
{kind === 'self'
? t(
'editor.room.discarded',
'The unsaved changes were discarded for everyone. This field shows the saved content.'
)
: t(
'editor.room.discardedRemote',
'Someone in this live session brought this field back to the saved content. Your unsaved text in this field was removed.'
)}
</Typography>
</Box>
<Flex gap={2} wrap="wrap">
<Button variant="secondary" size="S" ref={ref} onClick={onUndo} disabled={disabled}>
{kind === 'self'
? t('editor.room.undoDiscard', 'Undo')
: t('editor.room.restoreText', 'Restore my text')}
</Button>
<Button variant="tertiary" size="S" onClick={onDismiss}>
{t('editor.room.dismiss', 'Dismiss')}
</Button>
</Flex>
</Flex>
</Bar>
);
};

export default RoomNotice;
Loading