Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

draft-extend

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

draft-extend - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

14

dist/draft-extend.js

@@ -161,2 +161,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

getReadOnly: _react.PropTypes.func,
setReadOnly: _react.PropTypes.func,
onChange: _react.PropTypes.func

@@ -184,3 +185,4 @@ },

return {
decorator: decorator
decorator: decorator,
readOnly: false
};

@@ -192,2 +194,3 @@ },

getReadOnly: this.getReadOnly,
setReadOnly: this.setReadOnly,
onChange: this.props.onChange

@@ -307,4 +310,7 @@ };

getReadOnly: function getReadOnly() {
return this.props.readOnly;
return this.state.readOnly || this.props.readOnly;
},
setReadOnly: function setReadOnly(readOnly) {
this.setState({ readOnly: readOnly });
},
getDecoratedState: function getDecoratedState() {

@@ -369,5 +375,6 @@ var editorState = this.props.editorState;

var decoratedState = this.getDecoratedState();
var className = 'draft-extend ' + this.props.className;
var readOnly = this.getReadOnly();
return _react2.default.createElement(

@@ -387,2 +394,3 @@ 'div',

editorState: decoratedState,
readOnly: readOnly,
onChange: onChange,

@@ -389,0 +397,0 @@ blockStyleFn: blockStyleFn,

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("Immutable"),require("React"),require("Draft"),require("ReactDOM")):"function"==typeof define&&define.amd?define(["Immutable","React","Draft","ReactDOM"],t):"object"==typeof exports?exports.DraftExtend=t(require("Immutable"),require("React"),require("Draft"),require("ReactDOM")):e.DraftExtend=t(e.Immutable,e.React,e.Draft,e.ReactDOM)}(this,function(e,t,n,r){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t.compose=t.pluginUtils=t.createPlugin=t.Editor=void 0;var o=n(4),i=r(o),a=n(6),s=r(a),u=n(7),c=r(u),l=n(10),d=r(l);t.Editor=i.default,t.createPlugin=s.default,t.pluginUtils=c.default,t.compose=d.default},function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t){e.exports=n},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}Object.defineProperty(t,"__esModule",{value:!0});var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a=n(2),s=r(a),u=n(1),c=n(3),l=n(5),d=r(l),f={className:a.PropTypes.string,editorState:a.PropTypes.object,onChange:a.PropTypes.func,decorators:a.PropTypes.array,styleMap:a.PropTypes.object,buttons:a.PropTypes.array,overlays:a.PropTypes.array,blockRendererFn:a.PropTypes.func,blockStyleFn:a.PropTypes.func,keyBindingFn:a.PropTypes.func,keyCommandListeners:a.PropTypes.arrayOf(a.PropTypes.func),handleReturn:a.PropTypes.func,onEscape:a.PropTypes.func,onTab:a.PropTypes.func,onUpArrow:a.PropTypes.func,onDownArrow:a.PropTypes.func,readOnly:a.PropTypes.bool};t.default=s.default.createClass({displayName:"Editor",propTypes:f,childContextTypes:{getEditorState:a.PropTypes.func,getReadOnly:a.PropTypes.func,onChange:a.PropTypes.func},getDefaultProps:function(){return{className:"",editorState:c.EditorState.createEmpty(),onChange:function(){},decorators:[],styleMap:{},buttons:[],overlays:[],blockRendererFn:function(){},blockStyleFn:function(){},keyBindingFn:function(){},keyCommandListeners:[],readOnly:!1}},getInitialState:function(){var e=new c.CompositeDecorator(this.props.decorators);return{decorator:e}},getChildContext:function(){return{getEditorState:this.getDecoratedState,getReadOnly:this.getReadOnly,onChange:this.props.onChange}},componentWillMount:function(){this.keyCommandListeners=(0,u.List)(this.props.keyCommandListeners)},componentWillReceiveProps:function(e){if(e.decorators.length===this.state.decorator._decorators.length){var t=this.state.decorator._decorators.every(function(t,n){return t===e.decorators[n]});if(t)return}this.setState({decorator:new c.CompositeDecorator(e.decorators)})},addKeyCommandListener:function(e){this.keyCommandListeners=this.keyCommandListeners.unshift(e)},removeKeyCommandListener:function(e){this.keyCommandListeners=this.keyCommandListeners.filterNot(function(t){return t===e})},keyBindingFn:function(e){var t=this.props.keyBindingFn(e);return t?t:(0,c.getDefaultKeyBinding)(e)},handleKeyCommand:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?null:arguments[1],r=this.getDecoratedState(),o=this.keyCommandListeners.reduce(function(r,o){var i=r.state,a=r.hasChanged;if(a===!0)return{state:i,hasChanged:a};var s=o(i,e,n),u=s instanceof c.EditorState;return s===!0||u&&s!==i?u?(t.props.onChange(s),{state:s,hasChanged:!0}):{state:i,hasChanged:!0}:{state:i,hasChanged:a}},{state:r,hasChanged:!1});return o.hasChanged},handleReturn:function(e){return this.props.handleReturn&&this.props.handleReturn(e)||this.handleKeyCommand("return",e)},onEscape:function(e){return this.props.onEscape&&this.props.onEscape(e)||this.handleKeyCommand("escape",e)},onTab:function(e){return this.props.onTab&&this.props.onTab(e)||this.handleKeyCommand("tab",e)},onUpArrow:function(e){return this.props.onUpArrow&&this.props.onUpArrow(e)||this.handleKeyCommand("up-arrow",e)},onDownArrow:function(e){return this.props.onDownArrow&&this.props.onDownArrow(e)||this.handleKeyCommand("down-arrow",e)},focus:function(){this.refs.editor.focus()},blur:function(){this.refs.editor.blur()},getOtherProps:function(){var e=this,t=Object.keys(this.props),n=Object.keys(f),r=t.filter(function(e){return n.indexOf(e)===-1});return r.reduce(function(t,n){return t[n]=e.props[n],t},{})},getReadOnly:function(){return this.props.readOnly},getDecoratedState:function(){var e=this.props.editorState,t=this.state.decorator,n=e.getDecorator();return n&&n._decorators===t._decorators?e:c.EditorState.set(e,{decorator:t})},renderPluginButtons:function(){var e=this,t=this.getDecoratedState();return this.props.buttons.map(function(n,r){return s.default.createElement("li",{key:"button-"+r},s.default.createElement(n,i({},e.getOtherProps(),{editorState:t,onChange:e.props.onChange,addKeyCommandListener:e.addKeyCommandListener,removeKeyCommandListener:e.removeKeyCommandListener})))})},renderOverlays:function(){var e=this,t=this.getDecoratedState();return this.props.overlays.map(function(n,r){return s.default.createElement(d.default,{key:r},s.default.createElement(n,i({},e.getOtherProps(),{editorState:t,onChange:e.props.onChange,addKeyCommandListener:e.addKeyCommandListener,removeKeyCommandListener:e.removeKeyCommandListener})))})},render:function(){var e=this.props,t=e.styleMap,n=e.blockRendererFn,r=e.blockStyleFn,a=e.onChange,u=o(e,["styleMap","blockRendererFn","blockStyleFn","onChange"]),l=this.getDecoratedState(),d="draft-extend "+this.props.className;return s.default.createElement("div",{className:d},s.default.createElement("ul",{className:"draft-extend-controls"},this.renderPluginButtons()),s.default.createElement("div",{className:"draft-extend-editor"},s.default.createElement(c.Editor,i({},u,{ref:"editor",editorState:l,onChange:a,blockStyleFn:r,blockRendererFn:n,customStyleMap:t,keyBindingFn:this.keyBindingFn,handleKeyCommand:this.handleKeyCommand,handleReturn:this.handleReturn,onEscape:this.onEscape,onTab:this.onTab,onUpArrow:this.onUpArrow,onDownArrow:this.onDownArrow})),s.default.createElement("div",{className:"draft-extend-overlays"},this.renderOverlays())))}})},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(2),i=r(o),a=n(13),s=r(a);t.default=i.default.createClass({displayName:"OverlayWrapper",getInitialState:function(){var e=document.createElement("div");return document.body.appendChild(e),{node:e}},componentDidMount:function(){this.renderOverlay()},componentDidUpdate:function(){this.renderOverlay()},componentWillUnmount:function(){s.default.unmountComponentAtNode(this.state.node)},renderOverlay:function(){var e=i.default.Children.only(this.props.children);s.default.render(e,this.state.node)},render:function(){return null}})},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a=n(2),s=r(a),u=n(11),c=r(u),l=n(9),d=r(l),f=n(8),p=r(f),y=function(){},h=[],m={},g=function(e,t,n){return n},v=function(e,t,n){},b=function(e,t){},T=function(e){return[]},C=function(e){},k=function(e,t){return t},S=(0,c.default)(d.default),E=(0,c.default)(p.default),P=(0,c.default)(function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return Object.assign.apply(Object,[{}].concat(t))}),O=(0,c.default)(function(e,t){return e.concat(t)}),M=(0,c.default)(function(e){return Array.isArray(e)?e:[e]}),L=function w(e){var t=e.displayName,n=void 0===t?"Plugin":t,r=e.decorators,u=void 0===r?h:r,c=e.buttons,l=void 0===c?h:c,d=e.overlays,f=void 0===d?h:d,p=e.styleMap,L=void 0===p?m:p,F=e.blockRendererFn,R=void 0===F?y:F,x=e.blockStyleFn,_=void 0===x?y:x,A=e.keyBindingFn,B=void 0===A?y:A,D=e.keyCommandListener,K=void 0===D?y:D,j=e.htmlToStyle,H=void 0===j?g:j,N=e.htmlToBlock,U=void 0===N?v:N,q=e.htmlToEntity,I=void 0===q?b:q,W=e.textToEntity,z=void 0===W?T:W,V=e.styleToHTML,Z=void 0===V?m:V,G=e.blockToHTML,J=void 0===G?C:G,Q=e.entityToHTML,X=void 0===Q?k:Q;return function(e){return u=M(u),l=M(l),f=M(f),e.prototype&&e.prototype.isReactComponent?s.default.createClass({displayName:n,propTypes:{styleMap:a.PropTypes.object,decorators:a.PropTypes.array,buttons:a.PropTypes.array,overlays:a.PropTypes.array,blockRendererFn:a.PropTypes.func,blockStyleFn:a.PropTypes.func,keyBindingFn:a.PropTypes.func,keyCommandListeners:a.PropTypes.arrayOf(a.PropTypes.func)},getDefaultProps:function(){return{styleMap:m,decorators:h,buttons:h,overlays:h,blockRendererFn:y,blockStyleFn:y,keyBindingFn:y,keyCommandListeners:h}},focus:function(){this.refs.child.focus&&this.refs.child.focus()},blur:function(){this.refs.child.blur&&this.refs.child.blur()},render:function(){var t=P(this.props.styleMap,L),n=O(this.props.decorators,u),r=O(this.props.buttons,l),o=O(this.props.overlays,f),a=E(R,this.props.blockRendererFn),c=E(_,this.props.blockStyleFn),d=E(B,this.props.keyBindingFn),p=O(this.props.keyCommandListeners,M(K));return s.default.createElement(e,i({},this.props,{ref:"child",styleMap:t,decorators:n,buttons:r,overlays:o,blockRendererFn:a,blockStyleFn:c,keyBindingFn:d,keyCommandListeners:p}))}}):function(){for(var t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];if(1===n.length&&("string"==typeof n[0]||n[0].hasOwnProperty("_map")&&null!=n[0].getBlockMap))return e({htmlToStyle:H,htmlToBlock:U,htmlToEntity:I,textToEntity:z,styleToHTML:Z,blockToHTML:J,entityToHTML:X}).apply(void 0,n);var i=function(){var t=n[0],r=function(e,n,r){var o=t.htmlToStyle(e,n,r);return H(e,n,o)},o=E(U,t.htmlToBlock),i=E(I,t.htmlToEntity),a=function(e){return t.textToEntity(e).concat(z(e))},s=Object.assign({},t.styleToHTML,Z),u=E(S(J),S(t.blockToHTML)),c=function(e,n){var r=t.entityToHTML(e,n);return X(e,r)};return{v:w({htmlToStyle:r,htmlToBlock:o,htmlToEntity:i,textToEntity:a,styleToHTML:s,blockToHTML:u,entityToHTML:c})(e)}}();return"object"===("undefined"==typeof i?"undefined":o(i))?i.v:void 0}}};t.default=L},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(3),i=n(1),a=n(12),s=r(a),u=function(e){return e.replace(/[a-z][A-Z]/g,function(e){return e[0]+"-"+e[1].toLowerCase()})},c=function(e){var t=e.getCurrentContent().getBlockForKey(e.getSelection().getStartKey());if(t)return t.getEntityAt(e.getSelection().getStartOffset())};t.default={camelCaseToHyphen:u,styleObjectToString:function(e){return Object.keys(e).map(function(t){return u(t)+": "+e[t]+";"}).join(" ").replace(/"/g,'\\"')},entityStrategy:function(e){return function(t,n){t.findEntityRanges(function(t){var n=t.getEntity();return null!==n&&o.Entity.get(n).getType()===e},n)}},getEntitySelection:function(e,t){var n=[];return e.getCurrentContent().getBlocksAsArray().forEach(function(e){e.findEntityRanges(function(e){return e.getEntity()===t},function(t,r){n.push(o.SelectionState.createEmpty(e.getKey()).merge({anchorOffset:t,focusOffset:r,isBackward:!1,hasFocus:!0}))})}),(0,s.default)(1===n.length,"getEntitySelection: More than one range with the same entityKey. Please use unique entity instances"),n[0]},insertBlockAtCursor:function(e,t){var n=e.getCurrentContent(),r=e.getSelection(),a=o.Modifier.removeRange(n,r,"backward"),s=a.getSelectionAfter(),u=o.Modifier.splitBlock(a,s),c=u.getSelectionAfter(),l=o.Modifier.setBlockType(u,c,t.getType()),d=[t,new o.ContentBlock({key:(0,o.genKey)(),type:"unstyled",text:"",characterList:(0,i.List)()})],f=o.BlockMapBuilder.createFromArray(d),p=o.Modifier.replaceWithFragment(l,c,f),y=p.merge({selectionBefore:r,selectionAfter:p.getSelectionAfter().set("hasFocus",!0)});return o.EditorState.push(e,y,"insert-fragment")},getSelectedInlineStyles:function(e){var t=e.getSelection(),n=e.getCurrentContent(),r=n.getBlockMap().skipUntil(function(e,n){return n===t.getStartKey()}).takeUntil(function(e,r){return n.getKeyBefore(r)===t.getEndKey()});return r.reduce(function(e,n){var r=n.getKey(),o=0,i=n.getLength()-1;r===t.getStartKey()&&(o=t.getStartOffset()),r===t.getEndKey()&&(i=t.getEndOffset());for(var a=o;a<=i;a++)e=e.union(n.getInlineStyleAt(a));return e},(0,i.Set)())},matchAll:function(e,t){for(var n=[],r=t.exec(e);null!==r;)n.push(r.concat([r.index])),r=t.exec(e);return n},getActiveEntity:c,isEntityActive:function(e,t){var n=c(e);if(n){var r=o.Entity.get(n);return r&&r.type===t}return!1}}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return function(){var n=e.apply(void 0,arguments);return null===n||void 0===n?t.apply(void 0,arguments):n}}},function(e,t){"use strict";function n(e){return"function"==typeof e?e:function(t){return e[t.type]}}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(){if(0===t.length)return arguments.length<=0?void 0:arguments[0];var e=t[t.length-1],n=t.slice(0,-1);return n.reduceRight(function(e,t){return t(e)},e.apply(void 0,arguments))}}},function(e,t,n){"use strict";function r(e){var t=(0,o.Map)();return function(){var n=o.List.of.apply(o.List,arguments);return t.has(n)||(t=t.set(n,e.apply(void 0,arguments))),t.get(n)}}Object.defineProperty(t,"__esModule",{value:!0}),t.default=r;var o=n(1)},function(e,t,n){"use strict";var r=function(e,t,n,r,o,i,a,s){if(!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,i,a,s],l=0;u=new Error(t.replace(/%s/g,function(){return c[l++]})),u.name="Invariant Violation"}throw u.framesToPop=1,u}};e.exports=r},function(e,t){e.exports=r}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("Immutable"),require("React"),require("Draft"),require("ReactDOM")):"function"==typeof define&&define.amd?define(["Immutable","React","Draft","ReactDOM"],t):"object"==typeof exports?exports.DraftExtend=t(require("Immutable"),require("React"),require("Draft"),require("ReactDOM")):e.DraftExtend=t(e.Immutable,e.React,e.Draft,e.ReactDOM)}(this,function(e,t,n,r){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t.compose=t.pluginUtils=t.createPlugin=t.Editor=void 0;var o=n(4),i=r(o),a=n(6),s=r(a),u=n(7),c=r(u),l=n(10),d=r(l);t.Editor=i.default,t.createPlugin=s.default,t.pluginUtils=c.default,t.compose=d.default},function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t){e.exports=n},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}Object.defineProperty(t,"__esModule",{value:!0});var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a=n(2),s=r(a),u=n(1),c=n(3),l=n(5),d=r(l),f={className:a.PropTypes.string,editorState:a.PropTypes.object,onChange:a.PropTypes.func,decorators:a.PropTypes.array,styleMap:a.PropTypes.object,buttons:a.PropTypes.array,overlays:a.PropTypes.array,blockRendererFn:a.PropTypes.func,blockStyleFn:a.PropTypes.func,keyBindingFn:a.PropTypes.func,keyCommandListeners:a.PropTypes.arrayOf(a.PropTypes.func),handleReturn:a.PropTypes.func,onEscape:a.PropTypes.func,onTab:a.PropTypes.func,onUpArrow:a.PropTypes.func,onDownArrow:a.PropTypes.func,readOnly:a.PropTypes.bool};t.default=s.default.createClass({displayName:"Editor",propTypes:f,childContextTypes:{getEditorState:a.PropTypes.func,getReadOnly:a.PropTypes.func,setReadOnly:a.PropTypes.func,onChange:a.PropTypes.func},getDefaultProps:function(){return{className:"",editorState:c.EditorState.createEmpty(),onChange:function(){},decorators:[],styleMap:{},buttons:[],overlays:[],blockRendererFn:function(){},blockStyleFn:function(){},keyBindingFn:function(){},keyCommandListeners:[],readOnly:!1}},getInitialState:function(){var e=new c.CompositeDecorator(this.props.decorators);return{decorator:e,readOnly:!1}},getChildContext:function(){return{getEditorState:this.getDecoratedState,getReadOnly:this.getReadOnly,setReadOnly:this.setReadOnly,onChange:this.props.onChange}},componentWillMount:function(){this.keyCommandListeners=(0,u.List)(this.props.keyCommandListeners)},componentWillReceiveProps:function(e){if(e.decorators.length===this.state.decorator._decorators.length){var t=this.state.decorator._decorators.every(function(t,n){return t===e.decorators[n]});if(t)return}this.setState({decorator:new c.CompositeDecorator(e.decorators)})},addKeyCommandListener:function(e){this.keyCommandListeners=this.keyCommandListeners.unshift(e)},removeKeyCommandListener:function(e){this.keyCommandListeners=this.keyCommandListeners.filterNot(function(t){return t===e})},keyBindingFn:function(e){var t=this.props.keyBindingFn(e);return t?t:(0,c.getDefaultKeyBinding)(e)},handleKeyCommand:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?null:arguments[1],r=this.getDecoratedState(),o=this.keyCommandListeners.reduce(function(r,o){var i=r.state,a=r.hasChanged;if(a===!0)return{state:i,hasChanged:a};var s=o(i,e,n),u=s instanceof c.EditorState;return s===!0||u&&s!==i?u?(t.props.onChange(s),{state:s,hasChanged:!0}):{state:i,hasChanged:!0}:{state:i,hasChanged:a}},{state:r,hasChanged:!1});return o.hasChanged},handleReturn:function(e){return this.props.handleReturn&&this.props.handleReturn(e)||this.handleKeyCommand("return",e)},onEscape:function(e){return this.props.onEscape&&this.props.onEscape(e)||this.handleKeyCommand("escape",e)},onTab:function(e){return this.props.onTab&&this.props.onTab(e)||this.handleKeyCommand("tab",e)},onUpArrow:function(e){return this.props.onUpArrow&&this.props.onUpArrow(e)||this.handleKeyCommand("up-arrow",e)},onDownArrow:function(e){return this.props.onDownArrow&&this.props.onDownArrow(e)||this.handleKeyCommand("down-arrow",e)},focus:function(){this.refs.editor.focus()},blur:function(){this.refs.editor.blur()},getOtherProps:function(){var e=this,t=Object.keys(this.props),n=Object.keys(f),r=t.filter(function(e){return n.indexOf(e)===-1});return r.reduce(function(t,n){return t[n]=e.props[n],t},{})},getReadOnly:function(){return this.state.readOnly||this.props.readOnly},setReadOnly:function(e){this.setState({readOnly:e})},getDecoratedState:function(){var e=this.props.editorState,t=this.state.decorator,n=e.getDecorator();return n&&n._decorators===t._decorators?e:c.EditorState.set(e,{decorator:t})},renderPluginButtons:function(){var e=this,t=this.getDecoratedState();return this.props.buttons.map(function(n,r){return s.default.createElement("li",{key:"button-"+r},s.default.createElement(n,i({},e.getOtherProps(),{editorState:t,onChange:e.props.onChange,addKeyCommandListener:e.addKeyCommandListener,removeKeyCommandListener:e.removeKeyCommandListener})))})},renderOverlays:function(){var e=this,t=this.getDecoratedState();return this.props.overlays.map(function(n,r){return s.default.createElement(d.default,{key:r},s.default.createElement(n,i({},e.getOtherProps(),{editorState:t,onChange:e.props.onChange,addKeyCommandListener:e.addKeyCommandListener,removeKeyCommandListener:e.removeKeyCommandListener})))})},render:function(){var e=this.props,t=e.styleMap,n=e.blockRendererFn,r=e.blockStyleFn,a=e.onChange,u=o(e,["styleMap","blockRendererFn","blockStyleFn","onChange"]),l=this.getDecoratedState(),d="draft-extend "+this.props.className,f=this.getReadOnly();return s.default.createElement("div",{className:d},s.default.createElement("ul",{className:"draft-extend-controls"},this.renderPluginButtons()),s.default.createElement("div",{className:"draft-extend-editor"},s.default.createElement(c.Editor,i({},u,{ref:"editor",editorState:l,readOnly:f,onChange:a,blockStyleFn:r,blockRendererFn:n,customStyleMap:t,keyBindingFn:this.keyBindingFn,handleKeyCommand:this.handleKeyCommand,handleReturn:this.handleReturn,onEscape:this.onEscape,onTab:this.onTab,onUpArrow:this.onUpArrow,onDownArrow:this.onDownArrow})),s.default.createElement("div",{className:"draft-extend-overlays"},this.renderOverlays())))}})},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(2),i=r(o),a=n(13),s=r(a);t.default=i.default.createClass({displayName:"OverlayWrapper",getInitialState:function(){var e=document.createElement("div");return document.body.appendChild(e),{node:e}},componentDidMount:function(){this.renderOverlay()},componentDidUpdate:function(){this.renderOverlay()},componentWillUnmount:function(){s.default.unmountComponentAtNode(this.state.node)},renderOverlay:function(){var e=i.default.Children.only(this.props.children);s.default.render(e,this.state.node)},render:function(){return null}})},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a=n(2),s=r(a),u=n(11),c=r(u),l=n(9),d=r(l),f=n(8),p=r(f),y=function(){},h=[],m={},g=function(e,t,n){return n},v=function(e,t,n){},b=function(e,t){},T=function(e){return[]},C=function(e){},k=function(e,t){return t},O=(0,c.default)(d.default),S=(0,c.default)(p.default),P=(0,c.default)(function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return Object.assign.apply(Object,[{}].concat(t))}),E=(0,c.default)(function(e,t){return e.concat(t)}),M=(0,c.default)(function(e){return Array.isArray(e)?e:[e]}),L=function R(e){var t=e.displayName,n=void 0===t?"Plugin":t,r=e.decorators,u=void 0===r?h:r,c=e.buttons,l=void 0===c?h:c,d=e.overlays,f=void 0===d?h:d,p=e.styleMap,L=void 0===p?m:p,w=e.blockRendererFn,F=void 0===w?y:w,x=e.blockStyleFn,_=void 0===x?y:x,A=e.keyBindingFn,B=void 0===A?y:A,D=e.keyCommandListener,K=void 0===D?y:D,j=e.htmlToStyle,H=void 0===j?g:j,N=e.htmlToBlock,U=void 0===N?v:N,q=e.htmlToEntity,I=void 0===q?b:q,W=e.textToEntity,z=void 0===W?T:W,V=e.styleToHTML,Z=void 0===V?m:V,G=e.blockToHTML,J=void 0===G?C:G,Q=e.entityToHTML,X=void 0===Q?k:Q;return function(e){return u=M(u),l=M(l),f=M(f),e.prototype&&e.prototype.isReactComponent?s.default.createClass({displayName:n,propTypes:{styleMap:a.PropTypes.object,decorators:a.PropTypes.array,buttons:a.PropTypes.array,overlays:a.PropTypes.array,blockRendererFn:a.PropTypes.func,blockStyleFn:a.PropTypes.func,keyBindingFn:a.PropTypes.func,keyCommandListeners:a.PropTypes.arrayOf(a.PropTypes.func)},getDefaultProps:function(){return{styleMap:m,decorators:h,buttons:h,overlays:h,blockRendererFn:y,blockStyleFn:y,keyBindingFn:y,keyCommandListeners:h}},focus:function(){this.refs.child.focus&&this.refs.child.focus()},blur:function(){this.refs.child.blur&&this.refs.child.blur()},render:function(){var t=P(this.props.styleMap,L),n=E(this.props.decorators,u),r=E(this.props.buttons,l),o=E(this.props.overlays,f),a=S(F,this.props.blockRendererFn),c=S(_,this.props.blockStyleFn),d=S(B,this.props.keyBindingFn),p=E(this.props.keyCommandListeners,M(K));return s.default.createElement(e,i({},this.props,{ref:"child",styleMap:t,decorators:n,buttons:r,overlays:o,blockRendererFn:a,blockStyleFn:c,keyBindingFn:d,keyCommandListeners:p}))}}):function(){for(var t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];if(1===n.length&&("string"==typeof n[0]||n[0].hasOwnProperty("_map")&&null!=n[0].getBlockMap))return e({htmlToStyle:H,htmlToBlock:U,htmlToEntity:I,textToEntity:z,styleToHTML:Z,blockToHTML:J,entityToHTML:X}).apply(void 0,n);var i=function(){var t=n[0],r=function(e,n,r){var o=t.htmlToStyle(e,n,r);return H(e,n,o)},o=S(U,t.htmlToBlock),i=S(I,t.htmlToEntity),a=function(e){return t.textToEntity(e).concat(z(e))},s=Object.assign({},t.styleToHTML,Z),u=S(O(J),O(t.blockToHTML)),c=function(e,n){var r=t.entityToHTML(e,n);return X(e,r)};return{v:R({htmlToStyle:r,htmlToBlock:o,htmlToEntity:i,textToEntity:a,styleToHTML:s,blockToHTML:u,entityToHTML:c})(e)}}();return"object"===("undefined"==typeof i?"undefined":o(i))?i.v:void 0}}};t.default=L},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(3),i=n(1),a=n(12),s=r(a),u=function(e){return e.replace(/[a-z][A-Z]/g,function(e){return e[0]+"-"+e[1].toLowerCase()})},c=function(e){var t=e.getCurrentContent().getBlockForKey(e.getSelection().getStartKey());if(t)return t.getEntityAt(e.getSelection().getStartOffset())};t.default={camelCaseToHyphen:u,styleObjectToString:function(e){return Object.keys(e).map(function(t){return u(t)+": "+e[t]+";"}).join(" ").replace(/"/g,'\\"')},entityStrategy:function(e){return function(t,n){t.findEntityRanges(function(t){var n=t.getEntity();return null!==n&&o.Entity.get(n).getType()===e},n)}},getEntitySelection:function(e,t){var n=[];return e.getCurrentContent().getBlocksAsArray().forEach(function(e){e.findEntityRanges(function(e){return e.getEntity()===t},function(t,r){n.push(o.SelectionState.createEmpty(e.getKey()).merge({anchorOffset:t,focusOffset:r,isBackward:!1,hasFocus:!0}))})}),(0,s.default)(1===n.length,"getEntitySelection: More than one range with the same entityKey. Please use unique entity instances"),n[0]},insertBlockAtCursor:function(e,t){var n=e.getCurrentContent(),r=e.getSelection(),a=o.Modifier.removeRange(n,r,"backward"),s=a.getSelectionAfter(),u=o.Modifier.splitBlock(a,s),c=u.getSelectionAfter(),l=o.Modifier.setBlockType(u,c,t.getType()),d=[t,new o.ContentBlock({key:(0,o.genKey)(),type:"unstyled",text:"",characterList:(0,i.List)()})],f=o.BlockMapBuilder.createFromArray(d),p=o.Modifier.replaceWithFragment(l,c,f),y=p.merge({selectionBefore:r,selectionAfter:p.getSelectionAfter().set("hasFocus",!0)});return o.EditorState.push(e,y,"insert-fragment")},getSelectedInlineStyles:function(e){var t=e.getSelection(),n=e.getCurrentContent(),r=n.getBlockMap().skipUntil(function(e,n){return n===t.getStartKey()}).takeUntil(function(e,r){return n.getKeyBefore(r)===t.getEndKey()});return r.reduce(function(e,n){var r=n.getKey(),o=0,i=n.getLength()-1;r===t.getStartKey()&&(o=t.getStartOffset()),r===t.getEndKey()&&(i=t.getEndOffset());for(var a=o;a<=i;a++)e=e.union(n.getInlineStyleAt(a));return e},(0,i.Set)())},matchAll:function(e,t){for(var n=[],r=t.exec(e);null!==r;)n.push(r.concat([r.index])),r=t.exec(e);return n},getActiveEntity:c,isEntityActive:function(e,t){var n=c(e);if(n){var r=o.Entity.get(n);return r&&r.type===t}return!1}}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return function(){var n=e.apply(void 0,arguments);return null===n||void 0===n?t.apply(void 0,arguments):n}}},function(e,t){"use strict";function n(e){return"function"==typeof e?e:function(t){return e[t.type]}}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(){if(0===t.length)return arguments.length<=0?void 0:arguments[0];var e=t[t.length-1],n=t.slice(0,-1);return n.reduceRight(function(e,t){return t(e)},e.apply(void 0,arguments))}}},function(e,t,n){"use strict";function r(e){var t=(0,o.Map)();return function(){var n=o.List.of.apply(o.List,arguments);return t.has(n)||(t=t.set(n,e.apply(void 0,arguments))),t.get(n)}}Object.defineProperty(t,"__esModule",{value:!0}),t.default=r;var o=n(1)},function(e,t,n){"use strict";var r=function(e,t,n,r,o,i,a,s){if(!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,i,a,s],l=0;u=new Error(t.replace(/%s/g,function(){return c[l++]})),u.name="Invariant Violation"}throw u.framesToPop=1,u}};e.exports=r},function(e,t){e.exports=r}])});

@@ -53,2 +53,3 @@ 'use strict';

getReadOnly: _react.PropTypes.func,
setReadOnly: _react.PropTypes.func,
onChange: _react.PropTypes.func

@@ -76,3 +77,4 @@ },

return {
decorator: decorator
decorator: decorator,
readOnly: false
};

@@ -84,2 +86,3 @@ },

getReadOnly: this.getReadOnly,
setReadOnly: this.setReadOnly,
onChange: this.props.onChange

@@ -199,4 +202,7 @@ };

getReadOnly: function getReadOnly() {
return this.props.readOnly;
return this.state.readOnly || this.props.readOnly;
},
setReadOnly: function setReadOnly(readOnly) {
this.setState({ readOnly: readOnly });
},
getDecoratedState: function getDecoratedState() {

@@ -261,5 +267,6 @@ var editorState = this.props.editorState;

var decoratedState = this.getDecoratedState();
var className = 'draft-extend ' + this.props.className;
var readOnly = this.getReadOnly();
return _react2.default.createElement(

@@ -279,2 +286,3 @@ 'div',

editorState: decoratedState,
readOnly: readOnly,
onChange: onChange,

@@ -281,0 +289,0 @@ blockStyleFn: blockStyleFn,

{
"name": "draft-extend",
"version": "1.3.2",
"version": "1.3.3",
"description": "Build extensible Draft.js editors with configurable plugins and integrated serialization.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc