-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[WIP] Moving entities into content state #185 #376
[WIP] Moving entities into content state #185 #376
Conversation
Status update possible? Is there anyway we can help? Thanks for taking the initiative! |
@amireh I am waiting for initial feedback from @hellendag regarding this. |
@@ -62,7 +71,9 @@ function convertFromRawToDraftState( | |||
} | |||
); | |||
|
|||
return ContentState.createFromBlockArray(contentBlocks); | |||
const contentState = ContentState.createFromBlockArray(contentBlocks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might make sense for createFromBlockArray
to accept a second parameter for the entity map, rather than requiring the set
below.
Thanks for your patience. :) I think this is on the right track. A couple of comments here. Mostly I'm thinking we can just move everything directly into |
@hellendag I was on vacation last week. I hope I'll be able to take a look at this soon! :) |
Hey @johanneslumpe and @hellendag, this is awesome and in my opinion one of the more important things that need to be implemented atm. Not having entity state changes refresh the content state is a big pain point that gave me loads of headaches while developing plugins for draft-js-plugins, at the point were I change both component state and entity state to force atomic editor components to rerender, since forcing a rerender by setting selection doesn't work reliably. Is there anything you need help with? Has there been any further discussions about this PR internally @hellendag? |
@bkniffler Unfortunately I still didn't have time to revisit this - got some personal things to deal with right now. I will get back on this eventually though! |
@hellendag the only thing left to fix is the if (html) {
var htmlFragment = DraftPasteProcessor.processHTML(
html,
this.props.blockRenderMap
);
if (htmlFragment) {
var htmlMap = BlockMapBuilder.createFromArray(htmlFragment);
this.update(insertFragment(this.props.editorState, htmlMap));
return;
}
} So instead of having a fragment here, we could just return a new Another approach would be to pass |
…work with passed-in `ContentState` instance
@hellendag I went ahead and committed 012ea41 - it's one way to do it. we're generating additional objects now when parsing html now, but I'm not sure that that's a huge issue. Let's discuss what you think about it :) |
key: string, | ||
toMerge: {[key: string]: any} | ||
): ContentState { | ||
return updateEntityDataInContentState(this, key, toMerge, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you know, I don't love boolean arguments and return values. :) But I want to get this unblocked, so we can just revisit if needed.
Okay, let's go ahead and do this, then refine as needed. Thanks again for your patience! :) |
The link and media examples were using an outdated syntax that changed in [facebookarchive#376](facebookarchive#376). Old syntax: ``` const entityKey = Entity.create('LINK', 'MUTABLE', {url: urlValue}); ``` Correct: ``` const contentStateWithEntity = contentState.createEntity( 'LINK', 'MUTABLE', {url: urlValue} ); const entityKey = contentStateWithEntity.getLastCreatedEntityKey(); ``` Also while working on this, removed the 'require' of 'Entity' in the 'entity' example.
The link and media examples were using an outdated syntax that changed in [#376](#376). Old syntax: ``` const entityKey = Entity.create('LINK', 'MUTABLE', {url: urlValue}); ``` Correct: ``` const contentStateWithEntity = contentState.createEntity( 'LINK', 'MUTABLE', {url: urlValue} ); const entityKey = contentStateWithEntity.getLastCreatedEntityKey(); ``` Also while working on this, removed the 'require' of 'Entity' in the 'entity' example.
A previous PR had completely removed 'DraftEntity' the module and moved control over entities into ContentState.[1] This changed several public APIs of Draft.js in a non-backwards compabible way. [1]: facebookarchive#376 To make it easier to migrate multiple use cases to the new Draft.js API, and because the transition is too complex for a simple codemod, we are releasing a version that supports both the new and the old API and then later releasing a version that breaks the old API completely. In order to renew support for the old API while also supporting the new API, this PR - restores the DraftEntity module and associated tests/mocks - calls into DraftEntity methods under the hood of the new API We tried to leave as much of the new API code in place and unchanged as possible, so that things will be easier when we are fully removing DraftEntity and switching to the new approach. Next steps: - A PR to add warnings and comments about the deprecation of the old API - Add this, the warnings, and other recent PRs to 0.10.0 alpha version - Add documentation about migrating from deprecated to new API - Release 0.10.0; support both APIs - Make PR that basically undoes this one, moving entity control into ContentState, and release that as version 0.11.0, with warning that it no longer supports the deprecated API.
A previous PR had completely removed 'DraftEntity' the module and moved control over entities into ContentState.[1] This changed several public APIs of Draft.js in a non-backwards compabible way. [1]: #376 To make it easier to migrate multiple use cases to the new Draft.js API, and because the transition is too complex for a simple codemod, we are releasing a version that supports both the new and the old API and then later releasing a version that breaks the old API completely. In order to renew support for the old API while also supporting the new API, this PR - restores the DraftEntity module and associated tests/mocks - calls into DraftEntity methods under the hood of the new API We tried to leave as much of the new API code in place and unchanged as possible, so that things will be easier when we are fully removing DraftEntity and switching to the new approach. Next steps: - A PR to add warnings and comments about the deprecation of the old API - Add this, the warnings, and other recent PRs to 0.10.0 alpha version - Add documentation about migrating from deprecated to new API - Release 0.10.0; support both APIs - Make PR that basically undoes this one, moving entity control into ContentState, and release that as version 0.11.0, with warning that it no longer supports the deprecated API.
…karchive#376) * Initial demo changeset for entities in content state * lowercase string * add entity methods to content state * remove `DraftEntity` module * remove some `DraftEntity` requires * fix linting issues * fix flow issues * update `DraftPasteProcessor` and `convertFromHTMLtoContentBlocks` to work with passed-in `ContentState` instance * remove last traces of `DraftEntity` module * allow second argument for `createFromBlockArray` * use `contentState.getEntity` instead of pulling out entity map first * match exported function name * re-sort requires/imports to: classes, functions, types * respect 80 char limit * switch from random entity key to number * pass around `EntityMap` instance instead of `ContentState` when creating new html fragment * set new `entityMap` when regenerating block tree during editor state update, as the "current" content does not yet contain it * change entity key to be a numerical string to prevent enity-not-found error when using stringified key * fix flow errors
The link and media examples were using an outdated syntax that changed in [facebookarchive#376](facebookarchive#376). Old syntax: ``` const entityKey = Entity.create('LINK', 'MUTABLE', {url: urlValue}); ``` Correct: ``` const contentStateWithEntity = contentState.createEntity( 'LINK', 'MUTABLE', {url: urlValue} ); const entityKey = contentStateWithEntity.getLastCreatedEntityKey(); ``` Also while working on this, removed the 'require' of 'Entity' in the 'entity' example.
this pull request fixed broken Tex example by removing outdated syntax that changed in facebookarchive#376. refer issue to facebookarchive#697
A previous PR had completely removed 'DraftEntity' the module and moved control over entities into ContentState.[1] This changed several public APIs of Draft.js in a non-backwards compabible way. [1]: facebookarchive#376 To make it easier to migrate multiple use cases to the new Draft.js API, and because the transition is too complex for a simple codemod, we are releasing a version that supports both the new and the old API and then later releasing a version that breaks the old API completely. In order to renew support for the old API while also supporting the new API, this PR - restores the DraftEntity module and associated tests/mocks - calls into DraftEntity methods under the hood of the new API We tried to leave as much of the new API code in place and unchanged as possible, so that things will be easier when we are fully removing DraftEntity and switching to the new approach. Next steps: - A PR to add warnings and comments about the deprecation of the old API - Add this, the warnings, and other recent PRs to 0.10.0 alpha version - Add documentation about migrating from deprecated to new API - Release 0.10.0; support both APIs - Make PR that basically undoes this one, moving entity control into ContentState, and release that as version 0.11.0, with warning that it no longer supports the deprecated API.
The link and media examples were using an outdated syntax that changed in [#376](facebookarchive/draft-js#376). Old syntax: ``` const entityKey = Entity.create('LINK', 'MUTABLE', {url: urlValue}); ``` Correct: ``` const contentStateWithEntity = contentState.createEntity( 'LINK', 'MUTABLE', {url: urlValue} ); const entityKey = contentStateWithEntity.getLastCreatedEntityKey(); ``` Also while working on this, removed the 'require' of 'Entity' in the 'entity' example.
A previous PR had completely removed 'DraftEntity' the module and moved control over entities into ContentState.[1] This changed several public APIs of Draft.js in a non-backwards compabible way. [1]: facebookarchive/draft-js#376 To make it easier to migrate multiple use cases to the new Draft.js API, and because the transition is too complex for a simple codemod, we are releasing a version that supports both the new and the old API and then later releasing a version that breaks the old API completely. In order to renew support for the old API while also supporting the new API, this PR - restores the DraftEntity module and associated tests/mocks - calls into DraftEntity methods under the hood of the new API We tried to leave as much of the new API code in place and unchanged as possible, so that things will be easier when we are fully removing DraftEntity and switching to the new approach. Next steps: - A PR to add warnings and comments about the deprecation of the old API - Add this, the warnings, and other recent PRs to 0.10.0 alpha version - Add documentation about migrating from deprecated to new API - Release 0.10.0; support both APIs - Make PR that basically undoes this one, moving entity control into ContentState, and release that as version 0.11.0, with warning that it no longer supports the deprecated API.
This is just a very quick, hacky PR to showcase the general direction of how I want to approach things for #185. I mainly want to gather some feedback so we can discuss whether we want to keep
DraftEntity
and just use that to perform transactions on the state or whether we want to go a different route.I have updated most of the tests to pass. One is failing due to me not having implemented
DraftEntity.mergeData
and two other ones are failing because they rely on an implementation which requires acontentState
argument and I didn't refactor anything there yet.I'm totally down to refactor anything here or to go a different direction. Just wanted to get the ball rolling. But one way or another: this is going to be a breaking change ;)