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-7747: Two or more embedded items makes popup menu unable to open #147

Merged
merged 3 commits into from
Feb 9, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import IbexaEmbedContentInlineCommand from './embed-inline-command';

import { findContent } from '../../services/content-service';

const renderPreview = (title, contentId) => {
const renderPreview = (title, contentId, itemActionsContainer) => {
const itemActionsHTML = itemActionsContainer?.outerHTML ?? '';

return `<svg class="ibexa-icon ibexa-icon--medium ibexa-icon--secondary">
<use xlink:href="${window.ibexa.helpers.icon.getIconPath('embed')}"></use>
</svg>
Expand All @@ -26,7 +28,8 @@ const renderPreview = (title, contentId) => {
<use xlink:href="${window.ibexa.helpers.icon.getIconPath('options')}"></use>
</svg>
</button>
</span>`;
</span>
${itemActionsHTML}`;
};

class IbexaEmbedContentInlineEditing extends Plugin {
Expand All @@ -53,15 +56,17 @@ class IbexaEmbedContentInlineEditing extends Plugin {
.elementToElement({
model: 'embedInline',
view: (modelElement, { writer: downcastWriter }) => {
const { editor } = this;
const container = downcastWriter.createContainerElement('span', {
'data-ezelement': 'ezembedinline',
'data-ezview': 'embed-inline',
class: 'ibexa-embed-inline',
});
const preview = downcastWriter.createUIElement('span', { class: 'ibexa-embed-content' }, function (domDocument) {
const domElement = this.toDomElement(domDocument);
const itemActionsContainer = editor.sourceElement.parentNode.querySelector('.ibexa-embedded-item-actions');

domElement.innerHTML = renderPreview(modelElement.getAttribute('contentName'));
domElement.innerHTML = renderPreview(modelElement.getAttribute('contentName'), null, itemActionsContainer);

return domElement;
});
Expand All @@ -72,7 +77,7 @@ class IbexaEmbedContentInlineEditing extends Plugin {
},
})
.add((dispatcher) =>
dispatcher.on('attribute:contentName', (event, data, conversionApi) => {
dispatcher.on('attribute:contentName:embedInline', (event, data, conversionApi) => {
const { editor } = this;
const downcastWriter = conversionApi.writer;
const modelElement = data.item;
Expand All @@ -83,11 +88,12 @@ class IbexaEmbedContentInlineEditing extends Plugin {
const locationId = modelElement.getAttribute('locationId');
const languageCodes = modelElement.getAttribute('languageCodes');
const domElement = this.toDomElement(domDocument);
const itemActionsContainer = editor.sourceElement.parentNode.querySelector('.ibexa-embedded-item-actions');

domElement.innerHTML = renderPreview(contentName, contentId);
domElement.innerHTML = renderPreview(contentName, contentId, itemActionsContainer);

const itemActionsTriggerElement = domElement.querySelector('.ibexa-embedded-item__actions-menu-trigger-btn');
const itemActionsMenuContainer = editor.sourceElement.parentNode.querySelector(
const itemActionsMenuContainer = domElement.querySelector(
'.ibexa-embedded-item-actions .ibexa-multilevel-popup-menu',
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import IbexaEmbedContentCommand from './embed-command';

import { findContent } from '../../services/content-service';

const renderPreview = (title, contentId) => {
const renderPreview = (title, contentId, itemActionsContainer) => {
const itemActionsHTML = itemActionsContainer?.outerHTML ?? '';

return `<svg class="ibexa-icon ibexa-icon--medium ibexa-icon--secondary">
<use xlink:href="${window.ibexa.helpers.icon.getIconPath('embed')}"></use>
</svg>
Expand All @@ -26,7 +28,8 @@ const renderPreview = (title, contentId) => {
<use xlink:href="${window.ibexa.helpers.icon.getIconPath('options')}"></use>
</svg>
</button>
</span>`;
</span>
${itemActionsHTML}`;
};

class IbexaEmbedContentEditing extends Plugin {
Expand All @@ -52,6 +55,7 @@ class IbexaEmbedContentEditing extends Plugin {
.elementToElement({
model: 'embed',
view: (modelElement, { writer: downcastWriter }) => {
const { editor } = this;
const container = downcastWriter.createContainerElement('div', {
'data-href': `ezcontent://${modelElement.getAttribute('contentId')}`,
'data-ezelement': 'ezembed',
Expand All @@ -62,8 +66,9 @@ class IbexaEmbedContentEditing extends Plugin {
const contentId = modelElement.getAttribute('contentId');
const contentName = modelElement.getAttribute('contentName');
const domElement = this.toDomElement(domDocument);
const itemActionsContainer = editor.sourceElement.parentNode.querySelector('.ibexa-embedded-item-actions');

domElement.innerHTML = renderPreview(contentName, contentId);
domElement.innerHTML = renderPreview(contentName, contentId, itemActionsContainer);

return domElement;
});
Expand All @@ -74,7 +79,7 @@ class IbexaEmbedContentEditing extends Plugin {
},
})
.add((dispatcher) =>
dispatcher.on('attribute:contentName', (event, data, conversionApi) => {
dispatcher.on('attribute:contentName:embed', (event, data, conversionApi) => {
const { editor } = this;
const downcastWriter = conversionApi.writer;
const modelElement = data.item;
Expand All @@ -85,11 +90,12 @@ class IbexaEmbedContentEditing extends Plugin {
const locationId = modelElement.getAttribute('locationId');
const languageCodes = modelElement.getAttribute('languageCodes');
const domElement = this.toDomElement(domDocument);
const itemActionsContainer = editor.sourceElement.parentNode.querySelector('.ibexa-embedded-item-actions');

domElement.innerHTML = renderPreview(contentName);
domElement.innerHTML = renderPreview(contentName, contentId, itemActionsContainer);

const itemActionsTriggerElement = domElement.querySelector('.ibexa-embedded-item-actions__menu-trigger-btn');
const itemActionsMenuContainer = editor.sourceElement.parentNode.querySelector(
const itemActionsMenuContainer = domElement.querySelector(
'.ibexa-embedded-item-actions .ibexa-multilevel-popup-menu',
);

Expand Down
10 changes: 1 addition & 9 deletions src/bundle/Resources/public/scss/_general.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
background: $ibexa-color-light-100;
border: calculateRem(1px) solid $ibexa-color-light-100;
border-radius: calculateRem(4px);
font-size: calculateRem(18px);
font-size: $ibexa-text-font-size;
display: inline-block;
margin: 0 calculateRem(5px);
padding: calculateRem(2px);
Expand Down Expand Up @@ -132,14 +132,6 @@

[data-ezelement='ezembedinline'] {
vertical-align: middle;
font-size: calculateRem(16px);

.ibexa-embed-content {
.ibexa-icon {
width: calculateRem(22px);
height: calculateRem(22px);
}
}
}

[data-eztype='style'] {
Expand Down
Loading