This repository was archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
now accepts draftjs model as input, stringified model #32
Open
cherucole
wants to merge
1
commit into
react-native-toolkit:setup-bob
Choose a base branch
from
cherucole:setup-bob
base: setup-bob
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,9 @@ import { | |
| DefaultDraftBlockRenderMap, | ||
| DraftHandleValue, | ||
| convertToRaw, | ||
| ContentState, | ||
| convertFromRaw, | ||
| convertFromHTML, | ||
| } from 'draft-js'; | ||
| import { stateFromHTML } from 'draft-js-import-html'; | ||
| import { stateToHTML } from 'draft-js-export-html'; | ||
|
|
@@ -17,6 +20,8 @@ import EditorController from './Components/EditorController/EditorController'; | |
| import { ICustomWindow } from './types/ICustomWindow'; | ||
|
|
||
| declare let window: ICustomWindow; | ||
| const blob = | ||
| '{"blocks":[{"key":"bkha4","text":"This is a Main Heading","type":"header-one","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"76ipm","text":"This is a text block.","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"ascg","text":"This is a list","type":"unordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"9um5u","text":"With multiple items","type":"unordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"5l5nn","text":"In it","type":"unordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"c4p9a","text":"This is a sub-heading","type":"header-two","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"4vqhn","text":"And this is another text block","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"3vknd","text":"This is a numbered","type":"ordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"56mei","text":"List with about","type":"ordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"365ag","text":"3 items in it","type":"ordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"6mtqe","text":"This is a small heading","type":"header-three","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"78d5h","text":"And this is some formatted text","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":4,"length":4,"style":"SUPERSCRIPT"},{"offset":9,"length":2,"style":"STRIKETHROUGH"},{"offset":12,"length":4,"style":"ITALIC"},{"offset":17,"length":9,"style":"BOLD"},{"offset":27,"length":4,"style":"UNDERLINE"}],"entityRanges":[],"data":{}}],"entityMap":{}}'; | ||
|
|
||
| /** | ||
| * For testing the post messages | ||
|
|
@@ -29,10 +34,13 @@ declare let window: ICustomWindow; | |
| export type defaultSourceType = 'string'; | ||
|
|
||
| function App() { | ||
|
|
||
| const _draftEditorRef = useRef<Editor>(null); | ||
|
|
||
| const [editorState, setEditorState] = useState(() => | ||
| EditorState.createEmpty() | ||
| ); | ||
|
|
||
| const [placeholder, setPlaceholder] = useState(''); | ||
| const [editorStyle, setEditorStyle] = useState(''); | ||
| const [styleMap, setStyleMap] = useState({}); | ||
|
|
@@ -80,7 +88,8 @@ function App() { | |
| const setDefaultValue = (data: defaultSourceType) => { | ||
| try { | ||
| if (data) { | ||
| setEditorState(EditorState.createWithContent(stateFromHTML(data))); | ||
| const stateFromBlob = convertFromRaw(JSON.parse(data)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have the text editor running for other people that uses HTML as the default input. We probably have to keep using html as the default data for the inputs. However, provide an additional layer that will accept default value using different formats. For eg: |
||
| setEditorState(EditorState.createWithContent(stateFromBlob)); | ||
| } | ||
| } catch (e) { | ||
| console.error(e); | ||
|
|
@@ -146,6 +155,7 @@ function App() { | |
| JSON.stringify({ | ||
| editorState: stateToHTML(editorState.getCurrentContent()), | ||
| rawState: convertToRaw(editorState.getCurrentContent()), | ||
| plainText: editorState.getCurrentContent().getPlainText('\u0001'), | ||
| markdownState: stateToMarkdown(editorState.getCurrentContent()), | ||
| blockType: editorBlockType, | ||
| styles: styleString, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure why we need this data for...