Skip to content

Commit

Permalink
rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRembo committed Apr 8, 2024
1 parent 524ca93 commit 253d1d6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 52 deletions.
2 changes: 1 addition & 1 deletion dist/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default ((editor, opts = {}) => {
} else {
// Add Dynamic Content block only for email modes
const dcb = new DynamicContentBlocks(editor, opts);
dcb.addDynamciContentBlock();
dcb.addDynamicContentBlock();
} // Add icon to mj-hero


Expand Down
11 changes: 4 additions & 7 deletions dist/dynamicContent/dynamicContent.blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@ export default class DynamicContentBlocks {
this.blockManager = this.editor.BlockManager;
}

addDynamciContentBlock() {
addDynamicContentBlock() {
this.blockManager.add('dynamic-content', {
label: Mautic.translate('grapesjsbuilder.dynamicContentBlockLabel'),
activate: true,
select: true,
attributes: {
class: 'fa fa-tag'
},
media: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<path d="M0 80V229.5c0 17 6.7 33.3 18.7 45.3l176 176c25 25 65.5 25 90.5 0L418.7 317.3c25-25 25-65.5 0-90.5l-176-176c-12-12-28.3-18.7-45.3-18.7H48C21.5 32 0 53.5 0 80zm112 32a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/>
</svg>`,
content: {
type: 'dynamic-content',
content: '{dynamiccontent="Dynamic Content"}',
style: {
padding: '10px'
},
activeOnRender: 1
}
});
Expand Down
11 changes: 7 additions & 4 deletions dist/dynamicContent/dynamicContent.commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ export default class DynamicContentCommands {

stopDynamicContentPopup() {
// Destroy Dynamic Content editors and write the contents to the textarea
var logger = this.logger;
// eslint-disable-next-line prefer-destructuring
const logger = this.logger; // eslint-disable-next-line no-undef

if (ckEditors != undefined && ckEditors.size > 0) {
ckEditors.forEach(function (value, key, map) {
if (typeof ckEditors !== 'undefined' && ckEditors.size > 0) {
// eslint-disable-next-line no-undef
ckEditors.forEach((value, key, map) => {
const name = key.id;

if (name.includes('dynamicContent')) {
logger.debug(`Destroying Dynamic Content editor: ${name}`);
map.get(key).destroy();
map.get(key).destroy(); // eslint-disable-next-line no-undef

ckEditors.delete(key);
}
});
Expand Down
94 changes: 54 additions & 40 deletions dist/dynamicContent/dynamicContent.domcomponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,30 @@ export default class DynamicContentDomComponents {
const tagName = ContentService.isMjmlMode(editor) ? 'mj-text' : 'div';
const baseType = dc.getType(baseTypeName);
const baseModel = baseType.model;
const model = {
defaults: {
name: 'Dynamic Content',
tagName,
draggable: '[data-gjs-type=cell],[data-gjs-type=mj-column]',
droppable: false,
editable: false,
stylable: false,
propagate: ['droppable', 'editable'],
attributes: {
'data-gjs-type': 'dynamic-content',
// Type for GrapesJS
'data-slot': 'dynamicContent' // used to find the DC component on the canvas for e.g. token transformation

const dynamicContentModel = {
name: 'Dynamic Content',
tagName,
draggable: '[data-gjs-type=cell],[data-gjs-type=mj-column]',
droppable: false,
editable: false,
stylable: false,
propagate: ['droppable', 'editable'],
style: { ...baseModel.prototype.defaults['style-default'],
...{
display: 'block'
}
},
attributes: {
'data-gjs-type': 'dynamic-content',
// Type for GrapesJS
'data-slot': 'dynamicContent' // used to find the DC component on the canvas for e.g. token transformation

}
};
const model = {
defaults: { ...baseModel.prototype.defaults,
...dynamicContentModel
},

/**
* Initilize the component
Expand All @@ -51,26 +59,23 @@ export default class DynamicContentDomComponents {
}
});
}
},

// @todo: show the store items default content on the canvas
} // @todo: show the store items default content on the canvas
// updated(property, value, prevValue) {
// console.log('Local hook: model.updated', {
// console.debug('Local hook: model.updated', {
// property,
// value,
// prevValue,
// });
// },
// Dynamic Content component detection
isComponent(el) {
if (el.getAttribute && el.getAttribute('data-slot') === 'dynamicContent') {
return {
type: 'dynamic-content'
};
}
// does not work: gets removed when Sorting (by grapesjs)
// removed() {
// // Delete dynamic-content on Mautic side
// const component = this.model;
// this.em
// .get('Commands')
// .run('preset-mautic:dynamic-content-delete-store-item', { component });
// },

return false;
}

};
const view = {
Expand All @@ -82,12 +87,19 @@ export default class DynamicContentDomComponents {
},

// replace token with human readable view
onRender(el) {
// eslint-disable-next-line no-shadow
onRender({
editor,
model
}) {
const dcService = new DynamicContentService(editor);
const decId = DynamicContentService.getDataParamDecid(el.model);
const decId = DynamicContentService.getDataParamDecid(model);
const dcItem = dcService.getStoreItem(decId);
this.el.innerHTML = dcItem.content;
dcService.logger.debug('DC: Updated view', dcItem);

if (typeof dcItem !== 'undefined') {
this.el.innerHTML = dcItem.content;
dcService.logger.debug('DC: Updated view', dcItem);
}
},

// open the dynamic content modal if the editor is added or double clicked
Expand All @@ -97,19 +109,21 @@ export default class DynamicContentDomComponents {
this.em.get('Commands').run('preset-mautic:dynamic-content-open', {
target
});
} // does not work: gets removed when Sorting (by grapesjs)
// removed() {
// // Delete dynamic-content on Mautic side
// const component = this.model;
// this.em
// .get('Commands')
// .run('preset-mautic:dynamic-content-delete-store-item', { component });
// },

}

}; // add the Dynamic Content component

dc.addType('dynamic-content', {
// Dynamic Content component detection
isComponent: el => {
if (typeof el.getAttribute !== 'undefined' && el.getAttribute('data-slot') === 'dynamicContent') {
return {
type: 'dynamic-content'
};
}

return false;
},
model,
view
});
Expand Down

0 comments on commit 253d1d6

Please sign in to comment.