You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

draft-js-plugins-editor

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

draft-js-plugins-editor - npm Package Compare versions

Comparing version

to
1.1.0

8

CHANGELOG.md

@@ -8,2 +8,8 @@ # Change Log

## 1.1.0 - 2016-05-30
### Added
- Added `willUnmount` hook. This hook receives one object as argument, which contains `getEditorState` & `setEditorState`. The hook will be executed once the Editor component is about to be unmounted.
## 1.0.1 - 2016-05-03

@@ -24,3 +30,3 @@

- Added propTypes to the Editor
- Added `initialize` hook. This hook receives one object as argument. The object contains `getEditorState` & `setEditorState`.
- Added `initialize` hook. This hook receives one object as argument, which contains `getEditorState` & `setEditorState`.

@@ -27,0 +33,0 @@ ## 0.2.0 - 2016-03-25

@@ -208,2 +208,24 @@ 'use strict';

it('calls willUnmount', function () {
var plugins = [{
willUnmount: _sinon2.default.spy()
}];
var result = (0, _enzyme.mount)(_react2.default.createElement(_index2.default, {
editorState: editorState,
onChange: onChange,
plugins: plugins
}));
var pluginEditor = result.node;
var plugin = plugins[0];
var expectedArgument = {
getEditorState: pluginEditor.getEditorState,
setEditorState: pluginEditor.onChange
};
result.unmount();
(0, _chai.expect)(plugin.willUnmount).has.been.calledOnce();
(0, _chai.expect)(plugin.willUnmount).has.been.calledWith(expectedArgument);
});
it('calls the handle- and on-hooks of the first plugin and not the second in case it was handeled', function () {

@@ -210,0 +232,0 @@ var plugins = [{

50

lib/Editor/index.js

@@ -140,3 +140,17 @@ 'use strict';

}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
var _this2 = this;
this.resolvePlugins().forEach(function (plugin) {
if (plugin.willUnmount) {
plugin.willUnmount({
getEditorState: _this2.getEditorState,
setEditorState: _this2.onChange
});
}
});
}
// Cycle through the plugins, changing the editor state with what the plugins

@@ -179,7 +193,7 @@ // changed (or didn't)

var _initialiseProps = function _initialiseProps() {
var _this2 = this;
var _this3 = this;
this.onChange = function (editorState) {
var newEditorState = editorState;
_this2.resolvePlugins().forEach(function (plugin) {
_this3.resolvePlugins().forEach(function (plugin) {
if (plugin.onChange) {

@@ -190,4 +204,4 @@ newEditorState = plugin.onChange(newEditorState);

if (_this2.props.onChange) {
_this2.props.onChange(newEditorState);
if (_this3.props.onChange) {
_this3.props.onChange(newEditorState);
}

@@ -197,3 +211,3 @@ };

this.getEditorState = function () {
return _this2.props.editorState;
return _this3.props.editorState;
};

@@ -209,4 +223,4 @@

newArgs.push({
getEditorState: _this2.getEditorState,
setEditorState: _this2.onChange
getEditorState: _this3.getEditorState,
setEditorState: _this3.onChange
});

@@ -253,4 +267,4 @@ var _iteratorNormalCompletion3 = true;

newArgs.push({
getEditorState: _this2.getEditorState,
setEditorState: _this2.onChange
getEditorState: _this3.getEditorState,
setEditorState: _this3.onChange
});

@@ -390,3 +404,3 @@

var fnHookKeys = [];
var plugins = [_this2.props].concat(_toConsumableArray(_this2.resolvePlugins()));
var plugins = [_this3.props].concat(_toConsumableArray(_this3.resolvePlugins()));

@@ -415,7 +429,7 @@ plugins.forEach(function (plugin) {

eventHookKeys.forEach(function (attrName) {
pluginHooks[attrName] = _this2.createEventHooks(attrName, plugins);
pluginHooks[attrName] = _this3.createEventHooks(attrName, plugins);
});
fnHookKeys.forEach(function (attrName) {
pluginHooks[attrName] = _this2.createFnHooks(attrName, plugins);
pluginHooks[attrName] = _this3.createFnHooks(attrName, plugins);
});

@@ -427,4 +441,4 @@

this.resolvePlugins = function () {
var plugins = _this2.props.plugins.slice(0);
if (_this2.props.defaultKeyBindings) {
var plugins = _this3.props.plugins.slice(0);
if (_this3.props.defaultKeyBindings) {
plugins.push(defaultKeyBindingPlugin);

@@ -437,3 +451,3 @@ }

this.resolveDecorators = function () {
var _props = _this2.props;
var _props = _this3.props;
var decorators = _props.decorators;

@@ -450,7 +464,7 @@ var plugins = _props.plugins;

this.resolveCustomStyleMap = function () {
return _this2.props.plugins.filter(function (plug) {
return _this3.props.plugins.filter(function (plug) {
return plug.customStyleMap !== undefined;
}).map(function (plug) {
return plug.customStyleMap;
}).concat([_this2.props.customStyleMap]).reduce(function (styles, style) {
}).concat([_this3.props.customStyleMap]).reduce(function (styles, style) {
return _extends({}, styles, style);

@@ -462,3 +476,3 @@ }, {});

var accessibilityProps = {};
var plugins = [_this2.props].concat(_toConsumableArray(_this2.resolvePlugins()));
var plugins = [_this3.props].concat(_toConsumableArray(_this3.resolvePlugins()));
var _iteratorNormalCompletion7 = true;

@@ -465,0 +479,0 @@ var _didIteratorError7 = false;

{
"name": "draft-js-plugins-editor",
"version": "1.0.1",
"version": "1.1.0",
"description": "Editor for DraftJS Plugins",

@@ -5,0 +5,0 @@ "author": {