Skip to content

Commit

Permalink
Corrected problem with listItem, Added remove custom classes and attr…
Browse files Browse the repository at this point in the history
…ibutes on new item list
  • Loading branch information
mateuszdebinski committed Jan 24, 2024
1 parent 5e56315 commit ede7257
Showing 1 changed file with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,23 @@ class IbexaCustomAttributesEditing extends Plugin {
}
}

init() {
clearElement(element, customs) {
const { model } = this.editor;

Object.entries(customs).forEach(([elementName, config]) => {
if (elementName === element.name) {
return;
}

model.change((writer) => {
Object.keys(config).forEach((name) => {
writer.removeAttribute(name, element);
});
});
});
}
init() {
const { commands, model } = this.editor;
const customAttributesConfig = getCustomAttributesConfig();
const customClassesConfig = getCustomClassesConfig();
const elementsWithCustomAttributes = Object.keys(customAttributesConfig);
Expand All @@ -133,7 +148,9 @@ class IbexaCustomAttributesEditing extends Plugin {
const elementName = isList ? 'listItem' : element;
const customAttributes = Object.keys(customAttributesConfig[element]);

this.extendSchema(model.schema, elementName, { allowAttributes: `${prefix}${customAttributes}` });
customAttributes.forEach((customAttribute) => {
this.extendSchema(model.schema, elementName, { allowAttributes: `${prefix}${customAttribute}` });
});
});

elementsWithCustomClasses.forEach((element) => {
Expand All @@ -146,7 +163,18 @@ class IbexaCustomAttributesEditing extends Plugin {

this.defineConverters();

this.editor.commands.add('insertIbexaCustomAttributes', new IbexaCustomAttributesCommand(this.editor));
const command = new IbexaCustomAttributesCommand(this.editor);

commands.get('enter').on('afterExecute', () => {
const blocks = model.document.selection.getSelectedBlocks();

for (const block of blocks) {
this.clearElement(block, customAttributesConfig);
this.clearElement(block, customClassesConfig);
}
});

commands.add('insertIbexaCustomAttributes', command);
}
}

Expand Down

0 comments on commit ede7257

Please sign in to comment.