VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/7.2-wysiwyg-editor-(tiptap)

⇱ WYSIWYG Editor (TipTap) | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

WYSIWYG Editor (TipTap)

This document covers Maho's modern WYSIWYG (What You See Is What You Get) rich text editor implementation using TipTap. The editor provides advanced content editing capabilities across the admin interface, including CMS pages, blocks, product descriptions, email templates, and newsletters. It replaces legacy editors with a modern, extensible JavaScript-based solution that supports custom content types like widgets, variables, and complex layout grids.

For general admin interface architecture, see Admin Architecture. For grid and form components that often contain WYSIWYG fields, see Grid and Form Components.


Architecture Overview

Maho’s WYSIWYG editor leverages TipTap, a modular rich-text editor built on top of ProseMirror. The editor is initialized and managed via a custom JavaScript setup class (tiptapWysiwygSetup) and enriched with Maho-specific extensions for features like directives, widgets, and layout grids.

The architecture integrates:

  • Core TipTap Editor with standard and custom extensions
  • Directive parsing and rendering for Maho template directives (e.g., {{widget ...}}, {{var ...}})
  • Complex layout nodes for columns and bento-style grids
  • Image handling integrated with Maho’s media browser and image rendering backend
  • Synchronization between the visual editor content and a hidden textarea storing raw HTML

Component to Code Mapping


Sources: public/js/mage/adminhtml/wysiwyg/tiptap/setup.js12-39 public/js/mage/adminhtml/wysiwyg/tiptap/extensions.js9-24 public/js/mage/adminhtml/wysiwyg/tiptap/extensions/columns.js15-46 public/js/mage/adminhtml/wysiwyg/tiptap/extensions/bento.js175-265


Initialization and Setup

The tiptapWysiwygSetup class manages the lifecycle of the TipTap editor for each textarea intended as a rich text field. It handles the DOM structure, event bindings, content conversion, and toggling between WYSIWYG and plain HTML modes.

Editor Initialization Sequence


Sources: public/js/mage/adminhtml/wysiwyg/tiptap/setup.js14-39 public/js/mage/adminhtml/wysiwyg/tiptap/setup.js193-338 lib/Maho/Data/Form/Element/Editor.php53-64


Configuration Options

The editor’s configuration is created by Mage_Cms_Model_Wysiwyg_Config and passed as options to the JS setup.

OptionTypeDescription
hiddenbooleanStart editor hidden, showing plain textarea
add_imagesbooleanEnable "Insert Image" button and media browser integration
add_widgetsbooleanEnable widget insertion support
add_variablesbooleanEnable inserting variables (e.g., {{var ...}})
store_idintegerStore context for media browser and directives
directives_urlstringURL endpoint to render directive images
files_browser_window_urlstringURL for media browser dialog
widget_window_urlstringURL for widget chooser dialog
validate_html_urlstringURL for HTML validation service

Sources: public/js/mage/adminhtml/wysiwyg/tiptap/setup.js18-25 app/code/core/Mage/Cms/Model/Wysiwyg/Config.php54-91 lib/Maho/Data/Form/Element/Editor.php137-180


Core Extensions

Maho extends TipTap’s functionality with multiple custom extensions alongside the standard StarterKit.

Included Standard Extensions

  • StarterKit — Basic content nodes: paragraph, heading, bullet list, etc.
  • Table, TableRow, TableCell, TableHeader — Structured table support.
  • BubbleMenu — Contextual menus that appear near selections, e.g., for table or grid interaction.
  • DragHandle — Add drag controls for movable nodes.
  • TextAlign — Text alignment marks.

Maho-Specific Extensions

  • GlobalAttributes — Preserves class and style attributes on most node types to maintain inline and CSS styling through editing cycles.
  • VerticalAlign — Adds vertical-align CSS styling to table cells and headers.
  • MahoColumns, MahoColumn — Implements a CSS Grid based column layout.
  • MahoBentoGrid, MahoBentoCell — Implements complex CSS Grid bento layouts with named template areas.
  • Custom widget nodes for embedding Maho directives (mahoWidgetInline, mahoWidgetBlock).

GlobalAttributes Extension Detail

Preserves class and style attributes on elements such as paragraphs, headings, blockquotes, list items, table elements, and custom layout nodes.

  • Ensures visual consistency and custom CSS can be applied within the editor without loss on serialization.
  • Supports a wide node list including mahoColumns and mahoBentoGrid.

Sources: public/js/mage/adminhtml/wysiwyg/tiptap/extensions.js113-154


Layout Systems

Maho extends TipTap with two distinct but related layout systems leveraging CSS Grid and custom nodes:

1. Column Layouts (MahoColumns)

A block-level extension providing horizontal column layouts with configurable presets and drag-resizable widths.

Preset KeyLabelColumnsGrid Template Columns
2-equal2 Columns21fr 1fr
3-equal3 Columns31fr 1fr 1fr
4-equal4 Columns41fr 1fr 1fr 1fr
sidebar-leftSidebar Left21fr 2fr
sidebar-rightSidebar Right22fr 1fr
wide-centerWide Center31fr 2fr 1fr

The MahoColumns node contains child MahoColumn nodes, each representing a column block.

Sources: public/js/mage/adminhtml/wysiwyg/tiptap/extensions/columns.js15-46


2. Bento Grid Layouts (MahoBentoGrid)

A flexible CSS Grid layout system using named grid template areas to build asymmetric complex grids.

  • Defines areas, columns, and rows attributes to specify the grid template.
  • Contains MahoBentoCell children assigned to named grid areas.
  • Includes built-in presets like hero-2, feature-left, magazine, etc.

Sources: public/js/mage/adminhtml/wysiwyg/tiptap/extensions/bento.js16-19 public/js/mage/adminhtml/wysiwyg/tiptap/extensions/bento.js39-117 public/js/mage/adminhtml/wysiwyg/tiptap/extensions/bento.js175-265


Content Conversion and Synchronization

The editor maintains seamless sync between a plain HTML textarea (that stores content for backend use) and the TipTap editor's structured document model.

MethodDirectionImplementation Details
convertFromPlainPlain textarea → TipTap editorParses raw HTML, escapes directives within attributes, converts standalone directives to maho-widget span/div nodes
convertToPlainTipTap editor → textareaStrips trailing empty paragraph, beautifies HTML (via js-beautify), re-extracts directives from maho-widget nodes to raw directives
syncWysiwygToPlainEditor → Plain textareaCalled on form validation and submit, updates textarea value

Details on Directive Conversion

  • Directives like {{widget type="cms/some_type"}} are replaced by <span data-type="maho-widget" data-directive="{{widget type=&quot;cms/some_type&quot;}}"></span> in the editor content.
  • This allows TipTap to treat directives as atomic nodes and preserve them without interpreting as text.
  • When saving, these nodes are converted back to their raw directive string.

Sources: public/js/mage/adminhtml/wysiwyg/tiptap/setup.js76-128 public/js/mage/adminhtml/wysiwyg/tiptap/setup.js130-157 public/js/mage/adminhtml/wysiwyg/tiptap/setup.js52-65


Image and Widget Handling

MahoWidget Nodes

Custom TipTap nodes (mahoWidgetInline, mahoWidgetBlock) represent Maho template directives embedded in content, such as widgets and variables.

  • Utility functions parseDirective() and renderDirective() handle parsing directive strings (e.g., {{var some_variable}}) into structured objects, and rendering them back into directive strings.
  • Directive image URLs are dynamically generated via renderDirectiveImageUrl() which encodes directives for backend rendering calls.

Media Browser Integration

  • The media browser is invoked for image/file selection, integrated with WYSIWYG buttons if add_images config is true.
  • Image rendering requests for directives are handled via Mage_Adminhtml_Cms_WysiwygController::directiveAction().
  • Image URLs for directive-based images are constructed with embedded encoded directives, enabling dynamic serving of media.

Media Browser Data Flow


Sources: app/code/core/Mage/Adminhtml/controllers/Cms/WysiwygController.php99-131


HTML Validation Service

Maho integrates a W3C Nu HTML Validator service endpoint accessible via the validateHtmlAction in Mage_Adminhtml_Cms_WysiwygController.

  • Strips all template directives before validation.
  • Supports an ignore list from admin config (via XML in app/code/core/Mage/Cms/etc/system.xml) to filter out known harmless validation messages.
  • Returns structured JSON validation results or error messages.
  • Admin forms can trigger validator via a "Validate HTML" button.

Sources: app/code/core/Mage/Adminhtml/controllers/Cms/WysiwygController.php24-94 app/code/core/Mage/Cms/etc/system.xml75-92


Styling System

The editor's UI and content area styling is implemented using a CSS custom properties based stylesheet (tiptap.css), which controls colors, spacing, typography, and button styles consistently.

CSS Custom PropertyDescription
--tt-color-textPrimary text color
--tt-color-text-mutedMuted text and icon colors
--tt-color-borderBorder colors for wrapper and controls
--tt-btn-sizeStandard toolbar button size
--tt-font-monoDedicated monospace font for code blocks
--tt-shadow-*Box shadows for UI elements

The toolbar also uses subtle animations for hover, active, disabled, and active states with tooltips. The content area uses ProseMirror's class conventions with margin and padding rules for headings, paragraphs, lists, and blockquotes.

Sources: public/js/mage/adminhtml/wysiwyg/tiptap/tiptap.css3-35 public/js/mage/adminhtml/wysiwyg/tiptap/tiptap.css41-50 public/js/mage/adminhtml/wysiwyg/tiptap/tiptap.css199-210


Summary Diagram: WYSIWYG Editor Data Flow

This diagram summarizes the interactions between the Maho WYSIWYG Editor architecture components, bridging the natural language/domain concepts with actual code entities.


Sources: Combined from all files listed above.


References to Key Files

ComponentFile & Line Reference
TipTap Editor Setup Classpublic/js/mage/adminhtml/wysiwyg/tiptap/setup.js:12-39
TipTap Core & Extensions Exportpublic/js/mage/adminhtml/wysiwyg/tiptap/extensions.js:9-24
Columns Node Extensionpublic/js/mage/adminhtml/wysiwyg/tiptap/extensions/columns.js:15-46
Bento Grid Node Extensionpublic/js/mage/adminhtml/wysiwyg/tiptap/extensions/bento.js:175-265
WYSIWYG Controller (Backend API)app/code/core/Mage/Adminhtml/controllers/Cms/WysiwygController.php:24-94 and :99-131
WYSIWYG Config Modelapp/code/core/Mage/Cms/Model/Wysiwyg/Config.php:54-91
CSS Stylingpublic/js/mage/adminhtml/wysiwyg/tiptap/tiptap.css:1-257 (full file)

Conclusion

Maho’s TipTap-based WYSIWYG Editor system provides a modern, extensible, and well-integrated rich text editing experience in the admin interface. By combining robust content synchronization, advanced layout nodes, flexible directive support, and a cohesive media handling strategy, Maho delivers an editor capable of handling complex content structures typical for e-commerce CMS and product content management.


End of 7.2 - WYSIWYG Editor (TipTap)


Sources:

  • public/js/mage/adminhtml/wysiwyg/tiptap/setup.js
  • public/js/mage/adminhtml/wysiwyg/tiptap/extensions.js
  • public/js/mage/adminhtml/wysiwyg/tiptap/extensions/columns.js
  • public/js/mage/adminhtml/wysiwyg/tiptap/extensions/bento.js
  • app/code/core/Mage/Adminhtml/controllers/Cms/WysiwygController.php
  • app/code/core/Mage/Cms/Model/Wysiwyg/Config.php
  • public/js/mage/adminhtml/wysiwyg/tiptap/tiptap.css