|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var EditorState = require('draft-js/lib/EditorState'); |
|
|
|
|
|
var ContentState = require('draft-js/lib/ContentState'); |
|
|
|
|
|
var convertFromRaw = require('draft-js/lib/convertFromRawToDraftState'); |
|
|
|
|
|
var convertToRaw = require('draft-js/lib/convertFromDraftStateToRaw'); |
|
|
|
|
|
var toPlainText = function toPlainText( |
|
|
editorState |
|
|
) { |
|
|
return editorState.getCurrentContent().getPlainText(); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var emptyContentState = convertFromRaw({ |
|
|
entityMap: {}, |
|
|
blocks: [ |
|
|
{ |
|
|
text: '', |
|
|
key: 'foo', |
|
|
type: 'unstyled', |
|
|
entityRanges: [], |
|
|
}, |
|
|
], |
|
|
}); |
|
|
|
|
|
var fromPlainText = function fromPlainText( |
|
|
text |
|
|
) { |
|
|
if (!text || text === '') |
|
|
return EditorState.createWithContent(emptyContentState); |
|
|
return EditorState.createWithContent(ContentState.createFromText(text)); |
|
|
}; |
|
|
|
|
|
var toJSON = function toJSON( |
|
|
editorState |
|
|
) { |
|
|
return convertToRaw(editorState.getCurrentContent()); |
|
|
}; |
|
|
|
|
|
var toState = function toState(json ) { |
|
|
return EditorState.createWithContent(convertFromRaw(json)); |
|
|
}; |
|
|
|
|
|
var isAndroid = function isAndroid() { |
|
|
return navigator.userAgent.toLowerCase().indexOf('android') > -1; |
|
|
}; |
|
|
|
|
|
module.exports = { |
|
|
toJSON: toJSON, |
|
|
toState: toState, |
|
|
toPlainText: toPlainText, |
|
|
fromPlainText: fromPlainText, |
|
|
emptyContentState: emptyContentState, |
|
|
isAndroid: isAndroid, |
|
|
}; |
|
|
|