question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider adding start, end, and blockKey to the props passed to DecoratorComponent

See original GitHub issue

Do you want to request a feature or report a bug?

Feature

What is the current behavior?

Currently, this is what we pass to DecoratorComponent:

        <DecoratorComponent
          {...decoratorProps}
          contentState={this.props.contentState}
          decoratedText={decoratedText}
          dir={dir}
          key={decoratorOffsetKey}
          entityKey={block.getEntityAt(leafSet.get('start'))}
          offsetKey={decoratorOffsetKey}>
          {leaves}
        </DecoratorComponent>

What is the expected desired behavior?

I’ve had it occur a few times where I would like to know the start and end of the text being decorated.

One use case would be to decorate some text with a menu that can replace that given decorated text with a suggestion from the menu… I can extract the blockKey from the offsetKey, but I can’t easily figure out the start or the end from the given props.

My workaround is pretty janky - my decorator strategy uses a predefined list of ranges to find the text to decorate. Each decorated component I care about gets the same class, so then when I click replace with suggestion, I pass the replacement word as well as the node that’s being clicked to the callback. Then the editor finds the index of that node among all of the decorated components with that classname , and cross references that with the list of text ranges I used in the strategy to decorate in the first place.

start, end, and the blockKey are readily available, but aren’t passed in.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:6
  • Comments:6

github_iconTop GitHub Comments

3reactions
Nachasiccommented, Oct 19, 2018

While the pull request is pending, i’ve created a small gist that shows how you might calculate start and end range values for a decorator: https://gist.github.com/Nachasic/55ba65be46463c70336d700121ec4b6c

0reactions
Nachasiccommented, Oct 15, 2018

I am having the same issue — trying to create a decorator with an entity bound to it, and I need to keep ranges in sync. Any progress on PR?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Draft-js building search and replace functionality - React Rocket
To start we'll clone the draft js boilerplate repository, let's cd into our app folder, run yarn to install all dependencies and get...
Read more >
Decorators - Draft.js
The Decorator Component will receive various pieces of metadata in props , including a copy of the contentState , the entityKey if there...
Read more >
How passing props to component works in React
Master how to pass props (properties) to components in React with this useful beginner's guide, including demo code.
Read more >
module draft-js function - GitHub Pages
hasEdgeWithin (blockKey, start, end); function draft-js. ... var decorator = nullthrows(_this2.props.decorator); var DecoratorComponent = decorator.
Read more >
Release 2.5.2 Torchbox - Wagtail Documentation
Wagtail provides a start command similar to django-admin startproject. ... The developer is expected to add these classes to their front end ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found