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

IBX-5297: Fixed custom tag without any attribute #82

Merged
merged 2 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ class IbexaCustomTagEditing extends Plugin {
});
const header = downcastWriter.createUIElement('div', { class: 'ibexa-custom-tag__header' }, function (domDocument) {
const domElement = this.toDomElement(domDocument);
const customTagConfig = window.ibexa.richText.customTags[customTagName];
const attributesButton = `<button type="button" class="ibexa-btn ibexa-btn--ghost ibexa-btn--small ibexa-btn--no-text ibexa-btn--show-custom-tag-attributes">
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--secondary">
<use xlink:href="${window.ibexa.helpers.icon.getIconPath('settings-block')}"></use>
</svg>
</button>`;

domElement.innerHTML = `
<div class="ibexa-custom-tag__header-title">${window.ibexa.richText.customTags[customTagName].label}</div>
<div class="ibexa-custom-tag__header-title">${customTagConfig.label}</div>
<div class="ibexa-custom-tag__header-actions">
<button type="button" class="ibexa-btn ibexa-btn--ghost ibexa-btn--small ibexa-btn--no-text ibexa-btn--show-custom-tag-attributes">
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--secondary">
<use xlink:href="${window.ibexa.helpers.icon.getIconPath('settings-block')}"></use>
</svg>
</button>
${Object.keys(customTagConfig.attributes).length ? attributesButton : ''}
<button type="button" class="ibexa-btn ibexa-btn--ghost ibexa-btn--small ibexa-btn--no-text ibexa-btn--remove-custom-tag">
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--secondary">
<use xlink:href="${window.ibexa.helpers.icon.getIconPath('trash')}"></use>
Expand All @@ -73,10 +75,11 @@ class IbexaCustomTagEditing extends Plugin {
'data-ezelement': 'eztemplate',
'data-ezname': modelElement.getAttribute('customTagName'),
});
const values = modelElement.getAttribute('values');
const config = downcastWriter.createUIElement('span', { 'data-ezelement': 'ezconfig' }, function (domDocument) {
const domElement = this.toDomElement(domDocument);

domElement.innerHTML = Object.entries(modelElement.getAttribute('values')).reduce((total, [attribute, value]) => {
domElement.innerHTML = Object.entries(values).reduce((total, [attribute, value]) => {
// Escaping
// <script>alert("Hello! I am a script!");</script> --> &lt;script&gt;alert("Hello! I am a script!");&lt;/script&gt;
const stringTempNode = domDocument.createElement('div');
Expand All @@ -92,7 +95,10 @@ class IbexaCustomTagEditing extends Plugin {
});

downcastWriter.remove(downcastWriter.createRangeIn(container));
downcastWriter.insert(downcastWriter.createPositionAt(container, 0), config);

if (Object.keys(values).length) {
downcastWriter.insert(downcastWriter.createPositionAt(container, 0), config);
}

return container;
},
Expand All @@ -111,7 +117,8 @@ class IbexaCustomTagEditing extends Plugin {
}

const configElement = viewElement.getChild(1);
const configValuesIterator = configElement.getChildren();
const configValuesIterator =
configElement?.getAttribute('data-ezelement') === 'ezconfig' ? configElement.getChildren() : [];
const customTagName = viewElement.getAttribute('data-ezname');
const tagConfig = customTags[customTagName] ?? {};
const values = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class IbexaCustomTagUI extends Plugin {
return !!eventData.domTarget.closest('.ibexa-btn--show-custom-tag-attributes');
}

hasAttributes() {
return !!Object.keys(this.config.attributes).length;
}

enableUserBalloonInteractions() {
const viewDocument = this.editor.editing.view.document;

Expand Down Expand Up @@ -194,9 +198,11 @@ class IbexaCustomTagUI extends Plugin {
this.editor.focus();
this.editor.execute('insertIbexaCustomTag', { customTagName: this.componentName, values });

this.isNew = true;
if (this.hasAttributes()) {
this.isNew = true;

this.showForm();
this.showForm();
}
}

init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class IbexaCustomTags extends Plugin {
this.componentName = name;
this.config = config;

if (!this.config.attributes) {
this.config.attributes = {};
}

this.formView.setChildren(
{
attributes: this.config.attributes,
Expand All @@ -34,6 +38,10 @@ class IbexaCustomTags extends Plugin {
this.componentName = name;
this.config = config;

if (!this.config.attributes) {
this.config.attributes = {};
}

this.formView.setChildren(
{
attributes: this.config.attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ class IbexaInlineCustomTagEditing extends Plugin {
'data-ezelement': 'eztemplateinline',
'data-ezname': modelElement.getAttribute('customTagName'),
});
const values = modelElement.getAttribute('values');
const config = downcastWriter.createUIElement('span', { 'data-ezelement': 'ezconfig' }, function (domDocument) {
const domElement = this.toDomElement(domDocument);

domElement.innerHTML = Object.entries(modelElement.getAttribute('values')).reduce((total, [attribute, value]) => {
domElement.innerHTML = Object.entries(values).reduce((total, [attribute, value]) => {
const attributeValue = value ?? '';
const ezvalue = `<span data-ezelement="ezvalue" data-ezvalue-key="${attribute}">${attributeValue}</span>`;

Expand All @@ -63,7 +64,10 @@ class IbexaInlineCustomTagEditing extends Plugin {
});

downcastWriter.remove(downcastWriter.createRangeIn(container));
downcastWriter.insert(downcastWriter.createPositionAt(container, 0), config);

if (Object.keys(values).length) {
downcastWriter.insert(downcastWriter.createPositionAt(container, 0), config);
}

return container;
},
Expand All @@ -82,7 +86,8 @@ class IbexaInlineCustomTagEditing extends Plugin {
}

const configElement = viewElement.getChild(1);
const configValuesIterator = configElement.getChildren();
const configValuesIterator =
configElement?.getAttribute('data-ezelement') === 'ezconfig' ? configElement.getChildren() : [];
const customTagName = viewElement.getAttribute('data-ezname');
const values = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ class IbexaInlineCustomTagUI extends Plugin {
return modelElement && modelElement.name === 'inlineCustomTag' && modelElement.getAttribute('customTagName') === this.componentName;
}

hasAttributes() {
return !!Object.keys(this.config.attributes).length;
}

enableUserBalloonInteractions() {
const viewDocument = this.editor.editing.view.document;

this.listenTo(viewDocument, 'click', () => {
if (this.isInlineCustomTagSelected()) {
if (this.isInlineCustomTagSelected() && this.hasAttributes()) {
this.showForm();
}
});
Expand Down Expand Up @@ -121,9 +125,11 @@ class IbexaInlineCustomTagUI extends Plugin {
this.editor.focus();
this.editor.execute('insertIbexaInlineCustomTag', { customTagName: this.componentName, values });

this.isNew = true;
if (this.hasAttributes()) {
this.isNew = true;

this.showForm();
this.showForm();
}
}

init() {
Expand Down