-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathblocks.ts
More file actions
190 lines (170 loc) · 8.91 KB
/
blocks.ts
File metadata and controls
190 lines (170 loc) · 8.91 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import type { Editor, BlockProperties } from 'grapesjs';
import { RequiredPluginOptions } from '.';
export default (editor: Editor, opts: RequiredPluginOptions) => {
const { Blocks } = editor;
const imagePlaceholderSrc = opts.imagePlaceholderSrc || 'https://via.placeholder.com/350x250/78c5d6/fff';
const socialIcon = `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M18,16.08C17.24,16.08 16.56,16.38 16.04,16.85L8.91,12.7C8.96,12.47 9,12.24 9,12C9,11.76 8.96,11.53 8.91,11.3L15.96,7.19C16.5,7.69 17.21,8 18,8A3,3 0 0,0 21,5A3,3 0 0,0 18,2A3,3 0 0,0 15,5C15,5.24 15.04,5.47 15.09,5.7L8.04,9.81C7.5,9.31 6.79,9 6,9A3,3 0 0,0 3,12A3,3 0 0,0 6,15C6.79,15 7.5,14.69 8.04,14.19L15.16,18.34C15.11,18.55 15.08,18.77 15.08,19C15.08,20.61 16.39,21.91 18,21.91C19.61,21.91 20.92,20.61 20.92,19A2.92,2.92 0 0,0 18,16.08Z" />
</svg>`;
opts.resetBlocks && Blocks.getAll().reset();
const addBlock = (id: string, def: BlockProperties) => {
opts.blocks.indexOf(id)! >= 0 && Blocks.add(id, {
select: true,
category: editor.I18n.t('grapesjs-mjml.category'),
...def,
...opts.block(id),
});
};
// @ts-ignore
const getI18nLabel = (label: string) => editor.I18n.t(`grapesjs-mjml.components.names.${label}`)
addBlock('mj-1-column', {
label: getI18nLabel('oneColumn'),
media: `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M2 20h20V4H2v16Zm-1 0V4a1 1 0 0 1 1-1h20a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1Z"/>
</svg>`,
content: `<mj-section>
<mj-column><mj-text>Content 1</mj-text></mj-column>
</mj-section>`,
});
addBlock('mj-2-columns', {
label: getI18nLabel('twoColumn'),
media: `<svg viewBox="0 0 23 24">
<path fill="currentColor" d="M2 20h8V4H2v16Zm-1 0V4a1 1 0 0 1 1-1h8a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1ZM13 20h8V4h-8v16Zm-1 0V4a1 1 0 0 1 1-1h8a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-8a1 1 0 0 1-1-1Z"/>
</svg>`,
content: `<mj-section>
<mj-column><mj-text>Content 1</mj-text></mj-column>
<mj-column><mj-text>Content 2</mj-text></mj-column>
</mj-section>`,
});
addBlock('mj-3-columns', {
label: getI18nLabel('threeColumn'),
media: `<svg viewBox="0 0 23 24">
<path fill="currentColor" d="M2 20h4V4H2v16Zm-1 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1ZM17 20h4V4h-4v16Zm-1 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1ZM9.5 20h4V4h-4v16Zm-1 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1Z"/>
</svg>`,
content: `<mj-section>
<mj-column><mj-text>Content 1</mj-text></mj-column>
<mj-column><mj-text>Content 2</mj-text></mj-column>
<mj-column><mj-text>Content 3</mj-text></mj-column>
</mj-section>`,
});
addBlock('mj-text', {
label: getI18nLabel('text'),
media: `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M18.5,4L19.66,8.35L18.7,8.61C18.25,7.74 17.79,6.87 17.26,6.43C16.73,6 16.11,6 15.5,6H13V16.5C13,17 13,17.5 13.33,17.75C13.67,18 14.33,18 15,18V19H9V18C9.67,18 10.33,18 10.67,17.75C11,17.5 11,17 11,16.5V6H8.5C7.89,6 7.27,6 6.74,6.43C6.21,6.87 5.75,7.74 5.3,8.61L4.34,8.35L5.5,4H18.5Z" />
</svg>`,
content: '<mj-text>Insert text here</mj-text>',
activate: true,
});
addBlock('mj-button', {
label: getI18nLabel('button'),
media: `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M20 20.5C20 21.3 19.3 22 18.5 22H13C12.6 22 12.3 21.9 12 21.6L8 17.4L8.7 16.6C8.9 16.4 9.2 16.3 9.5 16.3H9.7L12 18V9C12 8.4 12.4 8 13 8S14 8.4 14 9V13.5L15.2 13.6L19.1 15.8C19.6 16 20 16.6 20 17.1V20.5M20 2H4C2.9 2 2 2.9 2 4V12C2 13.1 2.9 14 4 14H8V12H4V4H20V12H18V14H20C21.1 14 22 13.1 22 12V4C22 2.9 21.1 2 20 2Z" />
</svg>`,
content: '<mj-button>Button</mj-button>',
});
addBlock('mj-image', {
label: getI18nLabel('image'),
media: `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M21,3H3C2,3 1,4 1,5V19A2,2 0 0,0 3,21H21C22,21 23,20 23,19V5C23,4 22,3 21,3M5,17L8.5,12.5L11,15.5L14.5,11L19,17H5Z" />
</svg>`,
content: `<mj-image src="${imagePlaceholderSrc}"/>`,
activate: true,
});
addBlock('mj-divider', {
label: getI18nLabel('divider'),
media: `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M21 18H2V20H21V18M19 10V14H4V10H19M20 8H3C2.45 8 2 8.45 2 9V15C2 15.55 2.45 16 3 16H20C20.55 16 21 15.55 21 15V9C21 8.45 20.55 8 20 8M21 4H2V6H21V4Z" />
</svg>`,
content: '<mj-divider/>',
});
addBlock('mj-social-group', {
label: getI18nLabel('socialGroup'),
media: socialIcon,
content: `<mj-social font-size="12px" icon-size="24px" border-radius="12px" mode="horizontal">
<mj-social-element name="facebook"></mj-social-element>
<mj-social-element name="google"></mj-social-element>
<mj-social-element name="twitter"></mj-social-element>
</mj-social>`,
});
addBlock('mj-social-element', {
label: getI18nLabel('socialElement'),
media: socialIcon,
content: '<mj-social-element name="facebook" />',
});
addBlock('mj-spacer', {
label: getI18nLabel('spacer'),
media: `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M8,18H11V15H2V13H22V15H13V18H16L12,22L8,18M12,2L8,6H11V9H2V11H22V9H13V6H16L12,2Z" />
</svg>`,
content: '<mj-spacer/>',
});
addBlock('mj-navbar', {
label: getI18nLabel('navBar'),
media: `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" />
</svg>`,
content: `<mj-navbar>
<mj-navbar-link>Getting started</mj-navbar-link>
<mj-navbar-link>Try it live</mj-navbar-link>
<mj-navbar-link>Templates</mj-navbar-link>
<mj-navbar-link>Components</mj-navbar-link>
</mj-navbar>`,
});
addBlock('mj-navbar-link', {
label: getI18nLabel('navLink'),
media: `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M21,15.61L19.59,17L14.58,12L19.59,7L21,8.39L17.44,12L21,15.61M3,6H16V8H3V6M3,13V11H13V13H3M3,18V16H16V18H3Z" />
</svg>`,
content: `<mj-navbar-link>Link</mj-navbar-link>`,
});
addBlock('mj-hero', {
label: getI18nLabel('hero'),
media: `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M20,20H4A2,2 0 0,1 2,18V6A2,2 0 0,1 4,4H20A2,2 0 0,1 22,6V18A2,2 0 0,1 20,20M4,6V18H20V6H4M6,9H18V11H6V9M6,13H16V15H6V13Z" />
</svg>`,
content: `<mj-hero mode="fixed-height" height="469px" background-width="600px" background-height="469px" background-url="https://cloud.githubusercontent.com/assets/1830348/15354890/1442159a-1cf0-11e6-92b1-b861dadf1750.jpg" background-color="#2a3448" padding="100px 0px">
<mj-text padding="20px" color="#ffffff" font-family="Helvetica" align="center" font-size="45px" line-height="45px" font-weight="900">
GO TO SPACE
</mj-text>
<mj-button href="https://mjml.io/" align="center">
ORDER YOUR TICKET NOW
</mj-button>
</mj-hero>`,
});
addBlock('mj-wrapper', {
label: getI18nLabel('wrapper'),
media: `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M18 2H6C4.89 2 4 2.9 4 4V20C4 21.11 4.89 22 6 22H18C19.11 22 20 21.11 20 20V4C20 2.9 19.11 2 18 2M18 20H6V16H18V20M18 8H6V4H18V8Z" />
</svg>`,
content: `<mj-wrapper border="1px solid #000000" padding="50px 30px">
<mj-section border-top="1px solid #aaaaaa" border-left="1px solid #aaaaaa" border-right="1px solid #aaaaaa" padding="20px">
<mj-column>
<mj-image padding="0" src="${imagePlaceholderSrc}" />
</mj-column>
</mj-section>
<mj-section border-left="1px solid #aaaaaa" border-right="1px solid #aaaaaa" padding="20px" border-bottom="1px solid #aaaaaa">
<mj-column border="1px solid #dddddd">
<mj-text padding="20px"> First line of text </mj-text>
<mj-divider border-width="1px" border-style="dashed" border-color="lightgrey" padding="0 20px" />
<mj-text padding="20px"> Second line of text </mj-text>
</mj-column>
</mj-section>
</mj-wrapper>`,
});
addBlock('mj-raw', {
label: getI18nLabel('raw'),
media: `<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M12,17.56L16.07,16.43L16.62,10.33H9.38L9.2,8.3H16.8L17,6.31H7L7.56,12.32H14.45L14.22,14.9L12,15.5L9.78,14.9L9.64,13.24H7.64L7.93,16.43L12,17.56M4.07,3H19.93L18.5,19.2L12,21L5.5,19.2L4.07,3Z" />
</svg>`,
content: `<mj-raw>
<div class="container">
<img class="item" src="https://picsum.photos/seed/grapesjs-mjml-1/200/141" alt="Example image">
<img class="item" src="https://picsum.photos/seed/grapesjs-mjml-2/200/142" alt="Example image">
<img class="item" src="https://picsum.photos/seed/grapesjs-mjml-3/200/143" alt="Example image">
<img class="item" src="https://picsum.photos/seed/grapesjs-mjml-4/200/144" alt="Example image">
<img class="item" src="https://picsum.photos/seed/grapesjs-mjml-5/200/145" alt="Example image">
<img class="item" src="https://picsum.photos/seed/grapesjs-mjml-6/200/146" alt="Example image">
</div>
</mj-raw>`,
});
};