spatie/laravel-mailcoach-monaco
Adds the Monaco code editor to Mailcoach, providing a powerful editing experience for email templates with syntax highlighting and modern IDE-like features. Install alongside Mailcoach and select Monaco as your editor in the Mailcoach configuration.
Installation:
composer require spatie/laravel-mailcoach-monaco
Ensure spatie/laravel-mailcoach is also installed (this package is an editor extension for Mailcoach).
Configuration:
php artisan vendor:publish --provider="Spatie\MailcoachMonaco\MailcoachMonacoServiceProvider"
config/mailcoach.php to set 'editor' => 'monaco' under the mailcoach key.First Use Case:
Editor Integration:
mailcoach.emails.edit view).@mailcoachEditor
This directive injects the Monaco editor into the template form.Customizing Editor Options:
mailcoach-monaco config:
'monaco' => [
'theme' => 'vs-dark', // 'vs', 'vs-dark', or custom themes
'language' => 'html', // Default language mode
'options' => [
'fontSize' => 14,
'wordWrap' => 'on',
],
],
window.MailcoachMonacoOptions = {
theme: 'my-custom-theme',
minimap: { enabled: false },
};
Extending Functionality:
Add Language Support: Register custom languages (e.g., for handlebars templates) by extending Monaco’s language definitions:
monaco.languages.register({ id: 'handlebars' });
monaco.languages.setMonarchTokensProvider('handlebars', yourTokensProvider);
Load these in a custom JS file included in your Mailcoach assets.
Custom Keybindings:
Override or extend Monaco’s keybindings via the keybindings config array:
'keybindings' => [
'cmd+shift+p' => 'editor.action.quickCommand',
],
Asset Management:
resources/js/mailcoach-monaco.js exists and is compiled.'assets' => [
'js' => 'custom/monaco-editor.js',
'css' => 'custom/monaco-theme.css',
],
Asset Loading Conflicts:
only flag:
// mix.js('resources/js/mailcoach-monaco.js', 'public/js')
.only(['mailcoach-monaco']);
Performance Overhead:
if (window.location.pathname.includes('/mailcoach/emails')) {
import(/* webpackMode: "lazy" */ './monaco-editor');
}
Configuration Overrides:
php artisan view:clear
php artisan cache:clear
Language Mode Mismatches:
{{ variables }}).monaco.languages.register({ id: 'mailcoach-html' });
monaco.languages.setLanguageConfiguration('mailcoach-html', {
comments: { lineComment: '{{#', blockComment: ['{{/*', '*/}}'] },
});
Editor Not Loading:
config/mailcoach-monaco.php.spatie/laravel-mailcoach is installed and configured.Syntax Highlighting Issues:
monaco.editor.create(document.getElementById('editor'), {
value: '<div>{{ name }}</div>',
language: 'html',
theme: 'vs-dark',
});
Custom Themes:
/* resources/css/monaco-theme.css */
.monaco-editor .view-lines {
background: #1e1e1e;
}
Custom Editor Commands:
monaco.editor.registerCommand(monaco.Uri.parse('mailcoach://insert-variable'), () => {
// Logic to insert {{ variables }}
});
Real-Time Collaboration:
Plugin System:
monaco.editor.registerSnippet('mailcoach-button', {
content: '<a href="#" style="display: inline-block; padding: 10px 20px; background: #0066cc; color: white; text-decoration: none;">Button</a>',
prefix: 'button',
});
How can I help you explore Laravel packages today?