File size: 1,098 Bytes
d2897cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import 'grapesjs/dist/css/grapes.min.css';
import grapesJS from 'grapesjs';
import grapesJSMJML from 'grapesjs-mjml';

const editor = grapesJS.init({
  fromElement: 1,
  container: '#gjs',
  avoidInlineStyle: false,
  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();
});