This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
JavaScript $ReadOnlyArray<CompositeDecorator>
#1
Hello together,

I'm trying to get some code working which will highlight links automatically in an rich text editor. This is not my own written code this is from draft js and is provided by many different web pages because this is the absolutlly basic how it should work out.
My major problem is that when I deifinine the linkDecorator of the type CompositeDecorator the compiler tells me that the linkDecorator is $ReadOnlyArray<DraftDecorator> which can't handle the provided input. I have absolutly no idea what I'm doing wrong because for people on about 10 different websites exactly this code works out well. Even in an [online compiler][1] were you can compile the code yourself it works.
Also practically the programm won't throw errors but it simply won't do anything anymore after this line.

Thanks in advance for any help!!!


    function findLinkEntities(contentBlock, callback, contentState){
        contentBlock.findEntityRanges((character) => {
            const entityKey = character.getEntity();
            return(
                entityKey !== null &&
                    contentState.getEntity(entityKey).getElementById() === 'LINK'
            )
        }, callback);
    }

    const Link = (props) => {
        const { url,linkText} = props.contentState
            .getEntity(props.entityKey)
            .getData()
        return (
            <a style={{color: '#006cb7', textDecoration: 'underline'}}
                href={url}>
                {linkText || props.children}
            </a>
        )
    }

    const linkDecorator = new CompositeDecorator([
        {
            strategy: findLinkEntities,
            component: Link,
      }
    ])



  [1]: https://codesandbox.io/s/nz8fj?file=/src/index.js
Zitieren
#2
Unfortunately I can't help you like that either.
Do you have online where you can test it exactly? I can't get any further there now, I would have to install them all myself first so that I can continue. If rzscout can't help you, you should ask the websites that created it and such.



Sorry, my English is very shit
Hier sind alle meine Lösungen aus allen Foren. Ich helfe auch in Facebook-chat
Als Lösung markieren Zitieren
#3
Hi Tim,
the problem is that, i can't help you, because i use only native/vanilla JavaScript and not React.

You have to ask your question in a special forum for React. Sorry, the question is too specific. Programming a RichTextEditor in JS is very, very complex as some functions like execCommand() are deprecated.
Cry
GG

rzscout
Als Lösung markieren Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste