From c52eb627840a18db2a7752ca6c29df6257a09700 Mon Sep 17 00:00:00 2001 From: Schero94 <64200582+Schero94@users.noreply.github.com> Date: Fri, 20 Nov 2026 15:54:43 +0100 Subject: [PATCH] fix(admin): native Strapi look in the editor field (DS icons, tabs, tooltips, tokens) - @strapi/icons for the tool icons with an equivalent, rendered to static markup once (Editor.js takes icon strings); own SVG only where the DS has no match. - Undo: mirrored DS ArrowClockwise (no undo/redo icon in @strapi/icons 2.3). - Version history: DS Tabs variant "simple" (underlined). - Gutter markers: DS Tooltip instead of native title. - Annotation Apply: buttonPrimary600/500 and buttonNeutral0. - Full screen: Tab wraps inside the modal editor (DS FocusTrap logic). - theme.fonts.code removed (the DS theme has no font tokens). Docs read: @strapi/icons 2.3.1 (icons use styled-components useTheme for token fills), react-dom 18 renderToStaticMarkup, DS 2.3.1 Tabs (variant regular|simple), Tooltip, FocusTrap, Button token usage. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 12 +++ .../components/EditorField/CommentMarkers.jsx | 32 ++++---- .../components/EditorField/EditorToolbar.jsx | 7 +- .../components/EditorField/HistoryModal.jsx | 2 + .../EditorField/ShortcutsDialog.jsx | 3 +- .../components/EditorField/SuggestEditor.jsx | 6 +- .../EditorField/SuggestionMarkers.jsx | 34 ++++---- admin/src/components/EditorField/icons.jsx | 13 +++ admin/src/components/EditorField/index.jsx | 30 +++++++ .../src/components/RenderedContent/index.jsx | 3 +- admin/src/editor/code-font.mjs | 6 ++ admin/src/editor/tools/dom.js | 68 +++++++--------- admin/src/editor/tools/ds-icons.js | 80 +++++++++++++++++++ admin/src/editor/tools/inline-format.js | 5 +- admin/src/editor/tools/styles.js | 30 ++++--- admin/src/editor/tools/table.js | 5 +- tests/admin/native-feel.test.jsx | 59 ++++++++++++++ 17 files changed, 302 insertions(+), 93 deletions(-) create mode 100644 admin/src/components/EditorField/icons.jsx create mode 100644 admin/src/editor/code-font.mjs create mode 100644 admin/src/editor/tools/ds-icons.js create mode 100644 tests/admin/native-feel.test.jsx diff --git a/CHANGELOG.md b/CHANGELOG.md index e9dfcbe..172ff87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [Unreleased] + +### Changed (editor field: native Strapi look) + +- **Strapi Design System icons in the editor.** Block types, block menus and tool buttons use @strapi/icons where an equivalent exists (code, image, gallery, video, audio, link, Media Library, person, table, component, copy, delete, add, upload, check, colour, AI, underline, strikethrough, arrows, warning, table of contents); the editor-specific shapes (alignment, columns, borders, merge and split, sub- and superscript) keep their own icons. +- **Undo and redo** use one DS arrow, mirrored for undo (the two-arrow icon read as "refresh"). @strapi/icons has no undo or redo icon. +- **Version history** uses the DS underlined tabs (`variant="simple"`, as the Content Manager's Draft and Published tabs). +- **Comment and suggestion markers** show a DS tooltip instead of the browser's `title`. +- **Annotation Apply** uses the DS primary button colours in both themes. +- **Full screen** keeps Tab inside the editor (it is a modal dialog), like the DS focus trap. +- **Code font.** The Design System theme has no font tokens; the shortcut help and the preview read a plugin constant instead of the undefined `theme.fonts.code`. + ## [2.8.3](https://github.com/Schero94/Magic-Editor-X/compare/v2.8.2...v2.8.3) (2026-11-20) diff --git a/admin/src/components/EditorField/CommentMarkers.jsx b/admin/src/components/EditorField/CommentMarkers.jsx index b28b0a7..50555ce 100644 --- a/admin/src/components/EditorField/CommentMarkers.jsx +++ b/admin/src/components/EditorField/CommentMarkers.jsx @@ -1,5 +1,6 @@ import { useLayoutEffect, useRef, useState } from 'react'; import { Discuss } from '@strapi/icons'; +import { Tooltip } from '@strapi/design-system'; import styled from 'styled-components'; /** @@ -114,26 +115,29 @@ export const CommentMarkers = ({ containerRef, holderRef, counts, blockIds, vers return ( {positions.map(({ blockId, count, top, index }) => ( - onOpen(blockId)} > - + onOpen(blockId)} + > + + ))} ); diff --git a/admin/src/components/EditorField/EditorToolbar.jsx b/admin/src/components/EditorField/EditorToolbar.jsx index e4236a1..ae4874f 100644 --- a/admin/src/components/EditorField/EditorToolbar.jsx +++ b/admin/src/components/EditorField/EditorToolbar.jsx @@ -9,7 +9,8 @@ import { Typography, VisuallyHidden, } from '@strapi/design-system'; -import { ArrowClockwise, ArrowsCounterClockwise, Collapse, Expand } from '@strapi/icons'; +import { Collapse, Expand } from '@strapi/icons'; +import { RedoIcon, UndoIcon } from './icons'; import styled from 'styled-components'; import { FieldToolsMenu } from './FieldToolsMenu'; import { exitTools } from '../../editor/field-tools.mjs'; @@ -136,7 +137,7 @@ export const EditorToolbar = ({ onClick={onUndo} disabled={!ready || !canUndo} > - + - + )} diff --git a/admin/src/components/EditorField/HistoryModal.jsx b/admin/src/components/EditorField/HistoryModal.jsx index fa2c7f5..9d00f13 100644 --- a/admin/src/components/EditorField/HistoryModal.jsx +++ b/admin/src/components/EditorField/HistoryModal.jsx @@ -429,6 +429,8 @@ export const HistoryModal = ({ {preview.content ? ( (value === 'changes' ? showChanges() : setTab('preview'))} > diff --git a/admin/src/components/EditorField/ShortcutsDialog.jsx b/admin/src/components/EditorField/ShortcutsDialog.jsx index c95d3f3..7741841 100644 --- a/admin/src/components/EditorField/ShortcutsDialog.jsx +++ b/admin/src/components/EditorField/ShortcutsDialog.jsx @@ -1,6 +1,7 @@ import { Box, Button, Flex, Modal, Typography } from '@strapi/design-system'; import styled from 'styled-components'; import { shortcutKeyName } from '../../editor/field-tools.mjs'; +import { CODE_FONT } from '../../editor/code-font.mjs'; /** * Keyboard shortcut help (Ctrl/Cmd + Alt + /; 2.7.8: Ctrl/Cmd + / opens the Editor.js block menu). Lists the editor's own shortcuts, @@ -9,7 +10,7 @@ import { shortcutKeyName } from '../../editor/field-tools.mjs'; const Keys = styled.kbd` display: inline-block; - font-family: ${({ theme }) => theme.fonts?.code || 'monospace'}; + font-family: ${CODE_FONT}; font-size: ${({ theme }) => theme.fontSizes[1]}; color: ${({ theme }) => theme.colors.neutral800}; background: ${({ theme }) => theme.colors.neutral100}; diff --git a/admin/src/components/EditorField/SuggestEditor.jsx b/admin/src/components/EditorField/SuggestEditor.jsx index f489055..d1266b2 100644 --- a/admin/src/components/EditorField/SuggestEditor.jsx +++ b/admin/src/components/EditorField/SuggestEditor.jsx @@ -11,7 +11,7 @@ import { Textarea, Typography, } from '@strapi/design-system'; -import { ArrowClockwise, ArrowsCounterClockwise } from '@strapi/icons'; +import { RedoIcon, UndoIcon } from './icons'; import styled from 'styled-components'; import { buildTools, disposeTools, editorI18n, createUndoManager, INLINE_TOOLS } from '../../editor/tools'; import { prepareEditorValue } from '../../editor/sanitize'; @@ -364,7 +364,7 @@ export const SuggestEditor = ({ onClick={() => undoRef.current && undoRef.current.undo()} disabled={!ready || !undoState.canUndo} > - + undoRef.current && undoRef.current.redo()} disabled={!ready || !undoState.canRedo} > - + {pending ? ( {positions.map(({ blockId, count, top, index, besideComment }) => ( - onOpen(blockId)} > - + onOpen(blockId)} + > + + ))} ); diff --git a/admin/src/components/EditorField/icons.jsx b/admin/src/components/EditorField/icons.jsx new file mode 100644 index 0000000..4fe3460 --- /dev/null +++ b/admin/src/components/EditorField/icons.jsx @@ -0,0 +1,13 @@ +import { ArrowClockwise } from '@strapi/icons'; +import styled from 'styled-components'; + +/** + * Undo and redo icons (2.7.8). @strapi/icons 2.3 has no undo or redo icon. Redo is + * `ArrowClockwise`; undo is the same icon mirrored, so the pair reads as back and forward (the + * two-arrow `ArrowsCounterClockwise` used before read as "refresh"). + */ +export const UndoIcon = styled(ArrowClockwise)` + transform: scaleX(-1); +`; + +export const RedoIcon = ArrowClockwise; diff --git a/admin/src/components/EditorField/index.jsx b/admin/src/components/EditorField/index.jsx index ed13687..d618467 100644 --- a/admin/src/components/EditorField/index.jsx +++ b/admin/src/components/EditorField/index.jsx @@ -1667,12 +1667,42 @@ const EditorFieldBody = ({ setFocusMode(false); } }; + // 2.7.8: Tab stays inside the full screen editor (role="dialog", aria-modal), the way the DS + // FocusTrap wraps focus: from the last stop to the first and back. Dialogs opened from the + // editor live in their own portal and trap focus themselves. + const onTab = (event) => { + const frame = frameRef.current; + if (event.key !== 'Tab' || event.defaultPrevented || !frame || !frame.contains(document.activeElement)) + return; + const stops = Array.from( + frame.querySelectorAll( + 'a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"]' + ) + ).filter( + (element) => element.getClientRects().length > 0 && !element.closest('[inert], [aria-hidden="true"]') + ); + if (!stops.length) return; + const first = stops[0]; + const last = stops[stops.length - 1]; + const active = document.activeElement; + if (!event.shiftKey && (active === last || last.contains(active))) { + event.preventDefault(); + event.stopPropagation(); + first.focus(); + } else if (event.shiftKey && (active === first || first.contains(active))) { + event.preventDefault(); + event.stopPropagation(); + last.focus(); + } + }; + window.addEventListener('keydown', onTab, true); const previous = document.body.style.overflow; document.body.style.overflow = 'hidden'; document.addEventListener('keydown', onKey); return () => { document.body.style.overflow = previous; document.removeEventListener('keydown', onKey); + window.removeEventListener('keydown', onTab, true); }; }, [fullscreen]); diff --git a/admin/src/components/RenderedContent/index.jsx b/admin/src/components/RenderedContent/index.jsx index 0beff95..9a355f3 100644 --- a/admin/src/components/RenderedContent/index.jsx +++ b/admin/src/components/RenderedContent/index.jsx @@ -5,6 +5,7 @@ import { MagicEditorXContent } from '../../../../shared/frameworks/react.mjs'; import { sanitizeRawPreview } from './sanitize-raw'; import { loadMath } from '../../editor/math-view'; import { MATH_ATTRIBUTE } from '../../../../shared/sanitize-policy.mjs'; +import { CODE_FONT } from '../../editor/code-font.mjs'; /** * Rendered output of Magic Editor X content inside the admin (field preview, @@ -214,7 +215,7 @@ const Prose = styled.div` } & pre, & code { - font-family: ${({ theme }) => (theme.fonts && theme.fonts.code) || 'monospace'}; + font-family: ${CODE_FONT}; font-size: ${({ theme }) => theme.fontSizes[1]}; overflow-wrap: normal; } diff --git a/admin/src/editor/code-font.mjs b/admin/src/editor/code-font.mjs new file mode 100644 index 0000000..0e00044 --- /dev/null +++ b/admin/src/editor/code-font.mjs @@ -0,0 +1,6 @@ +/** + * Monospace font stack for code in the admin (2.7.8). The Strapi Design System 2.3 theme has no + * font tokens (`theme.fonts` does not exist; the DS sets only the body font globally), so the + * plugin keeps one stack here instead of reading an undefined `theme.fonts.code`. + */ +export const CODE_FONT = "'SFMono-Regular', Menlo, Consolas, monospace"; diff --git a/admin/src/editor/tools/dom.js b/admin/src/editor/tools/dom.js index 118b7e8..b7e3718 100644 --- a/admin/src/editor/tools/dom.js +++ b/admin/src/editor/tools/dom.js @@ -4,6 +4,8 @@ * icons below are static strings written in this file (trusted). */ +import { DS_ICONS } from './ds-icons'; + /** * Creates an element. * @param {string} tag - Tag name. @@ -118,49 +120,42 @@ export const editable = ({ return node; }; +/** + * Tool icons. 2.7.8: Strapi Design System icons where @strapi/icons has an equivalent + * (`ds-icons.js`); the hand-drawn SVGs remain for alignment, columns, borders and the other + * editor-specific shapes the DS does not have. + */ export const ICONS = { - alert: - '', + alert: DS_ICONS.alert, toggle: '', - code: '', - person: - '', - image: - '', - gallery: - '', - video: - '', - audio: - '', - arrowLeft: - '', - arrowRight: - '', + code: DS_ICONS.code, + person: DS_ICONS.person, + image: DS_ICONS.image, + gallery: DS_ICONS.gallery, + video: DS_ICONS.video, + audio: DS_ICONS.audio, + arrowLeft: DS_ICONS.arrowLeft, + arrowRight: DS_ICONS.arrowRight, delimiter: '', - link: '', + link: DS_ICONS.link, button: '', entry: '', block: '', - media: - '', + media: DS_ICONS.media, checklist: '', marker: '', - underline: - '', - strike: - '', + underline: DS_ICONS.underline, + strike: DS_ICONS.strike, tooltip: '', - sparkle: - '', + sparkle: DS_ICONS.sparkle, alignLeft: '', alignCenter: @@ -171,15 +166,11 @@ export const ICONS = { '', variant: '', - check: - '', - plus: '', - minus: - '', - upload: - '', - trash: - '', + check: DS_ICONS.check, + plus: DS_ICONS.plus, + minus: DS_ICONS.minus, + upload: DS_ICONS.upload, + trash: DS_ICONS.trash, border: '', background: @@ -188,17 +179,16 @@ export const ICONS = { '', mention: '', - toc: '', + toc: DS_ICONS.toc, lineNumbers: '', math: '', // 2.5: component block (four squares, like a component of fields). - component: - '', + component: DS_ICONS.component, inlineMath: '', footnote: '', // 2.5: "Copy block" in the block menu. - copy: '', + copy: DS_ICONS.copy, }; diff --git a/admin/src/editor/tools/ds-icons.js b/admin/src/editor/tools/ds-icons.js new file mode 100644 index 0000000..05669ab --- /dev/null +++ b/admin/src/editor/tools/ds-icons.js @@ -0,0 +1,80 @@ +import { createElement } from 'react'; +import { renderToStaticMarkup } from 'react-dom/server'; +import { ThemeProvider } from 'styled-components'; +import { + Check, + Code, + Duplicate, + GridFour, + GridNine, + Image, + Images, + Link, + List, + Minus, + MusicNotes, + Palette, + Play, + Plus, + PuzzlePiece, + Sparkle, + StrikeThrough, + Trash, + Underline, + Upload, + User, + WarningCircle, + ArrowLeft, + ArrowRight, +} from '@strapi/icons'; + +/** + * Strapi Design System icons as SVG markup for the Editor.js tools (2.7.8, native look). Editor.js + * takes icons as strings (toolbox `icon`, tune and popover items, `innerHTML` of tool buttons), so + * the @strapi/icons React components are rendered once with `renderToStaticMarkup`. The icons read + * `theme.colors` (styled-components `useTheme`) only to map token fills; with `fill="currentColor"` + * an empty theme is enough. Tools keep their own SVG only where @strapi/icons has no match. + */ +const NO_THEME = { colors: {} }; + +/** + * @param {import('react').ComponentType} Icon - @strapi/icons component. + * @param {number} [size=20] - Width and height in px (the Editor.js icon slot). + * @returns {string} SVG markup, `currentColor`, hidden from assistive technology. + */ +export const dsIcon = (Icon, size = 20) => + renderToStaticMarkup( + createElement( + ThemeProvider, + { theme: NO_THEME }, + createElement(Icon, { width: size, height: size, 'aria-hidden': 'true', focusable: 'false' }) + ) + ); + +/** DS icons for the tool icons that have an equivalent in @strapi/icons 2.3. */ +export const DS_ICONS = Object.freeze({ + alert: dsIcon(WarningCircle), + code: dsIcon(Code), + person: dsIcon(User), + image: dsIcon(Image), + gallery: dsIcon(GridFour), + video: dsIcon(Play), + audio: dsIcon(MusicNotes), + arrowLeft: dsIcon(ArrowLeft), + arrowRight: dsIcon(ArrowRight), + link: dsIcon(Link), + media: dsIcon(Images), + underline: dsIcon(Underline), + strike: dsIcon(StrikeThrough), + sparkle: dsIcon(Sparkle), + check: dsIcon(Check), + plus: dsIcon(Plus), + minus: dsIcon(Minus), + upload: dsIcon(Upload), + trash: dsIcon(Trash), + toc: dsIcon(List), + copy: dsIcon(Duplicate), + component: dsIcon(PuzzlePiece), + table: dsIcon(GridNine), + color: dsIcon(Palette), +}); diff --git a/admin/src/editor/tools/inline-format.js b/admin/src/editor/tools/inline-format.js index f79e669..427ec79 100644 --- a/admin/src/editor/tools/inline-format.js +++ b/admin/src/editor/tools/inline-format.js @@ -11,6 +11,7 @@ import { ANNOTATION_VALUE_PREFIX, cleanAnnotationAttributes, } from '../../../../shared/blocks/annotations.mjs'; +import { DS_ICONS } from './ds-icons'; /** * Inline formatting of 2.5, all off unless the field turns it on: @@ -30,9 +31,7 @@ const SVG = (body) => `${body}`; export const FORMAT_ICONS = Object.freeze({ - color: SVG( - '' - ), + color: DS_ICONS.color, superscript: SVG( '' ), diff --git a/admin/src/editor/tools/styles.js b/admin/src/editor/tools/styles.js index 690b170..b03d8f7 100644 --- a/admin/src/editor/tools/styles.js +++ b/admin/src/editor/tools/styles.js @@ -1,5 +1,6 @@ import { css } from 'styled-components'; import { setOpacity } from '@strapi/design-system'; +import { CODE_FONT } from '../code-font.mjs'; /** * Styles for the Editor.js core UI and every tool, scoped under `.mex-editor`. @@ -241,7 +242,7 @@ export const editorStyles = css` color: ${c('neutral800')}; border-radius: ${radius}; padding: 1px ${s(1)}; - font-family: 'SFMono-Regular', Menlo, Consolas, monospace; + font-family: ${CODE_FONT}; font-size: 0.9em; } @@ -757,7 +758,7 @@ export const editorStyles = css` } .ce-code__textarea { - font-family: 'SFMono-Regular', Menlo, Consolas, monospace; + font-family: ${CODE_FONT}; background: ${c('neutral100')}; color: ${c('neutral800')}; min-height: 120px; @@ -1254,7 +1255,7 @@ export const editorStyles = css` } .ce-rawtool__textarea { - font-family: 'SFMono-Regular', Menlo, Consolas, monospace; + font-family: ${CODE_FONT}; background: ${c('neutral100')}; color: ${c('neutral800')}; border-color: ${c('neutral200')}; @@ -1393,7 +1394,7 @@ export const editorStyles = css` /* Inline math (2.4): the TeX source is editable text in a chip. */ .ce-block span[data-mex-math] { - font-family: 'SFMono-Regular', Menlo, Consolas, monospace; + font-family: ${CODE_FONT}; font-size: 0.92em; color: ${c('neutral800')}; background: ${c('secondary100')}; @@ -1449,7 +1450,7 @@ export const editorStyles = css` } .mex-math-tool__input { - font-family: 'SFMono-Regular', Menlo, Consolas, monospace; + font-family: ${CODE_FONT}; min-height: 4.4rem; resize: vertical; width: 100%; @@ -1570,7 +1571,7 @@ export const editorStyles = css` width: auto; padding-block: ${s(1)}; padding-inline: ${s(2)}; - font-family: 'SFMono-Regular', Menlo, Consolas, monospace; + font-family: ${CODE_FONT}; font-size: ${f(1)}; } @@ -1578,7 +1579,7 @@ export const editorStyles = css` flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; - font-family: 'SFMono-Regular', Menlo, Consolas, monospace; + font-family: ${CODE_FONT}; font-size: ${f(1)}; color: ${c('neutral800')}; } @@ -1601,7 +1602,7 @@ export const editorStyles = css` .mex-code__body { display: flex; - font-family: 'SFMono-Regular', Menlo, Consolas, monospace; + font-family: ${CODE_FONT}; font-size: ${f(1)}; line-height: 1.6; } @@ -2670,10 +2671,17 @@ export const editorStyles = css` cursor: pointer; } + /* 2.7.8: the DS default button tokens (white on primary in both themes; neutral0 was dark text + on primary in dark mode). */ .mex-annotation-form__apply { - border: 1px solid ${c('primary600')}; - background: ${c('primary600')}; - color: ${c('neutral0')}; + border: 1px solid ${c('buttonPrimary600')}; + background: ${c('buttonPrimary600')}; + color: ${c('buttonNeutral0')}; + + &:hover { + border-color: ${c('buttonPrimary500')}; + background: ${c('buttonPrimary500')}; + } } .mex-annotation-form__remove { diff --git a/admin/src/editor/tools/table.js b/admin/src/editor/tools/table.js index 33366c0..4a23c41 100644 --- a/admin/src/editor/tools/table.js +++ b/admin/src/editor/tools/table.js @@ -25,6 +25,7 @@ import { splitCell, toTableModel, } from '../../../../shared/table.mjs'; +import { DS_ICONS } from './ds-icons'; /** * Table block (2.4). Replaces @editorjs/table with the same block name and @@ -52,9 +53,7 @@ const ICON = (path) => const S = 'stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"'; const ICONS = { - table: ICON( - `` - ), + table: DS_ICONS.table, headerRow: ICON( `` ), diff --git a/tests/admin/native-feel.test.jsx b/tests/admin/native-feel.test.jsx new file mode 100644 index 0000000..c81aa50 --- /dev/null +++ b/tests/admin/native-feel.test.jsx @@ -0,0 +1,59 @@ +/** + * 2.7.8 native Strapi look (re-audit): DS icons in the Editor.js tools, no `theme.fonts` (the DS + * theme has none), mirrored DS arrow for undo, underlined DS tabs in the version history, DS + * tooltips on the gutter markers, DS default button tokens for the annotation Apply button. + */ +import assert from 'node:assert/strict'; +import { readFileSync, readdirSync, statSync } from 'node:fs'; +import { join } from 'node:path'; +import { test } from 'node:test'; +import { fileURLToPath } from 'node:url'; +import { DS_ICONS, dsIcon } from '../../admin/src/editor/tools/ds-icons.js'; +import { ICONS } from '../../admin/src/editor/tools/dom.js'; +import { Code } from '@strapi/icons'; + +const root = fileURLToPath(new URL('../../admin/src/', import.meta.url)); +const read = (file) => readFileSync(join(root, file), 'utf8'); +const walk = (dir) => + readdirSync(dir).flatMap((entry) => { + const path = join(dir, entry); + return statSync(path).isDirectory() ? walk(path) : /\.(jsx?|mjs)$/.test(entry) ? [path] : []; + }); + +test('DS icons render to static, decorative SVG in currentColor', () => { + const svg = dsIcon(Code); + assert.match(svg, /^