draftjs-utils
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -14,3 +14,3 @@ import { assert } from 'chai'; | ||
customStyleMap, | ||
toggleInlineStyle, | ||
toggleCustomInlineStyle, | ||
customInlineStylesMap, | ||
@@ -134,3 +134,3 @@ getSelectionInlineStyle, | ||
describe('getSelectionInlineStyle, toggleInlineStyle test suite', () => { | ||
describe('getSelectionInlineStyle, toggleCustomInlineStyle test suite', () => { | ||
it('should correctly get color of selection', () => { | ||
@@ -148,3 +148,3 @@ const contentBlocks = convertFromHTML('<h1>aaaaaaaaaa</h1><ul><li>test</li></ul>'); | ||
); | ||
editorState = toggleInlineStyle(editorState, 'color', 'color-rgb(97,189,109)'); | ||
editorState = toggleCustomInlineStyle(editorState, 'color', 'color-rgb(97,189,109)'); | ||
assert.equal(getSelectionCustomInlineStyle( | ||
@@ -154,3 +154,3 @@ editorState, | ||
); | ||
editorState = toggleInlineStyle(editorState, 'bgcolor', 'bgcolor-rgb(97,189,109)'); | ||
editorState = toggleCustomInlineStyle(editorState, 'bgcolor', 'bgcolor-rgb(97,189,109)'); | ||
assert.equal(getSelectionCustomInlineStyle( | ||
@@ -157,0 +157,0 @@ editorState, |
@@ -8,3 +8,3 @@ import { assert } from 'chai'; | ||
import { getAllBlocks } from '../block'; | ||
import { handleNewLine } from '../keyPress'; | ||
import handleNewLine from '../keyPress'; | ||
@@ -11,0 +11,0 @@ describe('handleNewLine: Enter KeyPress test suite', () => { |
@@ -9,4 +9,5 @@ /* @flow */ | ||
getEntityRange, | ||
toggleInlineStyle, | ||
toggleCustomInlineStyle, | ||
getSelectionEntity, | ||
removeAllInlineStyles, | ||
getSelectionInlineStyle, | ||
@@ -55,4 +56,5 @@ getSelectionCustomInlineStyle, | ||
getEntityRange, | ||
toggleInlineStyle, | ||
toggleCustomInlineStyle, | ||
getSelectionEntity, | ||
removeAllInlineStyles, | ||
getSelectionInlineStyle, | ||
@@ -59,0 +61,0 @@ getSelectionCustomInlineStyle, |
@@ -176,3 +176,3 @@ /* @flow */ | ||
*/ | ||
export function toggleInlineStyle( | ||
export function toggleCustomInlineStyle( | ||
editorState: EditorState, | ||
@@ -262,1 +262,20 @@ styleType: string, | ||
} | ||
/** | ||
* Function to remove all inline styles applied to the selection. | ||
*/ | ||
export function removeAllInlineStyles(editorState: EditorState): void { | ||
const currentStyles = editorState.getCurrentInlineStyle(); | ||
let contentState = editorState.getCurrentContent(); | ||
currentStyles.forEach((style) => { | ||
contentState = Modifier.removeInlineStyle( | ||
contentState, | ||
editorState.getSelection(), | ||
style | ||
); | ||
}); | ||
return EditorState.push(editorState, contentState, 'change-inline-style'); | ||
} | ||
// todo: add unit test cases. |
{ | ||
"name": "draftjs-utils", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Collection of utility function for use with Draftjs.", | ||
@@ -5,0 +5,0 @@ "main": "lib/draftjs-utils.js", |
@@ -21,3 +21,3 @@ # DraftJS Utils | ||
| 6 | removeSelectedBlocksStyle | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | The function will reset the type of selected Blocks to `unstyled`.| | ||
| 7 | getSelectionText | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | string | The function will return plain text of current selection.| | ||
| 7 | getSelectionText | [EditorState](https://facebook.githubgetSelectionInlineStyle.io/draft-js/docs/api-reference-editor-state.html#content) | string | The function will return plain text of current selection.| | ||
| 8 | addLineBreakRemovingSelection | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | The function will replace currently selected text with a `\n`.| | ||
@@ -27,9 +27,14 @@ | 9 | insertNewUnstyledBlock | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) |[EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | The function will add a new unstyled Block and copy current selection to it.| | ||
| 11 | getSelectionInlineStyle | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | object | The function will return inline style applicable to current selection. The function will return only those styles that are applicable to whole selection.| | ||
| 12 | getSelectionEntity | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | [Entity](https://facebook.github.io/draft-js/docs/api-reference-entity.html#content) | The function will return the Entity of current selection. Entity can not span multiple Blocks, method will check only first selected Block.| | ||
| 13 | getEntityRange | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content), entityKey | object | The function will return the range of given Entity in currently selected Block. Entity can not span multiple Blocks, method will check only first selected Block.| | ||
| 14 | handleNewLine | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) |[EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content), Event | The function will handle newline event in editor gracefully, it will insert `\n` for soft-new lines and remove selected text if any. | | ||
| 15 | isListBlock | [ContentBlock](https://facebook.github.io/draft-js/docs/api-reference-content-block.html#content) | boolean | The function will return true is type of block is 'unordered-list-item' or 'ordered-list-item'.| | ||
| 16 | changeDepth | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) , adjustment, maxDepth | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | Change the depth of selected Blocks by adjustment if its less than maxdepth.| | ||
| 12 | setBlockData | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content), object | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | The function will add block level meta-data.| | ||
| 13 | getSelectedBlocksMetadata | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | [Map](https://facebook.github.io/immutable-js/docs/#/Map) | The function will return map of block data of current block.| | ||
| 14 | getSelectionEntity | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | [Entity](https://facebook.github.io/draft-js/docs/api-reference-entity.html#content) | The function will return the Entity of current selection. Entity can not span multiple Blocks, method will check only first selected Block.| | ||
| 15 | getEntityRange | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content), entityKey | object | The function will return the range of given Entity in currently selected Block. Entity can not span multiple Blocks, method will check only first selected Block.| | ||
| 16 | handleNewLine | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) |[EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content), Event | The function will handle newline event in editor gracefully, it will insert `\n` for soft-new lines and remove selected text if any. | | ||
| 17 | isListBlock | [ContentBlock](https://facebook.github.io/draft-js/docs/api-reference-content-block.html#content) | boolean | The function will return true is type of block is 'unordered-list-item' or 'ordered-list-item'.| | ||
| 18 | changeDepth | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) , adjustment, maxDepth | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | Change the depth of selected Blocks by adjustment if its less than maxdepth.| | ||
| 19 | getSelectionCustomInlineStyle | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) , Array<String> (of styles) | object | Function will return Map of custom inline styles applicable to current selection.| | ||
| 20 | toggleCustomInlineStyle | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) , string (styleType), string(styleValue) | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | Toggle application of custom inline style to current selection.| | ||
| 21 | removeAllInlineStyles | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | [EditorState](https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#content) | The function will remove all inline styles of current selection.| | ||
## License | ||
MIT. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4073142
2804
39
0