Skip to content

Error record is undefined when use toggleCustomInlineStyle on an entity (RawDraftEntity) #45

@lafonju

Description

@lafonju

Hey,
I would like to know if it is possible to use the toggleCustomInlineStyle method on an entity (RawDraftEntity) ?
For example, I have an html code with custom tags
<var data-name="$test">

I use htmlToDraft method for convert this code with a customChunkRenderer

private static customChunkRenderer(nodeName: string, node: HTMLElement): RawDraftEntity | undefined {
        let draftEntity: RawDraftEntity | undefined;
        if (nodeName === 'var') {
            const data = {
                name: node.dataset.name
            };
            draftEntity = {
                type: VariableType,
                mutability: 'IMMUTABLE',
                data: data
            };
        }
        return draftEntity;
    }

When I want to change the text size of my item, with the toggleCustomInlineStyle method, I get the following error message

TypeError: record is undefined
removeStyle
.../node_modules/draft-js/lib/CharacterMetadata.js:56

  53 | };
  54 | 
  55 | CharacterMetadata.removeStyle = function removeStyle(record, style) {
> 56 |   var withoutStyle = record.set('style', record.getStyle().remove(style));
     | ^  57 |   return CharacterMetadata.create(withoutStyle);
  58 | };
  59 | 

Then I want to retrieve the HTML code with the style applied to my item, with draftToHtml and my method customEntityTransform

private static customEntityTransform(...args): any {
        const entity = args[0] as RawDraftEntity;
        let value: string | undefined;
        if (entity.type === VariableType) {
            value = '<var data-name="' + entity.data.name + '">';
        }

        return value;
    }

Thank you very much

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions