-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Context-oriented behaviour #61
Comments
You're absolutely right. The context-orientation behavior is really useful, which hasn't been implement in the We actually do this in Facebook Notes. It seems like this will be a really common question and could be provided through the |
For resetting block type, you can use https://github.com/facebook/draft-js/blob/master/src/model/modifier/RichTextEditorUtil.js#L406 within a We could create a For nested lists, see http://facebook.github.io/draft-js/docs/advanced-topics-nested-lists.html#content. |
Going to close this because I think we can allow clients to define this behavior themselves. If it comes up more and it seems there is an obvious default, then we can reassess. :) |
…(Fixes issue #2226) (#2240) Summary: **Summary** When passing `createWithContent` a `state` parameter created using `convertFromHTML` from an empty string and `createFromBlockArray`, as shown in the example: ``` const sampleMarkup = '<b>Bold text</b>, <i>Italic text</i><br/ ><br />' + '<a href="http://www.facebook.com">Example link</a><br /><br/ >' + '<img src="image.png" height="112" width="200" />'; const blocksFromHTML = convertFromHTML(sampleMarkup); const state = ContentState.createFromBlockArray( blocksFromHTML.contentBlocks, blocksFromHTML.entityMap, ); this.state = { editorState: EditorState.createWithContent( state, decorator, ), }; ``` The following error is thrown: ``` TypeError: Cannot read property 'getKey' of undefined 84 | EditorState.createWithContent = function createWithContent(contentState, decorator) { > 85 | var firstKey = contentState.getBlockMap().first().getKey(); | ^ 86 | return EditorState.create({ 87 | currentContent: contentState, 88 | undoStack: Stack(), ``` The previous error is generated because `createWithContent` asumes that `contentState.getBlockMap().first()` will return an element, which is wrong for scenarios where the block map is empty. As a consecuence the `getKey();` function in `contentState.getBlockMap().first().getKey();` is executed on `undefined`, thus throwing the error. The previous scenario is very common if you are planning to use the editor to allow a user to write HTML content which could also be blank, especially as a default value. **Solution** In order to make the less amount of modifications to the code, I've added a validation that will run `createEmpty` in case the block map is empty. **Test Plan** Open `/draft-js/examples/draft-0-10-0/convertFromHTML/convert.html` and change line #61 from: `const blocksFromHTML = convertFromHTML(sampleMarkup);` to: `const blocksFromHTML = convertFromHTML('');` No error will be shown. Pull Request resolved: #2240 Differential Revision: D18247644 Pulled By: mrkev fbshipit-source-id: 3eb90fd5379e8a2d85efbb2b7b9587ca87701d12
…(Fixes issue facebookarchive#2226) (facebookarchive#2240) Summary: **Summary** When passing `createWithContent` a `state` parameter created using `convertFromHTML` from an empty string and `createFromBlockArray`, as shown in the example: ``` const sampleMarkup = '<b>Bold text</b>, <i>Italic text</i><br/ ><br />' + '<a href="http://www.facebook.com">Example link</a><br /><br/ >' + '<img src="image.png" height="112" width="200" />'; const blocksFromHTML = convertFromHTML(sampleMarkup); const state = ContentState.createFromBlockArray( blocksFromHTML.contentBlocks, blocksFromHTML.entityMap, ); this.state = { editorState: EditorState.createWithContent( state, decorator, ), }; ``` The following error is thrown: ``` TypeError: Cannot read property 'getKey' of undefined 84 | EditorState.createWithContent = function createWithContent(contentState, decorator) { > 85 | var firstKey = contentState.getBlockMap().first().getKey(); | ^ 86 | return EditorState.create({ 87 | currentContent: contentState, 88 | undoStack: Stack(), ``` The previous error is generated because `createWithContent` asumes that `contentState.getBlockMap().first()` will return an element, which is wrong for scenarios where the block map is empty. As a consecuence the `getKey();` function in `contentState.getBlockMap().first().getKey();` is executed on `undefined`, thus throwing the error. The previous scenario is very common if you are planning to use the editor to allow a user to write HTML content which could also be blank, especially as a default value. **Solution** In order to make the less amount of modifications to the code, I've added a validation that will run `createEmpty` in case the block map is empty. **Test Plan** Open `/draft-js/examples/draft-0-10-0/convertFromHTML/convert.html` and change line facebookarchive#61 from: `const blocksFromHTML = convertFromHTML(sampleMarkup);` to: `const blocksFromHTML = convertFromHTML('');` No error will be shown. Pull Request resolved: facebookarchive#2240 Differential Revision: D18247644 Pulled By: mrkev fbshipit-source-id: 3eb90fd5379e8a2d85efbb2b7b9587ca87701d12
…(Fixes issue facebookarchive#2226) (facebookarchive#2240) Summary: **Summary** When passing `createWithContent` a `state` parameter created using `convertFromHTML` from an empty string and `createFromBlockArray`, as shown in the example: ``` const sampleMarkup = '<b>Bold text</b>, <i>Italic text</i><br/ ><br />' + '<a href="http://www.facebook.com">Example link</a><br /><br/ >' + '<img src="image.png" height="112" width="200" />'; const blocksFromHTML = convertFromHTML(sampleMarkup); const state = ContentState.createFromBlockArray( blocksFromHTML.contentBlocks, blocksFromHTML.entityMap, ); this.state = { editorState: EditorState.createWithContent( state, decorator, ), }; ``` The following error is thrown: ``` TypeError: Cannot read property 'getKey' of undefined 84 | EditorState.createWithContent = function createWithContent(contentState, decorator) { > 85 | var firstKey = contentState.getBlockMap().first().getKey(); | ^ 86 | return EditorState.create({ 87 | currentContent: contentState, 88 | undoStack: Stack(), ``` The previous error is generated because `createWithContent` asumes that `contentState.getBlockMap().first()` will return an element, which is wrong for scenarios where the block map is empty. As a consecuence the `getKey();` function in `contentState.getBlockMap().first().getKey();` is executed on `undefined`, thus throwing the error. The previous scenario is very common if you are planning to use the editor to allow a user to write HTML content which could also be blank, especially as a default value. **Solution** In order to make the less amount of modifications to the code, I've added a validation that will run `createEmpty` in case the block map is empty. **Test Plan** Open `/draft-js/examples/draft-0-10-0/convertFromHTML/convert.html` and change line facebookarchive#61 from: `const blocksFromHTML = convertFromHTML(sampleMarkup);` to: `const blocksFromHTML = convertFromHTML('');` No error will be shown. Pull Request resolved: facebookarchive#2240 Differential Revision: D18247644 Pulled By: mrkev fbshipit-source-id: 3eb90fd5379e8a2d85efbb2b7b9587ca87701d12
Hello and thank you for your yet another awesome solution.
Just watched the demo on project page and noticed it doesn't have context-oriented behaviour. What does it mean?
It seems the good example for improving UX is focusing on Apple Pages to get good ideas and inherit user expectations.
The text was updated successfully, but these errors were encountered: