draft-js-entity-props-plugin
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -11,10 +11,41 @@ 'use strict'; | ||
var _removeBlock = require('./utils/removeBlock'); | ||
var _removeBlock2 = _interopRequireDefault(_removeBlock); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var setEntityDataFn = function setEntityDataFn(contentBlock, _ref) { | ||
var getEditorState = _ref.getEditorState; | ||
var setEditorState = _ref.setEditorState; | ||
return function (data) { | ||
var entityKey = contentBlock.getEntityAt(0); | ||
if (entityKey) { | ||
var editorState = getEditorState(); | ||
_draftJs.Entity.mergeData(entityKey, _extends({}, data)); | ||
setEditorState(_draftJs.EditorState.forceSelection(editorState, editorState.getSelection())); | ||
} | ||
}; | ||
}; | ||
var removeBlockFn = function removeBlockFn(contentBlock, _ref2) { | ||
var getEditorState = _ref2.getEditorState; | ||
var setEditorState = _ref2.setEditorState; | ||
return function () { | ||
setEditorState((0, _removeBlock2.default)(getEditorState(), contentBlock.get('key'))); | ||
}; | ||
}; | ||
var entityPropsPlugin = function entityPropsPlugin() { | ||
return { | ||
blockRendererFn: function blockRendererFn(contentBlock) { | ||
blockRendererFn: function blockRendererFn(contentBlock, options) { | ||
var entityKey = contentBlock.getEntityAt(0); | ||
var data = entityKey ? _draftJs.Entity.get(entityKey).data : {}; | ||
// Add entity data to blockProps of all blocks | ||
return { | ||
props: _extends({}, data) | ||
props: _extends({ | ||
pluginEditor: options | ||
}, options, data, { | ||
setEntityData: setEntityDataFn(contentBlock, options), | ||
removeBlock: removeBlockFn(contentBlock, options) | ||
}) | ||
}; | ||
@@ -21,0 +52,0 @@ } |
{ | ||
"name": "draft-js-entity-props-plugin", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Entity Props Plugin for DraftJS", | ||
@@ -5,0 +5,0 @@ "author": { |
6105
8
107