Comparing version 0.0.4 to 0.0.5
import React, { Component, createContext } from 'react'; | ||
import { CompositeDecorator, DefaultDraftBlockRenderMap, Editor, EditorState, getDefaultKeyBinding } from 'draft-js'; | ||
var HANDLED = 'handled'; | ||
var NOT_HANDLED = 'not-handled'; | ||
var constants = Object.freeze({ | ||
HANDLED: HANDLED, | ||
NOT_HANDLED: NOT_HANDLED | ||
}); | ||
var classCallCheck = function (instance, Constructor) { | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
} | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
var _extends = Object.assign || function (target) { | ||
function _objectSpread(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var ownKeys = Object.keys(source); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
return target; | ||
}; | ||
} | ||
var inherits = function (subClass, superClass) { | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
@@ -66,3 +86,2 @@ | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
@@ -72,84 +91,114 @@ configurable: true | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var objectWithoutProperties = function (obj, keys) { | ||
var target = {}; | ||
var key, i; | ||
for (var i in obj) { | ||
if (keys.indexOf(i) >= 0) continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; | ||
target[i] = obj[i]; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
}; | ||
} | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
var HANDLED = 'handled'; | ||
var NOT_HANDLED = 'not-handled'; | ||
var constants = Object.freeze({ | ||
HANDLED: HANDLED, | ||
NOT_HANDLED: NOT_HANDLED | ||
}); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var Context = createContext({}); | ||
var withEditorContext = function withEditorContext(Comp) { | ||
return function WithConsumer(props) { | ||
return React.createElement( | ||
Context.Consumer, | ||
null, | ||
function (contextProps) { | ||
return React.createElement(Comp, _extends({}, props, contextProps.editorProps)); | ||
} | ||
); | ||
return React.createElement(Context.Consumer, null, function (contextProps) { | ||
return React.createElement(Comp, _extends({}, props, contextProps.editorProps)); | ||
}); | ||
}; | ||
}; | ||
var withPluginContext = function withPluginContext(Comp) { | ||
return function WithConsumer(props) { | ||
return React.createElement( | ||
Context.Consumer, | ||
null, | ||
function (contextProps) { | ||
return React.createElement(Comp, _extends({}, props, contextProps.pluginProps)); | ||
} | ||
); | ||
return React.createElement(Context.Consumer, null, function (contextProps) { | ||
return React.createElement(Comp, _extends({}, props, contextProps.pluginProps)); | ||
}); | ||
}; | ||
@@ -160,16 +209,24 @@ }; | ||
return new CompositeDecorator(Array.from(plugins.values()).reduce(function (acc, plugin) { | ||
return Array.isArray(plugin.decorators) ? [].concat(toConsumableArray(acc), toConsumableArray(plugin.decorators)) : acc; | ||
return Array.isArray(plugin.decorators) ? _toConsumableArray(acc).concat(_toConsumableArray(plugin.decorators)) : acc; | ||
}, [])); | ||
}; | ||
var EditorContainer = function (_Component) { | ||
inherits(EditorContainer, _Component); | ||
var EditorContainer = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(EditorContainer, _Component); | ||
function EditorContainer(props) { | ||
classCallCheck(this, EditorContainer); | ||
var _this; | ||
var _this = possibleConstructorReturn(this, (EditorContainer.__proto__ || Object.getPrototypeOf(EditorContainer)).call(this, props)); | ||
_classCallCheck(this, EditorContainer); | ||
_this.state = { | ||
plugins: new Map().set('default', { keyBindingFn: getDefaultKeyBinding }), | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(EditorContainer).call(this, props)); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "mapKey", void 0); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", { | ||
plugins: new Map().set('default', { | ||
keyBindingFn: getDefaultKeyBinding | ||
}), | ||
editorState: EditorState.createEmpty(), | ||
@@ -181,21 +238,21 @@ editorProps: { | ||
} | ||
}; | ||
}); | ||
_this.resolveDecorator = function () { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "resolveDecorator", function () { | ||
return resolveDecorator(_this.state.plugins); | ||
}; | ||
}); | ||
_this.resolveCustomStyleMap = function () { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "resolveCustomStyleMap", function () { | ||
return Array.from(_this.state.plugins.values()).reduce(function (acc, plugin) { | ||
return plugin.customStyleMap != null ? _extends({}, acc, plugin.customStyleMap) : acc; | ||
return plugin.customStyleMap != null ? _objectSpread({}, acc, plugin.customStyleMap) : acc; | ||
}, _this.props.customStyleMap); | ||
}; | ||
}); | ||
_this.resolveBlockRendererMap = function () { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "resolveBlockRendererMap", function () { | ||
return Array.from(_this.state.plugins.values()).reduce(function (acc, plugin) { | ||
return plugin.blockRenderMap != null ? acc.merge(plugin.blockRenderMap) : acc; | ||
}, _this.props.blockRenderMap); | ||
}; | ||
}); | ||
_this.setupEditorState = function () { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "setupEditorState", function () { | ||
return _this.setState({ | ||
@@ -206,31 +263,33 @@ editorState: EditorState.set(_this.state.editorState, { | ||
}); | ||
}; | ||
}); | ||
_this.unregisterPlugin = function (key) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "unregisterPlugin", function (key) { | ||
var plugins = _this.state.plugins; | ||
plugins.delete(key); | ||
_this.setState({ | ||
plugins: plugins | ||
}); | ||
plugins.delete(key); | ||
_this.setState({ plugins: plugins }); | ||
_this.setupEditorState(); | ||
}; | ||
}); | ||
_this.registerPlugin = function (plugin) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "registerPlugin", function (plugin) { | ||
var plugins = _this.state.plugins; | ||
var key = _this.mapKey; | ||
_this.setState({ plugins: plugins.set(key, plugin) }); | ||
_this.setState({ | ||
plugins: plugins.set(key, plugin) | ||
}); | ||
_this.setupEditorState(); | ||
_this.mapKey++; | ||
return function () { | ||
return _this.unregisterPlugin(key); | ||
}; | ||
}; | ||
}); | ||
_this.returnFirstTruthy = function (methodName) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "returnFirstTruthy", function (methodName) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
@@ -248,3 +307,4 @@ } | ||
if (plugin[methodName] != null) { | ||
var result = plugin[methodName].apply(plugin, toConsumableArray(args)); | ||
var result = plugin[methodName].apply(plugin, args); | ||
if (result) { | ||
@@ -260,3 +320,3 @@ return result; | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
@@ -270,6 +330,6 @@ } | ||
} | ||
}; | ||
}); | ||
_this.returnFirstHandled = function (methodName) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "returnFirstHandled", function (methodName) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
@@ -287,3 +347,4 @@ } | ||
if (plugin[methodName] != null) { | ||
var result = plugin[methodName].apply(plugin, toConsumableArray(args)); | ||
var result = plugin[methodName].apply(plugin, args); | ||
if (result === HANDLED) { | ||
@@ -299,3 +360,3 @@ return result; | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
@@ -309,6 +370,6 @@ } | ||
} | ||
}; | ||
}); | ||
_this.eventCallback = function (methodName) { | ||
for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "eventCallback", function (methodName) { | ||
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
@@ -318,9 +379,9 @@ } | ||
return _this.state.plugins.forEach(function (plugin) { | ||
return plugin[methodName] != null && plugin[methodName].apply(plugin, toConsumableArray(args)); | ||
return plugin[methodName] != null && plugin[methodName].apply(plugin, args); | ||
}); | ||
}; | ||
}); | ||
_this.onChange = function (editorState) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onChange", function (editorState) { | ||
_this.props.onChange(editorState); | ||
}; | ||
}); | ||
@@ -331,8 +392,8 @@ _this.mapKey = 0; | ||
createClass(EditorContainer, [{ | ||
key: 'render', | ||
_createClass(EditorContainer, [{ | ||
key: "render", | ||
value: function render() { | ||
var _this2 = this; | ||
var editorProps = _extends({}, this.state.editorProps, { | ||
var editorProps = _objectSpread({}, this.state.editorProps, { | ||
editorState: this.state.editorState, | ||
@@ -398,8 +459,9 @@ customStyleMap: this.resolveCustomStyleMap(), | ||
return _this2.eventCallback('onBlur', e); | ||
} | ||
} // yepyepyep this gets the editorState lazily | ||
// avoids having to have a `getEditorState` prop | ||
// yepyepyep this gets the editorState lazily | ||
// avoids having to have a `getEditorState` prop | ||
});Object.defineProperty(editorProps, 'editorState', { | ||
get: function get$$1() { | ||
}); | ||
Object.defineProperty(editorProps, 'editorState', { | ||
get: function get() { | ||
return _this2.state.editorState; | ||
@@ -409,3 +471,2 @@ }, | ||
}); | ||
var pluginProps = { | ||
@@ -417,9 +478,8 @@ registerPlugin: this.registerPlugin, | ||
return _this2.setState({ | ||
editorProps: _extends({}, _this2.state.editorProps, editorProps) | ||
editorProps: _objectSpread({}, _this2.state.editorProps, editorProps) | ||
}); | ||
} | ||
}; | ||
Object.defineProperty(pluginProps, 'editorState', { | ||
get: function get$$1() { | ||
get: function get() { | ||
return _this2.state.editorState; | ||
@@ -429,11 +489,11 @@ }, | ||
}); | ||
return React.createElement( | ||
Context.Provider, | ||
{ value: { pluginProps: pluginProps, editorProps: editorProps } }, | ||
this.props.children | ||
); | ||
return React.createElement(Context.Provider, { | ||
value: { | ||
pluginProps: pluginProps, | ||
editorProps: editorProps | ||
} | ||
}, this.props.children); | ||
} | ||
}], [{ | ||
key: 'getDerivedStateFromProps', | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(props, state) { | ||
@@ -461,5 +521,3 @@ var editorState = props.editorState, | ||
webDriverTestID = props.webDriverTestID; | ||
return _extends({}, state, { | ||
return _objectSpread({}, state, { | ||
editorState: editorState != null ? EditorState.set(editorState, { | ||
@@ -480,3 +538,2 @@ decorator: resolveDecorator(state.plugins) | ||
textDirectionality: textDirectionality, | ||
ariaActiveDescendantID: ariaActiveDescendantID, | ||
@@ -495,35 +552,44 @@ ariaAutoComplete: ariaAutoComplete, | ||
}]); | ||
return EditorContainer; | ||
}(Component); | ||
EditorContainer.defaultProps = { | ||
_defineProperty(EditorContainer, "defaultProps", { | ||
customStyleMap: {}, | ||
blockRenderMap: DefaultDraftBlockRenderMap | ||
}; | ||
}); | ||
var Plugin = function (_Component) { | ||
inherits(Plugin, _Component); | ||
var Plugin = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(Plugin, _Component); | ||
function Plugin() { | ||
var _ref; | ||
var _getPrototypeOf2; | ||
var _temp, _this, _ret; | ||
var _this; | ||
classCallCheck(this, Plugin); | ||
_classCallCheck(this, Plugin); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = Plugin.__proto__ || Object.getPrototypeOf(Plugin)).call.apply(_ref, [this].concat(args))), _this), _this.componentWillUnmount = function () { | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Plugin)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "unsubscribe", void 0); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "componentWillUnmount", function () { | ||
return _this.unsubscribe(); | ||
}, _temp), possibleConstructorReturn(_this, _ret); | ||
}); | ||
return _this; | ||
} | ||
createClass(Plugin, [{ | ||
key: 'componentDidMount', | ||
_createClass(Plugin, [{ | ||
key: "componentDidMount", | ||
value: function componentDidMount() { | ||
var _props = this.props, | ||
registerPlugin = _props.registerPlugin, | ||
props = objectWithoutProperties(_props, ['registerPlugin']); | ||
var _this$props = this.props, | ||
registerPlugin = _this$props.registerPlugin, | ||
props = _objectWithoutProperties(_this$props, ["registerPlugin"]); | ||
@@ -533,10 +599,9 @@ this.unsubscribe = registerPlugin(props); | ||
}, { | ||
key: 'render', | ||
key: "render", | ||
value: function render() { | ||
var _props2 = this.props, | ||
setEditorState = _props2.setEditorState, | ||
editorState = _props2.editorState, | ||
setEditorProps = _props2.setEditorProps; | ||
var _this$props2 = this.props, | ||
setEditorState = _this$props2.setEditorState, | ||
editorState = _this$props2.editorState, | ||
setEditorProps = _this$props2.setEditorProps; | ||
if (this.props.children) { | ||
@@ -549,5 +614,7 @@ return this.props.children({ | ||
} | ||
return null; | ||
} | ||
}]); | ||
return Plugin; | ||
@@ -554,0 +621,0 @@ }(Component); |
@@ -11,59 +11,79 @@ 'use strict'; | ||
var HANDLED = 'handled'; | ||
var NOT_HANDLED = 'not-handled'; | ||
var constants = Object.freeze({ | ||
HANDLED: HANDLED, | ||
NOT_HANDLED: NOT_HANDLED | ||
}); | ||
var classCallCheck = function (instance, Constructor) { | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
} | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
var _extends = Object.assign || function (target) { | ||
function _objectSpread(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var ownKeys = Object.keys(source); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
return target; | ||
}; | ||
} | ||
var inherits = function (subClass, superClass) { | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
@@ -74,3 +94,2 @@ | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
@@ -80,84 +99,114 @@ configurable: true | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var objectWithoutProperties = function (obj, keys) { | ||
var target = {}; | ||
var key, i; | ||
for (var i in obj) { | ||
if (keys.indexOf(i) >= 0) continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; | ||
target[i] = obj[i]; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
}; | ||
} | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
var HANDLED = 'handled'; | ||
var NOT_HANDLED = 'not-handled'; | ||
var constants = Object.freeze({ | ||
HANDLED: HANDLED, | ||
NOT_HANDLED: NOT_HANDLED | ||
}); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var Context = React.createContext({}); | ||
var withEditorContext = function withEditorContext(Comp) { | ||
return function WithConsumer(props) { | ||
return React__default.createElement( | ||
Context.Consumer, | ||
null, | ||
function (contextProps) { | ||
return React__default.createElement(Comp, _extends({}, props, contextProps.editorProps)); | ||
} | ||
); | ||
return React__default.createElement(Context.Consumer, null, function (contextProps) { | ||
return React__default.createElement(Comp, _extends({}, props, contextProps.editorProps)); | ||
}); | ||
}; | ||
}; | ||
var withPluginContext = function withPluginContext(Comp) { | ||
return function WithConsumer(props) { | ||
return React__default.createElement( | ||
Context.Consumer, | ||
null, | ||
function (contextProps) { | ||
return React__default.createElement(Comp, _extends({}, props, contextProps.pluginProps)); | ||
} | ||
); | ||
return React__default.createElement(Context.Consumer, null, function (contextProps) { | ||
return React__default.createElement(Comp, _extends({}, props, contextProps.pluginProps)); | ||
}); | ||
}; | ||
@@ -168,16 +217,24 @@ }; | ||
return new draftJs.CompositeDecorator(Array.from(plugins.values()).reduce(function (acc, plugin) { | ||
return Array.isArray(plugin.decorators) ? [].concat(toConsumableArray(acc), toConsumableArray(plugin.decorators)) : acc; | ||
return Array.isArray(plugin.decorators) ? _toConsumableArray(acc).concat(_toConsumableArray(plugin.decorators)) : acc; | ||
}, [])); | ||
}; | ||
var EditorContainer = function (_Component) { | ||
inherits(EditorContainer, _Component); | ||
var EditorContainer = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(EditorContainer, _Component); | ||
function EditorContainer(props) { | ||
classCallCheck(this, EditorContainer); | ||
var _this; | ||
var _this = possibleConstructorReturn(this, (EditorContainer.__proto__ || Object.getPrototypeOf(EditorContainer)).call(this, props)); | ||
_classCallCheck(this, EditorContainer); | ||
_this.state = { | ||
plugins: new Map().set('default', { keyBindingFn: draftJs.getDefaultKeyBinding }), | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(EditorContainer).call(this, props)); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "mapKey", void 0); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", { | ||
plugins: new Map().set('default', { | ||
keyBindingFn: draftJs.getDefaultKeyBinding | ||
}), | ||
editorState: draftJs.EditorState.createEmpty(), | ||
@@ -189,21 +246,21 @@ editorProps: { | ||
} | ||
}; | ||
}); | ||
_this.resolveDecorator = function () { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "resolveDecorator", function () { | ||
return resolveDecorator(_this.state.plugins); | ||
}; | ||
}); | ||
_this.resolveCustomStyleMap = function () { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "resolveCustomStyleMap", function () { | ||
return Array.from(_this.state.plugins.values()).reduce(function (acc, plugin) { | ||
return plugin.customStyleMap != null ? _extends({}, acc, plugin.customStyleMap) : acc; | ||
return plugin.customStyleMap != null ? _objectSpread({}, acc, plugin.customStyleMap) : acc; | ||
}, _this.props.customStyleMap); | ||
}; | ||
}); | ||
_this.resolveBlockRendererMap = function () { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "resolveBlockRendererMap", function () { | ||
return Array.from(_this.state.plugins.values()).reduce(function (acc, plugin) { | ||
return plugin.blockRenderMap != null ? acc.merge(plugin.blockRenderMap) : acc; | ||
}, _this.props.blockRenderMap); | ||
}; | ||
}); | ||
_this.setupEditorState = function () { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "setupEditorState", function () { | ||
return _this.setState({ | ||
@@ -214,31 +271,33 @@ editorState: draftJs.EditorState.set(_this.state.editorState, { | ||
}); | ||
}; | ||
}); | ||
_this.unregisterPlugin = function (key) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "unregisterPlugin", function (key) { | ||
var plugins = _this.state.plugins; | ||
plugins.delete(key); | ||
_this.setState({ | ||
plugins: plugins | ||
}); | ||
plugins.delete(key); | ||
_this.setState({ plugins: plugins }); | ||
_this.setupEditorState(); | ||
}; | ||
}); | ||
_this.registerPlugin = function (plugin) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "registerPlugin", function (plugin) { | ||
var plugins = _this.state.plugins; | ||
var key = _this.mapKey; | ||
_this.setState({ plugins: plugins.set(key, plugin) }); | ||
_this.setState({ | ||
plugins: plugins.set(key, plugin) | ||
}); | ||
_this.setupEditorState(); | ||
_this.mapKey++; | ||
return function () { | ||
return _this.unregisterPlugin(key); | ||
}; | ||
}; | ||
}); | ||
_this.returnFirstTruthy = function (methodName) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "returnFirstTruthy", function (methodName) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
@@ -256,3 +315,4 @@ } | ||
if (plugin[methodName] != null) { | ||
var result = plugin[methodName].apply(plugin, toConsumableArray(args)); | ||
var result = plugin[methodName].apply(plugin, args); | ||
if (result) { | ||
@@ -268,3 +328,3 @@ return result; | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
@@ -278,6 +338,6 @@ } | ||
} | ||
}; | ||
}); | ||
_this.returnFirstHandled = function (methodName) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "returnFirstHandled", function (methodName) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
@@ -295,3 +355,4 @@ } | ||
if (plugin[methodName] != null) { | ||
var result = plugin[methodName].apply(plugin, toConsumableArray(args)); | ||
var result = plugin[methodName].apply(plugin, args); | ||
if (result === HANDLED) { | ||
@@ -307,3 +368,3 @@ return result; | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
@@ -317,6 +378,6 @@ } | ||
} | ||
}; | ||
}); | ||
_this.eventCallback = function (methodName) { | ||
for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "eventCallback", function (methodName) { | ||
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
@@ -326,9 +387,9 @@ } | ||
return _this.state.plugins.forEach(function (plugin) { | ||
return plugin[methodName] != null && plugin[methodName].apply(plugin, toConsumableArray(args)); | ||
return plugin[methodName] != null && plugin[methodName].apply(plugin, args); | ||
}); | ||
}; | ||
}); | ||
_this.onChange = function (editorState) { | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onChange", function (editorState) { | ||
_this.props.onChange(editorState); | ||
}; | ||
}); | ||
@@ -339,8 +400,8 @@ _this.mapKey = 0; | ||
createClass(EditorContainer, [{ | ||
key: 'render', | ||
_createClass(EditorContainer, [{ | ||
key: "render", | ||
value: function render() { | ||
var _this2 = this; | ||
var editorProps = _extends({}, this.state.editorProps, { | ||
var editorProps = _objectSpread({}, this.state.editorProps, { | ||
editorState: this.state.editorState, | ||
@@ -406,8 +467,9 @@ customStyleMap: this.resolveCustomStyleMap(), | ||
return _this2.eventCallback('onBlur', e); | ||
} | ||
} // yepyepyep this gets the editorState lazily | ||
// avoids having to have a `getEditorState` prop | ||
// yepyepyep this gets the editorState lazily | ||
// avoids having to have a `getEditorState` prop | ||
});Object.defineProperty(editorProps, 'editorState', { | ||
get: function get$$1() { | ||
}); | ||
Object.defineProperty(editorProps, 'editorState', { | ||
get: function get() { | ||
return _this2.state.editorState; | ||
@@ -417,3 +479,2 @@ }, | ||
}); | ||
var pluginProps = { | ||
@@ -425,9 +486,8 @@ registerPlugin: this.registerPlugin, | ||
return _this2.setState({ | ||
editorProps: _extends({}, _this2.state.editorProps, editorProps) | ||
editorProps: _objectSpread({}, _this2.state.editorProps, editorProps) | ||
}); | ||
} | ||
}; | ||
Object.defineProperty(pluginProps, 'editorState', { | ||
get: function get$$1() { | ||
get: function get() { | ||
return _this2.state.editorState; | ||
@@ -437,11 +497,11 @@ }, | ||
}); | ||
return React__default.createElement( | ||
Context.Provider, | ||
{ value: { pluginProps: pluginProps, editorProps: editorProps } }, | ||
this.props.children | ||
); | ||
return React__default.createElement(Context.Provider, { | ||
value: { | ||
pluginProps: pluginProps, | ||
editorProps: editorProps | ||
} | ||
}, this.props.children); | ||
} | ||
}], [{ | ||
key: 'getDerivedStateFromProps', | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(props, state) { | ||
@@ -469,5 +529,3 @@ var editorState = props.editorState, | ||
webDriverTestID = props.webDriverTestID; | ||
return _extends({}, state, { | ||
return _objectSpread({}, state, { | ||
editorState: editorState != null ? draftJs.EditorState.set(editorState, { | ||
@@ -488,3 +546,2 @@ decorator: resolveDecorator(state.plugins) | ||
textDirectionality: textDirectionality, | ||
ariaActiveDescendantID: ariaActiveDescendantID, | ||
@@ -503,35 +560,44 @@ ariaAutoComplete: ariaAutoComplete, | ||
}]); | ||
return EditorContainer; | ||
}(React.Component); | ||
EditorContainer.defaultProps = { | ||
_defineProperty(EditorContainer, "defaultProps", { | ||
customStyleMap: {}, | ||
blockRenderMap: draftJs.DefaultDraftBlockRenderMap | ||
}; | ||
}); | ||
var Plugin = function (_Component) { | ||
inherits(Plugin, _Component); | ||
var Plugin = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(Plugin, _Component); | ||
function Plugin() { | ||
var _ref; | ||
var _getPrototypeOf2; | ||
var _temp, _this, _ret; | ||
var _this; | ||
classCallCheck(this, Plugin); | ||
_classCallCheck(this, Plugin); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = Plugin.__proto__ || Object.getPrototypeOf(Plugin)).call.apply(_ref, [this].concat(args))), _this), _this.componentWillUnmount = function () { | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Plugin)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "unsubscribe", void 0); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "componentWillUnmount", function () { | ||
return _this.unsubscribe(); | ||
}, _temp), possibleConstructorReturn(_this, _ret); | ||
}); | ||
return _this; | ||
} | ||
createClass(Plugin, [{ | ||
key: 'componentDidMount', | ||
_createClass(Plugin, [{ | ||
key: "componentDidMount", | ||
value: function componentDidMount() { | ||
var _props = this.props, | ||
registerPlugin = _props.registerPlugin, | ||
props = objectWithoutProperties(_props, ['registerPlugin']); | ||
var _this$props = this.props, | ||
registerPlugin = _this$props.registerPlugin, | ||
props = _objectWithoutProperties(_this$props, ["registerPlugin"]); | ||
@@ -541,10 +607,9 @@ this.unsubscribe = registerPlugin(props); | ||
}, { | ||
key: 'render', | ||
key: "render", | ||
value: function render() { | ||
var _props2 = this.props, | ||
setEditorState = _props2.setEditorState, | ||
editorState = _props2.editorState, | ||
setEditorProps = _props2.setEditorProps; | ||
var _this$props2 = this.props, | ||
setEditorState = _this$props2.setEditorState, | ||
editorState = _this$props2.editorState, | ||
setEditorProps = _this$props2.setEditorProps; | ||
if (this.props.children) { | ||
@@ -557,5 +622,7 @@ return this.props.children({ | ||
} | ||
return null; | ||
} | ||
}]); | ||
return Plugin; | ||
@@ -562,0 +629,0 @@ }(React.Component); |
{ | ||
"name": "@djsp/core", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "djsp Core Components", | ||
@@ -14,5 +14,7 @@ "author": "juliankrispel", | ||
"test:watch": "react-scripts test --env=jsdom", | ||
"build": "rollup -c", | ||
"build": "rimraf dist && rollup -c && yarn build:flow", | ||
"build:flow": "./node_modules/.bin/flow-copy-source -v -i '**/__tests__/**' src dist", | ||
"start": "rollup -c -w", | ||
"prepare": "yarn run build", | ||
"flow": "./node_modules/.bin/flow", | ||
"prepare": "yarn run build && yarn build:flow", | ||
"predeploy": "cd example && yarn install && yarn run build", | ||
@@ -33,9 +35,5 @@ "deploy": "gh-pages -d example/build" | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-preset-react": "^6.24.1", | ||
"babel-preset-stage-0": "^6.24.1", | ||
"cross-env": "^5.1.4", | ||
"flow-bin": "^0.83.0", | ||
"flow-copy-source": "^2.0.2", | ||
"gh-pages": "^1.1.0", | ||
@@ -45,4 +43,5 @@ "react": "^16.2.0", | ||
"react-scripts": "^1.1.1", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.54.0", | ||
"rollup-plugin-babel": "^3.0.3", | ||
"rollup-plugin-babel": "^4.0.3", | ||
"rollup-plugin-commonjs": "^8.2.1", | ||
@@ -49,0 +48,0 @@ "rollup-plugin-node-resolve": "^3.0.2", |
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
53734
15
10
1031