Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Preference Center blocks to GrapesJS builder #46

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions dist/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,47 @@ import DynamicContentBlocks from './dynamicContent/dynamicContent.blocks';
import ContentService from './content.service';
import ButtonBlock from './buttonBlock';
import BlocksMjml from './blocks/blocks.mjml';
import PreferenceCenterBlocks from './preferenceCenter/preferenceCenter.blocks';
export default ((editor, opts = {}) => {
const bm = editor.BlockManager;
const blocks = bm.getAll();
const mode = ContentService.getMode(editor);
if (mode === ContentService.modeEmailMjml) {
const blockMjml = new BlocksMjml(editor);
blockMjml.addBlocks();
}

// a add button block for landing page
if (mode === ContentService.modePageHtml) {
const buttonBlock = new ButtonBlock(editor);
buttonBlock.addButtonBlock();
} else {
// Add Dynamic Content block only for email modes
const dcb = new DynamicContentBlocks(editor, opts);
dcb.addDynamciContentBlock();
// All block inside Blocks category
blocks.forEach(block => {
block.set({
category: Mautic.translate('grapesjsbuilder.categoryBlockLabel')
});
});

// eslint-disable-next-line default-case
switch (ContentService.getMode(editor)) {
case ContentService.modePageHtml:
{
const buttonBlock = new ButtonBlock(editor);
buttonBlock.addButtonBlock();

// Check if page is for preference center
const isPreferenceCenter = ContentService.isPreferenceCenter();
if (isPreferenceCenter) {
const pcb = new PreferenceCenterBlocks(editor);
pcb.addPreferenceCenterBlocks();
}
break;
}
case ContentService.modeEmailMjml:
{
const blockMjml = new BlocksMjml(editor);
blockMjml.addBlocks();
const dcb = new DynamicContentBlocks(editor, opts);
dcb.addDynamciContentBlock();
break;
}
case ContentService.modeEmailHtml:
{
const dcb = new DynamicContentBlocks(editor, opts);
dcb.addDynamciContentBlock();
break;
}
}

// Add icon to mj-hero
Expand All @@ -35,13 +59,6 @@ export default ((editor, opts = {}) => {
bm.remove('mj-wrapper');
}

// All block inside Blocks category
blocks.forEach(block => {
block.set({
category: Mautic.translate('grapesjsbuilder.categoryBlockLabel')
});
});

/*
* Custom block inside Sections category
*/
Expand Down
7 changes: 7 additions & 0 deletions dist/components.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
/* eslint-disable no-else-return */
import DynamicContentDomComponents from './dynamicContent/dynamicContent.domcomponents';
import PreferenceCenterDomComponents from './preferenceCenter/preferenceCenter.domcomponents';
import ContentService from './content.service';

// https://grapesjs.com/docs/api/component.html
export default (editor => {
const mode = ContentService.getMode(editor);
DynamicContentDomComponents.addDynamicContentType(editor);
if (mode === ContentService.modePageHtml) {
const pcdom = new PreferenceCenterDomComponents(editor);
pcdom.addPreferenceCenterContentTypes(editor);
}
});
3 changes: 3 additions & 0 deletions dist/content.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export default class ContentService {
}
return ContentService.getMode(editor) === ContentService.modeEmailMjml;
}
static isPreferenceCenter() {
return mQuery('#page_isPreferenceCenter_1').is(':checked');
}
static getMode(editor) {
const cfg = editor.getConfig();
if (!cfg.pluginsOpts || !cfg.pluginsOpts.grapesjsmautic || !cfg.pluginsOpts.grapesjsmautic.mode) {
Expand Down
Loading