• Stars
    star
    527
  • Rank 84,091 (Top 2 %)
  • Language
    TypeScript
  • Created over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Newsletter Builder with MJML components in GrapesJS

GrapesJS MJML

Requires GrapesJS v0.15.9 or higher

build

This plugin enables the usage of MJML components inside the GrapesJS environment. MJML components are rendered in real-time using the official v4 compiler (+ some mocks to make it run in the browser), therefore the result is, almost, the same as using the MJML Live Editor.

Demo

GrapesJS


Supported MJML components: mj-mjml mj-head mj-body mj-wrapper mj-group mj-section mj-column mj-text mj-image mj-button mj-social mj-social-element mj-divider mj-spacer mj-style mj-font mj-hero mj-navbar mj-navbar-link mj-raw

Options

Option Description Default
blocks Which blocks to add (all)
block Add custom block options, based on block id. (blockId) => ({})
codeViewerTheme Code viewer theme. hopscotch
fonts Custom fonts on exported HTML header more info {}
importPlaceholder Placeholder MJML template for the import modal ''
imagePlaceholderSrc Image placeholder source 'https://via.placeholder.com/350x250/78c5d6/fff'
i18n I18n object containing language more info {}
overwriteExport Overwrite default export command true
preMjml String before the MJML in export code ''
postMjml String after the MJML in export code ''
resetBlocks Clean all previous blocks if true true
resetDevices Clean all previous devices and set a new one for mobile true
resetStyleManager Reset the Style Manager and add new properties for MJML true
resetDevices Clean all previous devices and set a new one for mobile true
hideSelector Hide the default selector manager true
useXmlParser Experimental: use XML parser instead of HTML. This should allow importing void MJML elements (without closing tags) like <mj-image/> false
columnsPadding Column padding (this way it's easier to select columns) 10px 0
useCustomTheme Load custom preset theme true

Download

  • npm i grapesjs-mjml

Usage

<link href="path/to/grapes.min.css" rel="stylesheet"/>
<script src="path/to/grapes.min.js"></script>
<script src="path/to/grapesjs-mjml.min.js"></script>

<div id="gjs">
  <mjml>
    <mj-body>
      <!-- Your MJML body here -->
      <mj-section>
        <mj-column>
          <mj-text>My Company</mj-text>
        </mj-column>
      </mj-section>
    </mj-body>
  </mjml>
</div>

<script type="text/javascript">
  const editor = grapesjs.init({
      fromElement: true,
      container: '#gjs',
      plugins: ['grapesjs-mjml'],
      pluginsOpts: {
        'grapesjs-mjml': {/* ...options */}
      }
  });
</script>

Or using ESM imports:

import 'grapesjs/dist/css/grapes.min.css'
import grapesJS from 'grapesjs'
import grapesJSMJML from 'grapesjs-mjml'

grapesJS.init({
   fromElement: true,
   container: '#gjs',
   plugins: [grapesJSMJML],
   pluginsOpts: {
      [grapesJSMJML]: {/* ...options */}
   },
});

i18n usage:

import 'grapesjs/dist/css/grapes.min.css'
import grapesJS from 'grapesjs'
import nl from 'grapesjs/locale/nl'
import grapesJSMJML from 'grapesjs-mjml'
import mjmlNL from 'grapesjs-mjml/locale/nl'

grapesJS.init({
   fromElement: true,
   container: '#gjs',
   i18n: {
      // locale: 'en', // default locale
      // detectLocale: true, // by default, the editor will detect the language
      // localeFallback: 'en', // default fallback
      messages: { nl: nl },
   },
   plugins: [grapesJSMJML],
   pluginsOpts: {
      [grapesJSMJML]: {
        // Optional options
        i18n: { nl: mjmlNL }
      }
   },
});

fonts usage:

import 'grapesjs/dist/css/grapes.min.css'
import grapesJS from 'grapesjs'
import grapesJSMJML from 'grapesjs-mjml'

const editor = grapesJS.init({
   fromElement: true,
   container: '#gjs',
   plugins: [grapesJSMJML],
   pluginsOpts: {
      [grapesJSMJML]: {
        // The font imports are included on HTML <head/> when fonts are used on the template
        fonts: {
          Montserrat: 'https://fonts.googleapis.com/css?family=Montserrat',
          'Open Sans': 'https://fonts.googleapis.com/css?family=Open+Sans'
        }
      }
   },
});

// add custom fonts options on editor's font list
editor.on('load', () => {
  const styleManager = editor.StyleManager;
  const fontProperty = styleManager.getProperty('typography', 'font-family');

  const list = [];
  // empty list
  fontProperty.set('list', list);

  // custom list
  list.push(fontProperty.addOption({value: 'Montserrat, sans-serif', name: 'Montserrat'}));
  list.push(fontProperty.addOption({value: 'Open Sans, sans-serif', name: 'Open Sans'}));
  fontProperty.set('list', list);

  styleManager.render();
});

Development

Clone the repository

$ git clone https://github.com/GrapesJS/mjml.git
$ cd mjml

Install it

$ npm i

Start the dev server

$ npm start

Releasing

  1. Run npm run v:patch to bump the version in package.json and create a git tag
  2. Push the commit + new tag
  3. Go to github and draft a new release
  4. Select the new tag and add some release notes
  5. Hit publish, the release will automatically publish to npm

License

BSD 3-Clause

More Repositories

1

grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
TypeScript
17,231
star
2

cimice

Experimental user session recorder http://artf.github.io/cimice/
JavaScript
328
star
3

grapesjs-preset-webpage

GrapesJS Plugin Webpage Preset
TypeScript
246
star
4

grapesjs-preset-newsletter

GrapesJS preset configuration for the newsletter editor http://grapesjs.com
JavaScript
143
star
5

grapick

Easy configurable gradient picker, with no dependencies
JavaScript
107
star
6

ajaxable

Make your forms instantly ajaxable
JavaScript
94
star
7

grapesjs-plugin-ckeditor

This plugin replaces the default Rich Text Editor with the one from CKEditor
JavaScript
74
star
8

grapesjs-cli

GrapesJS CLI helper for the development
JavaScript
63
star
9

grapesjs-tui-image-editor

GrapesJS TOAST UI Image Editor
TypeScript
62
star
10

grapesjs-blocks-basic

Basic blocks for the GrapesJS editor
TypeScript
53
star
11

grapesjs-plugin-export

Export GrapesJS templates in a zip archive
TypeScript
53
star
12

grapesjs-plugin-forms

Set of form components and blocks for the GrapesJS editor
TypeScript
47
star
13

grapesjs-custom-code

GrapesJS component for the embed of custom code
TypeScript
45
star
14

grapesjs-firestore

Cloud Firestore storage wrapper for GrapesJS
TypeScript
30
star
15

grapesjs-plugin-boilerplate

[DEPRECATED use https://github.com/artf/grapesjs-cli] GrapesJS Plugin Boilerplate
JavaScript
29
star
16

grapesjs-blocks-flexbox

Add the flexbox block
JavaScript
29
star
17

grapesjs-tabs

Simple tabs component plugin for GrapesJS
JavaScript
27
star
18

grapesjs-aviary

Add the Aviary Image Editor in GrapesJS
JavaScript
26
star
19

grapesjs-navbar

Simple navbar component for the GrapesJS editor
TypeScript
24
star
20

codemirror-formatting

Codemirror formatting addon http://codemirror.net/2/demo/formatting.html
JavaScript
21
star
21

grapesjs-lory-slider

GrapesJS Slider Component by using lory
JavaScript
20
star
22

grapesjs-style-bg

Full-stack background style property type for GrapesJS, with the possibility to add images, colors, and gradients
TypeScript
20
star
23

grapesjs-parser-postcss

Custom CSS parser for GrapesJS by using PostCSS
JavaScript
18
star
24

grapesjs-tooltip

Simple, CSS only, tooltip component for GrapesJS
TypeScript
17
star
25

grapesjs-indexeddb

IndexedDB storage wrapper for GrapesJS
TypeScript
17
star
26

grapesjs-style-filter

Add filter type input to the Style Manager in GrapesJS
JavaScript
16
star
27

grapesjs-typed

GrapesJS Typed component made by wrapping Typed.js library
JavaScript
16
star
28

grapesjs-plugin-filestack

Enable Filestack uploader inside the Asset Manager
JavaScript
16
star
29

grapesjs-touch

Enable touch support in GrapesJS
JavaScript
14
star
30

grapesjs-component-countdown

Simple countdown component for the GrapesJS Editor
TypeScript
14
star
31

grapesjs-style-gradient

Add gradient input to the Style Manager in GrapesJS
TypeScript
11
star
32

EmojiBelt

A Chrome Extension which tries to enable emoji panel on inputs
JavaScript
4
star