draftjs-utils
Advanced tools
Comparing version 0.2.7 to 0.2.8
@@ -114,3 +114,3 @@ import { | ||
forEach(customInlineStylesMap.bgcolor, (key, value) => { | ||
assert.isDefined(value['background-color']); | ||
assert.isDefined(value.backgroundColor); | ||
}); | ||
@@ -127,3 +127,3 @@ forEach(customInlineStylesMap.fontSize, (key, value) => { | ||
forEach(customStyleMap, (key, value) => { | ||
assert.isDefined(value.color || value['background-color'] | ||
assert.isDefined(value.color || value.backgroundColor | ||
|| value.fontSize || value.fontFamily); | ||
@@ -130,0 +130,0 @@ }); |
@@ -12,2 +12,3 @@ /* @flow */ | ||
List, | ||
Map, | ||
} from 'immutable'; | ||
@@ -157,1 +158,43 @@ | ||
} | ||
/** | ||
* Function will add block level meta-data. | ||
*/ | ||
export function setBlockData(editorState: EditorState, data: Object): EditorState { | ||
const newContentState = Modifier.setBlockData( | ||
editorState.getCurrentContent(), | ||
editorState.getSelection(), | ||
data); | ||
return EditorState.push(editorState, newContentState, 'change-block-data'); | ||
} | ||
/** | ||
* Function will return currently selected blocks meta data. | ||
*/ | ||
export function getSelectedBlocksMetadata(editorState: EditorState): Map { | ||
let metaData = new Map({}); | ||
const selectedBlocks = getSelectedBlocksList(editorState); | ||
if (selectedBlocks && selectedBlocks.size > 0) { | ||
for (let i = 0; i < selectedBlocks.size; i++) { | ||
const data = selectedBlocks.get(i).getData(); | ||
if (!data || data.size === 0) { | ||
metaData = metaData.clear(); | ||
break; | ||
} | ||
if (i === 0) { | ||
metaData = data; | ||
} else { | ||
metaData.forEach((value, key) => { // eslint-disable-line no-loop-func | ||
if (!data.get(key) || data.get(key) !== value) { | ||
metaData = metaData.delete(key); | ||
} | ||
}); | ||
if (metaData.size === 0) { | ||
metaData = metaData.clear(); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
return metaData; | ||
} |
@@ -25,2 +25,4 @@ /* @flow */ | ||
clearEditorContent, | ||
setBlockData, | ||
getSelectedBlocksMetadata, | ||
} from './block'; | ||
@@ -47,2 +49,4 @@ import { | ||
clearEditorContent, | ||
setBlockData, | ||
getSelectedBlocksMetadata, | ||
// Functions related to inline styles | ||
@@ -49,0 +53,0 @@ colors, |
{ | ||
"name": "draftjs-utils", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "Collection of utility function for use with Draftjs.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
3847333
2735