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.2.0 to 1.3.0

lib/util/accumulateFunction.js

105

dist/draft-extend.js

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

root["DraftExtend"] = factory(root["Immutable"], root["React"], root["Draft"], root["ReactDOM"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_11__) {
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_13__) {
return /******/ (function(modules) { // webpackBootstrap

@@ -77,3 +77,3 @@ /******/ // The module cache

var _compose = __webpack_require__(8);
var _compose = __webpack_require__(10);

@@ -413,3 +413,3 @@ var _compose2 = _interopRequireDefault(_compose);

var _reactDom = __webpack_require__(11);
var _reactDom = __webpack_require__(13);

@@ -464,6 +464,14 @@ var _reactDom2 = _interopRequireDefault(_reactDom);

var _memoize = __webpack_require__(9);
var _memoize = __webpack_require__(11);
var _memoize2 = _interopRequireDefault(_memoize);
var _blockTypeObjectFunction = __webpack_require__(9);
var _blockTypeObjectFunction2 = _interopRequireDefault(_blockTypeObjectFunction);
var _accumulateFunction = __webpack_require__(8);
var _accumulateFunction2 = _interopRequireDefault(_accumulateFunction);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -487,2 +495,5 @@

};
var defaultBlockToHTML = function defaultBlockToHTML(block) {
return undefined;
};
var defaultEntityToHTML = function defaultEntityToHTML(entity, originalText) {

@@ -492,15 +503,4 @@ return originalText;

// utility function to accumulate the common plugin option function pattern of
// handling args by returning a non-null result or delegate to other plugins
var accumulateFunction = function accumulateFunction(acc, newFn) {
return function () {
var result = newFn.apply(undefined, arguments);
if (result === null || result === undefined) {
return acc.apply(undefined, arguments);
}
return result;
};
};
var memoizedAccumulateFunction = (0, _memoize2.default)(accumulateFunction);
var memoizedBlockTypeObjectFunction = (0, _memoize2.default)(_blockTypeObjectFunction2.default);
var memoizedAccumulateFunction = (0, _memoize2.default)(_accumulateFunction2.default);
var memoizedAssign = (0, _memoize2.default)(function () {

@@ -550,3 +550,3 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {

var _ref$blockToHTML = _ref.blockToHTML;
var blockToHTML = _ref$blockToHTML === undefined ? emptyObject : _ref$blockToHTML;
var blockToHTML = _ref$blockToHTML === undefined ? defaultBlockToHTML : _ref$blockToHTML;
var _ref$entityToHTML = _ref.entityToHTML;

@@ -602,5 +602,5 @@ var entityToHTML = _ref$entityToHTML === undefined ? defaultEntityToHTML : _ref$entityToHTML;

var newOverlays = memoizedConcat(this.props.overlays, overlays);
var newBlockRendererFn = memoizedAccumulateFunction(this.props.blockRendererFn, blockRendererFn);
var newBlockStyleFn = memoizedAccumulateFunction(this.props.blockStyleFn, blockStyleFn);
var newKeyBindingFn = memoizedAccumulateFunction(this.props.keyBindingFn, keyBindingFn);
var newBlockRendererFn = memoizedAccumulateFunction(blockRendererFn, this.props.blockRendererFn);
var newBlockStyleFn = memoizedAccumulateFunction(blockStyleFn, this.props.blockStyleFn);
var newKeyBindingFn = memoizedAccumulateFunction(keyBindingFn, this.props.keyBindingFn);
var newKeyCommandListeners = memoizedConcat(this.props.keyCommandListeners, memoizedCoerceArray(keyCommandListener));

@@ -654,9 +654,5 @@

var newHTMLToBlock = function newHTMLToBlock(nodeName, node, lastList) {
return oldOptions.htmlToBlock(nodeName, node, lastList) || htmlToBlock(nodeName, node, lastList);
};
var newHTMLToBlock = memoizedAccumulateFunction(htmlToBlock, oldOptions.htmlToBlock);
var newHTMLToEntity = function newHTMLToEntity(nodeName, node) {
return oldOptions.htmlToEntity(nodeName, node) || htmlToEntity(nodeName, node);
};
var newHTMLToEntity = memoizedAccumulateFunction(htmlToEntity, oldOptions.htmlToEntity);

@@ -668,4 +664,5 @@ var newTextToEntity = function newTextToEntity(text) {

var newStyleToHTML = Object.assign({}, oldOptions.styleToHTML, styleToHTML);
var newBlockToHTML = Object.assign({}, oldOptions.blockToHTML, blockToHTML);
var newBlockToHTML = memoizedAccumulateFunction(memoizedBlockTypeObjectFunction(blockToHTML), memoizedBlockTypeObjectFunction(oldOptions.blockToHTML));
var newEntityToHTML = function newEntityToHTML(entity, originalText) {

@@ -712,3 +709,3 @@ var acc = oldOptions.entityToHTML(entity, originalText);

var _invariant = __webpack_require__(10);
var _invariant = __webpack_require__(12);

@@ -859,2 +856,44 @@ var _invariant2 = _interopRequireDefault(_invariant);

// utility function to accumulate the common plugin option function pattern of
// handling args by returning a non-null result or delegate to other plugins
exports.default = function (newFn, acc) {
return function () {
var result = newFn.apply(undefined, arguments);
if (result === null || result === undefined) {
return acc.apply(undefined, arguments);
}
return result;
};
};
/***/ },
/* 9 */
/***/ function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = blockTypeObjectFunction;
function blockTypeObjectFunction(typeObject) {
if (typeof typeObject === 'function') {
return typeObject;
}
return function (block) {
return typeObject[block.type];
};
}
/***/ },
/* 10 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function () {

@@ -880,3 +919,3 @@ for (var _len = arguments.length, funcs = Array(_len), _key = 0; _key < _len; _key++) {

/***/ },
/* 9 */
/* 11 */
/***/ function(module, exports, __webpack_require__) {

@@ -909,3 +948,3 @@

/***/ },
/* 10 */
/* 12 */
/***/ function(module, exports, __webpack_require__) {

@@ -967,6 +1006,6 @@

/***/ },
/* 11 */
/* 13 */
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_11__;
module.exports = __WEBPACK_EXTERNAL_MODULE_13__;

@@ -973,0 +1012,0 @@ /***/ }

@@ -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(8),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};t.default=s.default.createClass({displayName:"Editor",propTypes:f,childContextTypes:{getEditorState: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:[]}},getInitialState:function(){var e=new c.CompositeDecorator(this.props.decorators);return{decorator:e}},getChildContext:function(){return{getEditorState:this.getDecoratedState,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},{})},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){return s.default.createElement(d.default,null,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(11),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(9),c=r(u),l=function(){},d=[],f={},p=function(e,t,n){return n},y=function(e,t,n){},h=function(e,t){},m=function(e){return[]},g=function(e,t){return t},v=function(e,t){return function(){var n=t.apply(void 0,arguments);return null===n||void 0===n?e.apply(void 0,arguments):n}},b=(0,c.default)(v),T=(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))}),C=(0,c.default)(function(e,t){return e.concat(t)}),k=(0,c.default)(function(e){return Array.isArray(e)?e:[e]}),S=function E(e){var t=e.displayName,n=void 0===t?"Plugin":t,r=e.decorators,u=void 0===r?d:r,c=e.buttons,v=void 0===c?d:c,S=e.overlays,P=void 0===S?d:S,M=e.styleMap,O=void 0===M?f:M,L=e.blockRendererFn,w=void 0===L?l:L,F=e.blockStyleFn,x=void 0===F?l:F,A=e.keyBindingFn,B=void 0===A?l:A,D=e.keyCommandListener,K=void 0===D?l:D,R=e.htmlToStyle,_=void 0===R?p:R,j=e.htmlToBlock,H=void 0===j?y:j,N=e.htmlToEntity,U=void 0===N?h:N,q=e.textToEntity,I=void 0===q?m:q,W=e.styleToHTML,z=void 0===W?f:W,V=e.blockToHTML,Z=void 0===V?f:V,G=e.entityToHTML,J=void 0===G?g:G;return function(e){return u=k(u),v=k(v),P=k(P),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:f,decorators:d,buttons:d,overlays:d,blockRendererFn:l,blockStyleFn:l,keyBindingFn:l,keyCommandListeners:d}},focus:function(){this.refs.child.focus&&this.refs.child.focus()},blur:function(){this.refs.child.blur&&this.refs.child.blur()},render:function(){var t=T(this.props.styleMap,O),n=C(this.props.decorators,u),r=C(this.props.buttons,v),o=C(this.props.overlays,P),a=b(this.props.blockRendererFn,w),c=b(this.props.blockStyleFn,x),l=b(this.props.keyBindingFn,B),d=C(this.props.keyCommandListeners,k(K));return s.default.createElement(e,i({},this.props,{ref:"child",styleMap:t,decorators:n,buttons:r,overlays:o,blockRendererFn:a,blockStyleFn:c,keyBindingFn:l,keyCommandListeners:d}))}}):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:_,htmlToBlock:H,htmlToEntity:U,textToEntity:I,styleToHTML:z,blockToHTML:Z,entityToHTML:J}).apply(void 0,n);var i=function(){var t=n[0],r=function(e,n,r){var o=t.htmlToStyle(e,n,r);return _(e,n,o)},o=function(e,n,r){return t.htmlToBlock(e,n,r)||H(e,n,r)},i=function(e,n){return t.htmlToEntity(e,n)||U(e,n)},a=function(e){return t.textToEntity(e).concat(I(e))},s=Object.assign({},t.styleToHTML,z),u=Object.assign({},t.blockToHTML,Z),c=function(e,n){var r=t.entityToHTML(e,n);return J(e,r)};return{v:E({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=S},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(10),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(/"/,'\\"')},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(){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};t.default=s.default.createClass({displayName:"Editor",propTypes:f,childContextTypes:{getEditorState: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:[]}},getInitialState:function(){var e=new c.CompositeDecorator(this.props.decorators);return{decorator:e}},getChildContext:function(){return{getEditorState:this.getDecoratedState,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},{})},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){return s.default.createElement(d.default,null,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))}),M=(0,c.default)(function(e,t){return e.concat(t)}),O=(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,x=void 0===F?y:F,_=e.blockStyleFn,A=void 0===_?y:_,B=e.keyBindingFn,D=void 0===B?y:B,K=e.keyCommandListener,R=void 0===K?y:K,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=O(u),l=O(l),f=O(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=M(this.props.decorators,u),r=M(this.props.buttons,l),o=M(this.props.overlays,f),a=E(x,this.props.blockRendererFn),c=E(A,this.props.blockStyleFn),d=E(D,this.props.keyBindingFn),p=M(this.props.keyCommandListeners,O(R));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(/"/,'\\"')},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}])});

@@ -19,2 +19,10 @@ 'use strict';

var _blockTypeObjectFunction = require('../util/blockTypeObjectFunction');
var _blockTypeObjectFunction2 = _interopRequireDefault(_blockTypeObjectFunction);
var _accumulateFunction = require('../util/accumulateFunction');
var _accumulateFunction2 = _interopRequireDefault(_accumulateFunction);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -38,2 +46,5 @@

};
var defaultBlockToHTML = function defaultBlockToHTML(block) {
return undefined;
};
var defaultEntityToHTML = function defaultEntityToHTML(entity, originalText) {

@@ -43,15 +54,4 @@ return originalText;

// utility function to accumulate the common plugin option function pattern of
// handling args by returning a non-null result or delegate to other plugins
var accumulateFunction = function accumulateFunction(acc, newFn) {
return function () {
var result = newFn.apply(undefined, arguments);
if (result === null || result === undefined) {
return acc.apply(undefined, arguments);
}
return result;
};
};
var memoizedAccumulateFunction = (0, _memoize2.default)(accumulateFunction);
var memoizedBlockTypeObjectFunction = (0, _memoize2.default)(_blockTypeObjectFunction2.default);
var memoizedAccumulateFunction = (0, _memoize2.default)(_accumulateFunction2.default);
var memoizedAssign = (0, _memoize2.default)(function () {

@@ -101,3 +101,3 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {

var _ref$blockToHTML = _ref.blockToHTML;
var blockToHTML = _ref$blockToHTML === undefined ? emptyObject : _ref$blockToHTML;
var blockToHTML = _ref$blockToHTML === undefined ? defaultBlockToHTML : _ref$blockToHTML;
var _ref$entityToHTML = _ref.entityToHTML;

@@ -153,5 +153,5 @@ var entityToHTML = _ref$entityToHTML === undefined ? defaultEntityToHTML : _ref$entityToHTML;

var newOverlays = memoizedConcat(this.props.overlays, overlays);
var newBlockRendererFn = memoizedAccumulateFunction(this.props.blockRendererFn, blockRendererFn);
var newBlockStyleFn = memoizedAccumulateFunction(this.props.blockStyleFn, blockStyleFn);
var newKeyBindingFn = memoizedAccumulateFunction(this.props.keyBindingFn, keyBindingFn);
var newBlockRendererFn = memoizedAccumulateFunction(blockRendererFn, this.props.blockRendererFn);
var newBlockStyleFn = memoizedAccumulateFunction(blockStyleFn, this.props.blockStyleFn);
var newKeyBindingFn = memoizedAccumulateFunction(keyBindingFn, this.props.keyBindingFn);
var newKeyCommandListeners = memoizedConcat(this.props.keyCommandListeners, memoizedCoerceArray(keyCommandListener));

@@ -205,9 +205,5 @@

var newHTMLToBlock = function newHTMLToBlock(nodeName, node, lastList) {
return oldOptions.htmlToBlock(nodeName, node, lastList) || htmlToBlock(nodeName, node, lastList);
};
var newHTMLToBlock = memoizedAccumulateFunction(htmlToBlock, oldOptions.htmlToBlock);
var newHTMLToEntity = function newHTMLToEntity(nodeName, node) {
return oldOptions.htmlToEntity(nodeName, node) || htmlToEntity(nodeName, node);
};
var newHTMLToEntity = memoizedAccumulateFunction(htmlToEntity, oldOptions.htmlToEntity);

@@ -219,4 +215,5 @@ var newTextToEntity = function newTextToEntity(text) {

var newStyleToHTML = Object.assign({}, oldOptions.styleToHTML, styleToHTML);
var newBlockToHTML = Object.assign({}, oldOptions.blockToHTML, blockToHTML);
var newBlockToHTML = memoizedAccumulateFunction(memoizedBlockTypeObjectFunction(blockToHTML), memoizedBlockTypeObjectFunction(oldOptions.blockToHTML));
var newEntityToHTML = function newEntityToHTML(entity, originalText) {

@@ -223,0 +220,0 @@ var acc = oldOptions.entityToHTML(entity, originalText);

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

@@ -27,8 +27,10 @@ "main": "lib/index.js",

"author": "Ben Briggs",
"peerDependencies": {
"draft-js": ">=0.7.0",
"react": ">=15.0.2",
"react-dom": ">=15.0.2"
},
"dependencies": {
"draft-js": "^0.6.0",
"immutable": "^3.8.1",
"invariant": "^2.2.1",
"react": "^15.0.2",
"react-dom": "^15.0.2"
"invariant": "^2.2.1"
},

@@ -43,6 +45,9 @@ "devDependencies": {

"babel-standalone": "^6.7.7",
"draft-convert": "^1.1.0",
"draft-convert": "^1.2.0",
"draft-js": "^0.8.1",
"es6-shim": "^0.35.0",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"webpack": "^1.13.0"
}
}
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