Skip to content

Commit

Permalink
Edit/Preview embedded item
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasOsti committed Aug 31, 2023
1 parent 2871098 commit e48c10a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class IbexaEmbedContentInlineCommand extends Command {
});
}

createEmbed(writer, { contentId, contentName, locationId, languagesCode }) {
return writer.createElement('embedInline', { contentId, contentName, locationId, languagesCode });
createEmbed(writer, { contentId, contentName, locationId, versionNo, languageCodes }) {
return writer.createElement('embedInline', { contentId, contentName, locationId, versionNo, languageCodes });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class IbexaEmbedContentInlineEditing extends Plugin {
isObject: true,
isInline: true,
allowWhere: '$text',
allowAttributes: ['contentId', 'contentName', 'locationId', 'languagesCode'],
allowAttributes: ['contentId', 'contentName', 'locationId', 'versionNo', 'languageCodes'],
});
}

Expand Down Expand Up @@ -78,7 +78,8 @@ class IbexaEmbedContentInlineEditing extends Plugin {
const contentId = modelElement.getAttribute('contentId');
const contentName = modelElement.getAttribute('contentName');
const locationId = modelElement.getAttribute('locationId');
const languagesCode = modelElement.getAttribute('languagesCode');
const versionNo = modelElement.getAttribute('versionNo');
const languageCodes = modelElement.getAttribute('languageCodes');
const domElement = this.toDomElement(domDocument);

domElement.innerHTML = renderPreview(contentName, contentId);
Expand All @@ -90,11 +91,10 @@ class IbexaEmbedContentInlineEditing extends Plugin {
detail: {
contentId,
locationId,
languagesCode,
actionsMenuConfig: {
container: itemActionsMenuContainer,
triggerElement: itemActionsTriggerElement
}
versionNo,
languageCodes,
menuTriggerElement: itemActionsTriggerElement,
menuContainer: itemActionsMenuContainer,
}
}));

Expand Down Expand Up @@ -141,18 +141,15 @@ class IbexaEmbedContentInlineEditing extends Plugin {
const contentName = contents[0].TranslatedName;
const contentId = contents[0]._id;
const locationId = contents[0].MainLocation._href.split('/').pop();
const languagesCode = contents[0].CurrentVersion.Version.VersionInfo.VersionTranslationInfo.Language.map((language) => language.languageCode);

console.log(
'Test: Richtext embed inline: contents[0].CurrentVersion.Version.VersionInfo.VersionTranslationInfo.Language',
contents[0],
);
const versionNo = contents[0].currentVersionNo;
const languageCodes = contents[0].CurrentVersion.Version.VersionInfo.VersionTranslationInfo.Language.map((language) => language.languageCode);

this.editor.model.change((writer) => {
writer.setAttribute('contentName', contentName, modelElement);
writer.setAttribute('contentId', contentId, modelElement);
writer.setAttribute('locationId', locationId, modelElement);
writer.setAttribute('languagesCode', languagesCode, modelElement);
writer.setAttribute('versionNo', versionNo, modelElement);
writer.setAttribute('languageCodes', languageCodes, modelElement);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class IbexaEmbedContentInlineUI extends IbexaEmbedBaseUI {
contentId: items[0].ContentInfo.Content._id,
contentName: items[0].ContentInfo.Content.TranslatedName,
locationId: items[0].id,
languagesCode: items[0].ContentInfo.Content.CurrentVersion.Version.VersionInfo.VersionTranslationInfo.Language.map((language) => language.languageCode),
versionNo: items[0].ContentInfo.Content.currentVersionNo,
languageCodes: items[0].ContentInfo.Content.CurrentVersion.Version.VersionInfo.VersionTranslationInfo.Language.map((language) => language.languageCode),
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class IbexaEmbedContentCommand extends Command {
});
}

createEmbed(writer, { contentId, contentName, locationId, languagesCode }) {
return writer.createElement('embed', { contentId, contentName, locationId, languagesCode });
createEmbed(writer, { contentId, contentName, locationId, versionNo, languageCodes }) {
return writer.createElement('embed', { contentId, contentName, locationId, versionNo, languageCodes });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class IbexaEmbedContentEditing extends Plugin {
schema.register('embed', {
isObject: true,
allowWhere: '$block',
allowAttributes: ['contentId', 'contentName', 'locationId', 'languagesCode'],
allowAttributes: ['contentId', 'contentName', 'locationId', 'versionNo', 'languageCodes'],
});
}

Expand Down Expand Up @@ -79,24 +79,23 @@ class IbexaEmbedContentEditing extends Plugin {
const contentId = modelElement.getAttribute('contentId');
const contentName = modelElement.getAttribute('contentName');
const locationId = modelElement.getAttribute('locationId');
const languagesCode = modelElement.getAttribute('languagesCode');
const versionNo = modelElement.getAttribute('versionNo');
const languageCodes = modelElement.getAttribute('languageCodes');
const domElement = this.toDomElement(domDocument);


domElement.innerHTML = renderPreview(modelElement.getAttribute('contentName'));
console.log('xxx')
domElement.innerHTML = renderPreview(contentName);

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

domDocument.body.dispatchEvent(new CustomEvent('ibexa-embedded-item:create-dynamic-menu', {
detail: {
contentId,
locationId,
languagesCode,
actionsMenuConfig: {
container: itemActionsMenuContainer,
triggerElement: itemActionsTriggerElement
}
versionNo,
languageCodes,
menuTriggerElement: itemActionsTriggerElement,
menuContainer: itemActionsMenuContainer,
}
}));

Expand Down Expand Up @@ -144,18 +143,15 @@ class IbexaEmbedContentEditing extends Plugin {
const contentName = contents[0].TranslatedName;
const contentId = contents[0]._id;
const locationId = contents[0].MainLocation._href.split('/').pop();
const languagesCode = contents[0].CurrentVersion.Version.VersionInfo.VersionTranslationInfo.Language.map((language) => language.languageCode);

console.log(
'Test: Richtext embed: contents[0].CurrentVersion.Version.VersionInfo.VersionTranslationInfo.Language',
contents[0],
);
const versionNo = contents[0].currentVersionNo;
const languageCodes = contents[0].CurrentVersion.Version.VersionInfo.VersionTranslationInfo.Language.map((language) => language.languageCode);

this.editor.model.change((writer) => {
writer.setAttribute('contentName', contentName, modelElement);
writer.setAttribute('contentId', contentId, modelElement);
writer.setAttribute('locationId', locationId, modelElement);
writer.setAttribute('languagesCode', languagesCode, modelElement);
writer.setAttribute('versionNo', versionNo, modelElement);
writer.setAttribute('languageCodes', languageCodes, modelElement);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class IbexaEmbedContentUI extends IbexaEmbedBaseUI {
contentId: items[0].ContentInfo.Content._id,
contentName: items[0].ContentInfo.Content.TranslatedName,
locationId: items[0].id,
languagesCode: items[0].ContentInfo.Content.CurrentVersion.Version.VersionInfo.VersionTranslationInfo.Language.map((language) => language.languageCode),
versionNo: items[0].ContentInfo.Content.currentVersionNo,
languageCodes: items[0].ContentInfo.Content.CurrentVersion.Version.VersionInfo.VersionTranslationInfo.Language.map((language) => language.languageCode),
};
}
}
Expand Down

0 comments on commit e48c10a

Please sign in to comment.