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 f2cb46b
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,24 @@ 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 +149,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 +164,16 @@ class IbexaCustomAttributesEditing extends Plugin {

this.defineConverters();

this.editor.commands.add('insertIbexaCustomAttributes', 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', new IbexaCustomAttributesCommand(this.editor));
}
}

Expand Down

0 comments on commit f2cb46b

Please sign in to comment.