diff --git a/.npmignore b/.npmignore index dc6adbb29..c903f5017 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,3 @@ -dist/slate.js docs examples lib diff --git a/dist/slate.js b/dist/slate.js deleted file mode 100644 index 70fccf6d9..000000000 --- a/dist/slate.js +++ /dev/null @@ -1,66176 +0,0 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Slate = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * Noop. - */ - -function noop() {} - -/** - * Editor. - */ - -var Editor = function (_React$Component) { - _inherits(Editor, _React$Component); - - /** - * When created, compute the plugins from `props`. - * - * @param {Object} props - */ - - /** - * Properties. - */ - - function Editor(props) { - _classCallCheck(this, Editor); - - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Editor).call(this, props)); - - _initialiseProps.call(_this); - - _this.tmp = {}; - _this.state = {}; - _this.state.plugins = _this.resolvePlugins(props); - _this.state.state = _this.resolveState(props.state); - return _this; - } - - /** - * When the `props` are updated, recompute the plugins. - * - * @param {Object} props - */ - - /** - * Blur the editor. - */ - - /** - * Focus the editor. - */ - - /** - * Get the editor's current `state`. - * - * @return {State} state - */ - - /** - * When the `state` changes, pass through plugins, then bubble up. - * - * @param {State} state - */ - - /** - * When an event by `name` fires, pass it through the plugins, and update the - * state if one of them chooses to. - * - * @param {String} name - * @param {Mixed} ...args - */ - - /** - * On before input. - * - * @param {Mixed} ...args - */ - - /** - * On key down. - * - * @param {Mixed} ...args - */ - - /** - * On paste. - * - * @param {Mixed} ...args - */ - - /** - * Render the editor. - * - * @return {Element} element - */ - - /** - * Render a `node`, cascading through the plugins. - * - * @param {Node} node - * @return {Element} element - */ - - /** - * Render a `mark`, cascading through the plugins. - * - * @param {Mark} mark - * @return {Object} style - */ - - /** - * Resolve the editor's current plugins from `props` when they change. - * - * Add a plugin made from the editor's own `props` at the beginning of the - * stack. That way, you can add a `onKeyDown` handler to the editor itself, - * and it will override all of the existing plugins. - * - * Also add the "core" functionality plugin that handles the most basic events - * for the editor, like delete characters and such. - * - * @param {Object} props - * @return {Array} plugins - */ - - /** - * Resolve the editor's current state from `props` when they change. - * - * This is where we handle decorating the text nodes with the decorator - * functions, so that they are always accounted for when rendering. - * - * @param {State} state - * @return {State} state - */ - - return Editor; -}(_react2.default.Component); - -/** - * Export. - */ - -Editor.propTypes = { - className: _react2.default.PropTypes.string, - onBeforeInput: _react2.default.PropTypes.func, - onChange: _react2.default.PropTypes.func.isRequired, - onDocumentChange: _react2.default.PropTypes.func, - onKeyDown: _react2.default.PropTypes.func, - onPaste: _react2.default.PropTypes.func, - onSelectionChange: _react2.default.PropTypes.func, - placeholder: _react2.default.PropTypes.any, - placeholderClassName: _react2.default.PropTypes.string, - placeholderStyle: _react2.default.PropTypes.object, - plugins: _react2.default.PropTypes.array, - readOnly: _react2.default.PropTypes.bool, - renderDecorations: _react2.default.PropTypes.func, - renderMark: _react2.default.PropTypes.func, - renderNode: _react2.default.PropTypes.func, - state: _react2.default.PropTypes.object.isRequired, - style: _react2.default.PropTypes.object -}; -Editor.defaultProps = { - onDocumentChange: noop, - onSelectionChange: noop, - plugins: [], - readOnly: false -}; - -var _initialiseProps = function _initialiseProps() { - var _this2 = this; - - this.componentWillReceiveProps = function (props) { - if (props.plugins != _this2.props.plugins) { - _this2.setState({ plugins: _this2.resolvePlugins(props) }); - } - - if (props.state != _this2.props.state) { - _this2.setState({ state: _this2.resolveState(props.state) }); - } - }; - - this.blur = function () { - var state = _this2.state.state.transform().blur().apply(); - - _this2.onChange(state); - }; - - this.focus = function () { - var state = _this2.state.state.transform().focus().apply(); - - _this2.onChange(state); - }; - - this.getState = function () { - return _this2.state.state; - }; - - this.onChange = function (state) { - if (state == _this2.state.state) return; - - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = _this2.state.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var plugin = _step.value; - - if (!plugin.onChange) continue; - var newState = plugin.onChange(state, _this2); - if (newState == null) continue; - state = newState; - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - _this2.props.onChange(state); - - if (state.document != _this2.tmp.document) { - _this2.props.onDocumentChange(state.document, state); - _this2.tmp.document = state.document; - } - - if (state.selection != _this2.tmp.selection) { - _this2.props.onSelectionChange(state.selection, state); - _this2.tmp.selection = state.selection; - } - }; - - this.onEvent = function (name) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; - } - - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = _this2.state.plugins[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var plugin = _step2.value; - - if (!plugin[name]) continue; - var newState = plugin[name].apply(plugin, args.concat([_this2.state.state, _this2])); - if (!newState) continue; - _this2.onChange(newState); - break; - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2.return) { - _iterator2.return(); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - }; - - this.onBeforeInput = function () { - for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args[_key2] = arguments[_key2]; - } - - _this2.onEvent.apply(_this2, ['onBeforeInput'].concat(args)); - }; - - this.onKeyDown = function () { - for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { - args[_key3] = arguments[_key3]; - } - - _this2.onEvent.apply(_this2, ['onKeyDown'].concat(args)); - }; - - this.onPaste = function () { - for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { - args[_key4] = arguments[_key4]; - } - - _this2.onEvent.apply(_this2, ['onPaste'].concat(args)); - }; - - this.render = function () { - return _react2.default.createElement(_content2.default, { - className: _this2.props.className, - editor: _this2, - state: _this2.state.state, - onChange: _this2.onChange, - readOnly: _this2.props.readOnly, - renderMark: _this2.renderMark, - renderNode: _this2.renderNode, - onPaste: _this2.onPaste, - onBeforeInput: _this2.onBeforeInput, - onKeyDown: _this2.onKeyDown, - style: _this2.props.style - }); - }; - - this.renderNode = function (node) { - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = _this2.state.plugins[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var plugin = _step3.value; - - if (!plugin.renderNode) continue; - var component = plugin.renderNode(node, _this2.state.state, _this2); - if (component) return component; - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3.return) { - _iterator3.return(); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - }; - - this.renderMark = function (mark) { - var _iteratorNormalCompletion4 = true; - var _didIteratorError4 = false; - var _iteratorError4 = undefined; - - try { - for (var _iterator4 = _this2.state.plugins[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var plugin = _step4.value; - - if (!plugin.renderMark) continue; - var style = plugin.renderMark(mark, _this2.state.state, _this2); - if (style) return style; - } - } catch (err) { - _didIteratorError4 = true; - _iteratorError4 = err; - } finally { - try { - if (!_iteratorNormalCompletion4 && _iterator4.return) { - _iterator4.return(); - } - } finally { - if (_didIteratorError4) { - throw _iteratorError4; - } - } - } - }; - - this.resolvePlugins = function (props) { - var onChange = props.onChange; - var plugins = props.plugins; - - var editorPlugin = _objectWithoutProperties(props, ['onChange', 'plugins']); - - var corePlugin = (0, _core2.default)(props); - return [editorPlugin].concat(_toConsumableArray(plugins), [corePlugin]); - }; - - this.resolveState = function (state) { - var plugins = _this2.state.plugins; - var _state = state; - var document = _state.document; - - - document = document.decorateTexts(function (text) { - var _iteratorNormalCompletion5 = true; - var _didIteratorError5 = false; - var _iteratorError5 = undefined; - - try { - for (var _iterator5 = plugins[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { - var plugin = _step5.value; - - if (!plugin.renderDecorations) continue; - var characters = plugin.renderDecorations(text, state, _this2); - if (characters) return characters; - } - } catch (err) { - _didIteratorError5 = true; - _iteratorError5 = err; - } finally { - try { - if (!_iteratorNormalCompletion5 && _iterator5.return) { - _iterator5.return(); - } - } finally { - if (_didIteratorError5) { - throw _iteratorError5; - } - } - } - }); - - state = state.merge({ document: document }); - return state; - }; -}; - -exports.default = Editor; -},{"../models/state":16,"../plugins/core":20,"./content":1,"react":362}],3:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _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; }; - -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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _offsetKey = require('../utils/offset-key'); - -var _offsetKey2 = _interopRequireDefault(_offsetKey); - -var _react = require('react'); - -var _react2 = _interopRequireDefault(_react); - -var _reactDom = require('react-dom'); - -var _reactDom2 = _interopRequireDefault(_reactDom); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * Leaf. - */ - -var Leaf = function (_React$Component) { - _inherits(Leaf, _React$Component); - - function Leaf() { - _classCallCheck(this, Leaf); - - return _possibleConstructorReturn(this, Object.getPrototypeOf(Leaf).apply(this, arguments)); - } - - _createClass(Leaf, [{ - key: 'shouldComponentUpdate', - - - /** - * Should component update? - * - * @param {Object} props - * @return {Boolean} shouldUpdate - */ - - value: function shouldComponentUpdate(props) { - var start = props.start; - var end = props.end; - var node = props.node; - var state = props.state; - var selection = state.selection; - - - var should = selection.hasEdgeBetween(node, start, end) || props.start != this.props.start || props.end != this.props.end || props.text != this.props.text || props.marks != this.props.marks; - - return should; - } - - /** - * Properties. - */ - - }, { - key: 'componentDidMount', - value: function componentDidMount() { - this.updateSelection(); - } - }, { - key: 'componentDidUpdate', - value: function componentDidUpdate() { - this.updateSelection(); - } - }, { - key: 'updateSelection', - value: function updateSelection() { - var state = this.props.state; - var selection = state.selection; - - // If the selection is not focused we have nothing to do. - - if (!selection.isFocused) return; - - var anchorOffset = selection.anchorOffset; - var focusOffset = selection.focusOffset; - var _props = this.props; - var node = _props.node; - var start = _props.start; - var end = _props.end; - - // If neither matches, the selection doesn't start or end here, so exit. - - var hasAnchor = selection.hasAnchorBetween(node, start, end); - var hasFocus = selection.hasFocusBetween(node, start, end); - if (!hasAnchor && !hasFocus) return; - - // We have a selection to render, so prepare a few things... - var native = window.getSelection(); - var el = _reactDom2.default.findDOMNode(this).firstChild; - - // If both the start and end are here, set the selection all at once. - if (hasAnchor && hasFocus) { - native.removeAllRanges(); - var range = window.document.createRange(); - range.setStart(el, anchorOffset - start); - native.addRange(range); - native.extend(el, focusOffset - start); - return; - } - - // If the selection is forward, we can set things in sequence. In - // the first leaf to render, reset the selection and set the new start. And - // then in the second leaf to render, extend to the new end. - if (selection.isForward) { - if (hasAnchor) { - native.removeAllRanges(); - var _range = window.document.createRange(); - _range.setStart(el, anchorOffset - start); - native.addRange(_range); - } else if (hasFocus) { - native.extend(el, focusOffset - start); - } - } - - // Otherwise, if the selection is backward, we need to hack the order a bit. - // In the first leaf to render, set a phony start anchor to store the true - // end position. And then in the second leaf to render, set the start and - // extend the end to the stored value. - else { - if (hasFocus) { - native.removeAllRanges(); - var _range2 = window.document.createRange(); - _range2.setStart(el, focusOffset - start); - native.addRange(_range2); - } else if (hasAnchor) { - var endNode = native.focusNode; - var endOffset = native.focusOffset; - native.removeAllRanges(); - var _range3 = window.document.createRange(); - _range3.setStart(el, anchorOffset - start); - native.addRange(_range3); - native.extend(endNode, endOffset); - } - } - } - }, { - key: 'render', - value: function render() { - var _props2 = this.props; - var node = _props2.node; - var text = _props2.text; - var marks = _props2.marks; - var start = _props2.start; - var end = _props2.end; - var renderMark = _props2.renderMark; - - var offsetKey = _offsetKey2.default.stringify({ - key: node.key, - start: start, - end: end - }); - - var style = marks.reduce(function (memo, mark) { - return _extends({}, memo, renderMark(mark)); - }, {}); - - return _react2.default.createElement( - 'span', - { - 'data-offset-key': offsetKey, - style: style - }, - text || _react2.default.createElement('br', null) - ); - } - }]); - - return Leaf; -}(_react2.default.Component); - -/** - * Export. - */ - -Leaf.propTypes = { - end: _react2.default.PropTypes.number.isRequired, - marks: _react2.default.PropTypes.object.isRequired, - node: _react2.default.PropTypes.object.isRequired, - renderMark: _react2.default.PropTypes.func.isRequired, - start: _react2.default.PropTypes.number.isRequired, - state: _react2.default.PropTypes.object.isRequired, - text: _react2.default.PropTypes.string.isRequired -}; -exports.default = Leaf; -},{"../utils/offset-key":28,"react":362,"react-dom":214}],4:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _reactPortal = require('react-portal'); - -var _reactPortal2 = _interopRequireDefault(_reactPortal); - -var _react = require('react'); - -var _react2 = _interopRequireDefault(_react); - -var _findDomNode = require('../utils/find-dom-node'); - -var _findDomNode2 = _interopRequireDefault(_findDomNode); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * Placeholder. - */ - -var Placeholder = function (_React$Component) { - _inherits(Placeholder, _React$Component); - - function Placeholder() { - var _Object$getPrototypeO; - - var _temp, _this, _ret; - - _classCallCheck(this, Placeholder); - - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(Placeholder)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.shouldComponentUpdate = function (props, state) { - return props.children != _this.props.children || props.className != _this.props.className || props.parent != _this.props.parent || props.node != _this.props.node || props.style != _this.props.style; - }, _this.isVisible = function () { - var _this$props = _this.props; - var onlyFirstChild = _this$props.onlyFirstChild; - var node = _this$props.node; - var parent = _this$props.parent; - - if (node.text) return false; - if (parent.nodes.size > 1) return false; - - var isFirst = parent.nodes.first() === node; - if (isFirst) return true; - - return false; - }, _this.onOpen = function (portal) { - var node = _this.props.node; - - var el = portal.firstChild; - var nodeEl = (0, _findDomNode2.default)(node); - var rect = nodeEl.getBoundingClientRect(); - el.style.pointerEvents = 'none'; - el.style.position = 'absolute'; - el.style.top = window.scrollY + rect.top + 'px'; - el.style.left = window.scrollX + rect.left + 'px'; - el.style.width = rect.width + 'px'; - el.style.height = rect.height + 'px'; - }, _this.render = function () { - var isOpen = _this.isVisible(); - var _this$props2 = _this.props; - var children = _this$props2.children; - var className = _this$props2.className; - var style = _this.props.style; - - - if (typeof children === 'string' && style == null && className == null) { - style = { opacity: '0.333' }; - } - - return _react2.default.createElement( - _reactPortal2.default, - { isOpened: isOpen, onOpen: _this.onOpen }, - _react2.default.createElement( - 'span', - { className: className, style: style }, - children - ) - ); - }, _temp), _possibleConstructorReturn(_this, _ret); - } - - /** - * Properties. - */ - - /** - * Should the component update? - * - * @param {Object} props - * @param {Object} state - * @return {Boolean} - */ - - /** - * Is the placeholder visible? - * - * @return {Boolean} - */ - - /** - * On open, update the placeholder element's position. - * - * @param {Element} portal - */ - - /** - * Render. - * - * If the placeholder is a string, and no `className` or `style` has been - * passed, give it a default style of lowered opacity. - * - * @return {Element} element - */ - - return Placeholder; -}(_react2.default.Component); - -/** - * Export. - */ - -Placeholder.propTypes = { - children: _react2.default.PropTypes.any.isRequired, - className: _react2.default.PropTypes.string, - node: _react2.default.PropTypes.object.isRequired, - parent: _react2.default.PropTypes.object.isRequired, - state: _react2.default.PropTypes.object.isRequired, - style: _react2.default.PropTypes.object -}; -exports.default = Placeholder; -},{"../utils/find-dom-node":25,"react":362,"react-portal":216}],5:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _leaf = require('./leaf'); - -var _leaf2 = _interopRequireDefault(_leaf); - -var _react = require('react'); - -var _react2 = _interopRequireDefault(_react); - -var _groupByMarks = require('../utils/group-by-marks'); - -var _groupByMarks2 = _interopRequireDefault(_groupByMarks); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * Text. - */ - -var Text = function (_React$Component) { - _inherits(Text, _React$Component); - - function Text() { - _classCallCheck(this, Text); - - return _possibleConstructorReturn(this, Object.getPrototypeOf(Text).apply(this, arguments)); - } - - _createClass(Text, [{ - key: 'shouldComponentUpdate', - - - /** - * Should the component update? - * - * @param {Object} props - * @param {Object} state - * @return {Boolean} shouldUpdate - */ - - value: function shouldComponentUpdate(props, state) { - return props.state.selection.hasEdgeIn(props.node) || props.node.decorations != this.props.node.decorations || props.node.characters != this.props.node.characters; - } - - /** - * Render. - * - * @return {Element} element - */ - - /** - * Properties. - */ - - }, { - key: 'render', - value: function render() { - return _react2.default.createElement( - 'span', - null, - this.renderLeaves() - ); - } - - /** - * Render the leaf nodes. - * - * @return {Array} leaves - */ - - }, { - key: 'renderLeaves', - value: function renderLeaves() { - var _this2 = this; - - var node = this.props.node; - var characters = node.characters; - var decorations = node.decorations; - - var ranges = (0, _groupByMarks2.default)(decorations || characters); - - return ranges.map(function (range, i, original) { - var previous = original.slice(0, i); - var offset = previous.size ? previous.map(function (r) { - return r.text; - }).join('').length : 0; - return _this2.renderLeaf(range, i, offset); - }); - } - - /** - * Render a single leaf node given a `range` and `offset`. - * - * @param {Object} range - * @param {Number} index - * @param {Number} offset - * @return {Element} leaf - */ - - }, { - key: 'renderLeaf', - value: function renderLeaf(range, index, offset) { - var _props = this.props; - var node = _props.node; - var renderMark = _props.renderMark; - var state = _props.state; - - var text = range.text; - var marks = range.marks; - var start = offset; - var end = offset + text.length; - - return _react2.default.createElement(_leaf2.default, { - key: node.key + '-' + index, - state: state, - node: node, - start: start, - end: end, - text: text, - marks: marks, - renderMark: renderMark - }); - } - }]); - - return Text; -}(_react2.default.Component); - -/** - * Export. - */ - -Text.propTypes = { - editor: _react2.default.PropTypes.object.isRequired, - node: _react2.default.PropTypes.object.isRequired, - renderMark: _react2.default.PropTypes.func.isRequired, - state: _react2.default.PropTypes.object.isRequired -}; -exports.default = Text; -},{"../utils/group-by-marks":26,"./leaf":3,"immutable":122,"react":362}],6:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _leaf = require('./leaf'); - -var _leaf2 = _interopRequireDefault(_leaf); - -var _mark = require('../models/mark'); - -var _mark2 = _interopRequireDefault(_mark); - -var _offsetKey = require('../utils/offset-key'); - -var _offsetKey2 = _interopRequireDefault(_offsetKey); - -var _react = require('react'); - -var _react2 = _interopRequireDefault(_react); - -var _reactDom = require('react-dom'); - -var _reactDom2 = _interopRequireDefault(_reactDom); - -var _keycode = require('keycode'); - -var _keycode2 = _interopRequireDefault(_keycode); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * Void. - */ - -var Void = function (_React$Component) { - _inherits(Void, _React$Component); - - function Void() { - var _Object$getPrototypeO; - - var _temp, _this, _ret; - - _classCallCheck(this, Void); - - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(Void)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.shouldComponentUpdate = function (props) { - return props.node != _this.props.node || props.state.selection.hasEdgeIn(props.node) || _this.props.state.selection.hasEdgeIn(_this.props.node); - }, _this.render = function () { - var _this$props = _this.props; - var children = _this$props.children; - var node = _this$props.node; - - var Tag = node.kind == 'block' ? 'div' : 'span'; - var style = { - position: 'relative' - }; - - return _react2.default.createElement( - Tag, - { style: style }, - _this.renderSpacer(), - _react2.default.createElement( - 'div', - { contentEditable: false }, - children - ) - ); - }, _this.renderSpacer = function () { - var style = { - position: 'absolute', - top: '0px', - right: '0px', - bottom: '0px', - left: '0px', - textIndent: '-9999px' - }; - - return _react2.default.createElement( - 'span', - { style: style }, - _this.renderLeaf() - ); - }, _this.renderLeaf = function () { - var _this$props2 = _this.props; - var node = _this$props2.node; - var state = _this$props2.state; - - var child = node.getTextNodes().first(); - var text = ''; - var marks = _mark2.default.createSet(); - var start = 0; - var end = 0; - var offsetKey = _offsetKey2.default.stringify({ - key: child.key, - start: start, - end: end - }); - - return _react2.default.createElement(_leaf2.default, { - ref: _this.renderLeafRefs, - renderMark: _this.renderLeafMark, - key: offsetKey, - state: state, - node: child, - start: start, - end: end, - text: text, - marks: marks - }); - }, _this.renderLeafMark = function (mark) { - return {}; - }, _this.renderLeafRefs = function (el) { - _this.leaf = el; - }, _temp), _possibleConstructorReturn(_this, _ret); - } - - return Void; -}(_react2.default.Component); - -/** - * Export. - */ - -Void.propTypes = { - children: _react2.default.PropTypes.any.isRequired, - editor: _react2.default.PropTypes.object.isRequired, - node: _react2.default.PropTypes.object.isRequired, - state: _react2.default.PropTypes.object.isRequired -}; -exports.default = Void; -},{"../models/mark":13,"../utils/offset-key":28,"./leaf":3,"keycode":125,"react":362,"react-dom":214}],7:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Utils = exports.Text = exports.State = exports.Selection = exports.Raw = exports.Plain = exports.Placeholder = exports.Mark = exports.Inline = exports.Html = exports.Editor = exports.Document = exports.Data = exports.Character = exports.Block = undefined; - -var _editor = require('./components/editor'); - -var _editor2 = _interopRequireDefault(_editor); - -var _placeholder = require('./components/placeholder'); - -var _placeholder2 = _interopRequireDefault(_placeholder); - -var _block = require('./models/block'); - -var _block2 = _interopRequireDefault(_block); - -var _character = require('./models/character'); - -var _character2 = _interopRequireDefault(_character); - -var _data = require('./models/data'); - -var _data2 = _interopRequireDefault(_data); - -var _document = require('./models/document'); - -var _document2 = _interopRequireDefault(_document); - -var _inline = require('./models/inline'); - -var _inline2 = _interopRequireDefault(_inline); - -var _mark = require('./models/mark'); - -var _mark2 = _interopRequireDefault(_mark); - -var _selection = require('./models/selection'); - -var _selection2 = _interopRequireDefault(_selection); - -var _state = require('./models/state'); - -var _state2 = _interopRequireDefault(_state); - -var _text = require('./models/text'); - -var _text2 = _interopRequireDefault(_text); - -var _html = require('./serializers/html'); - -var _html2 = _interopRequireDefault(_html); - -var _plain = require('./serializers/plain'); - -var _plain2 = _interopRequireDefault(_plain); - -var _raw = require('./serializers/raw'); - -var _raw2 = _interopRequireDefault(_raw); - -var _key = require('./utils/key'); - -var _key2 = _interopRequireDefault(_key); - -var _findDomNode = require('./utils/find-dom-node'); - -var _findDomNode2 = _interopRequireDefault(_findDomNode); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * Utils. - */ - -/** - * Models. - */ - -/** - * Components. - */ - -var Utils = { - Key: _key2.default, - findDOMNode: _findDomNode2.default -}; - -/** - * Export. - */ - -/** - * Serializers. - */ - -exports.Block = _block2.default; -exports.Character = _character2.default; -exports.Data = _data2.default; -exports.Document = _document2.default; -exports.Editor = _editor2.default; -exports.Html = _html2.default; -exports.Inline = _inline2.default; -exports.Mark = _mark2.default; -exports.Placeholder = _placeholder2.default; -exports.Plain = _plain2.default; -exports.Raw = _raw2.default; -exports.Selection = _selection2.default; -exports.State = _state2.default; -exports.Text = _text2.default; -exports.Utils = Utils; -exports.default = { - Block: _block2.default, - Character: _character2.default, - Data: _data2.default, - Document: _document2.default, - Editor: _editor2.default, - Html: _html2.default, - Inline: _inline2.default, - Mark: _mark2.default, - Placeholder: _placeholder2.default, - Plain: _plain2.default, - Raw: _raw2.default, - Selection: _selection2.default, - State: _state2.default, - Text: _text2.default, - Utils: Utils -}; -},{"./components/editor":2,"./components/placeholder":4,"./models/block":8,"./models/character":9,"./models/data":10,"./models/document":11,"./models/inline":12,"./models/mark":13,"./models/selection":15,"./models/state":16,"./models/text":17,"./serializers/html":21,"./serializers/plain":22,"./serializers/raw":23,"./utils/find-dom-node":25,"./utils/key":27}],8:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -require('./document'); - -var _inline = require('./inline'); - -var _inline2 = _interopRequireDefault(_inline); - -var _data = require('./data'); - -var _data2 = _interopRequireDefault(_data); - -var _node = require('./node'); - -var _node2 = _interopRequireDefault(_node); - -var _text = require('./text'); - -var _text2 = _interopRequireDefault(_text); - -var _uid = require('../utils/uid'); - -var _uid2 = _interopRequireDefault(_uid); - -var _immutable = require('immutable'); - -var _immutable2 = _interopRequireDefault(_immutable); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } -/** - * Prevent circuit. - */ - -/** - * Dependencies. - */ - -/** - * Default properties. - */ - -var DEFAULTS = { - data: new _immutable.Map(), - isVoid: false, - key: null, - nodes: new _immutable.List(), - type: null -}; - -/** - * Block. - */ - -var Block = function (_ref) { - _inherits(Block, _ref); - - function Block() { - _classCallCheck(this, Block); - - return _possibleConstructorReturn(this, Object.getPrototypeOf(Block).apply(this, arguments)); - } - - _createClass(Block, [{ - key: 'kind', - - - /** - * Get the node's kind. - * - * @return {String} kind - */ - - get: function get() { - return 'block'; - } - - /** - * Get the length of the concatenated text of the node. - * - * @return {Number} length - */ - - }, { - key: 'length', - get: function get() { - return this.text.length; - } - - /** - * Get the concatenated text `string` of all child nodes. - * - * @return {String} text - */ - - }, { - key: 'text', - get: function get() { - return this.nodes.map(function (node) { - return node.text; - }).join(''); - } - }], [{ - key: 'create', - - - /** - * Create a new `Block` with `properties`. - * - * @param {Object} properties - * @return {Block} element - */ - - value: function create() { - var properties = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - if (properties instanceof Block) return properties; - if (properties instanceof _inline2.default) return properties; - if (properties instanceof _text2.default) return properties; - if (!properties.type) throw new Error('You must pass a block `type`.'); - - properties.key = (0, _uid2.default)(4); - properties.data = _data2.default.create(properties.data); - properties.isVoid = !!properties.isVoid; - properties.nodes = Block.createList(properties.nodes); - - return new Block(properties).normalize(); - } - - /** - * Create a list of `Blocks` from an array. - * - * @param {Array} elements - * @return {List} list - */ - - }, { - key: 'createList', - value: function createList() { - var elements = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; - - if (_immutable.List.isList(elements)) return elements; - return new _immutable.List(elements.map(Block.create)); - } - }]); - - return Block; -}(new _immutable.Record(DEFAULTS)); - -/** - * Mix in `Node` methods. - */ - -for (var method in _node2.default) { - Block.prototype[method] = _node2.default[method]; -} - -/** - * Export. - */ - -exports.default = Block; -},{"../utils/uid":30,"./data":10,"./document":11,"./inline":12,"./node":14,"./text":17,"immutable":122}],9:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _mark = require('./mark'); - -var _mark2 = _interopRequireDefault(_mark); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * Record. - */ - -var CharacterRecord = new _immutable.Record({ - marks: new _immutable.Set(), - text: '' -}); - -/** - * Character. - */ - -var Character = function (_CharacterRecord) { - _inherits(Character, _CharacterRecord); - - function Character() { - _classCallCheck(this, Character); - - return _possibleConstructorReturn(this, Object.getPrototypeOf(Character).apply(this, arguments)); - } - - _createClass(Character, [{ - key: 'kind', - - - /** - * Get the kind. - * - * @return {String} kind - */ - - get: function get() { - return 'character'; - } - }], [{ - key: 'create', - - - /** - * Create a character record with `properties`. - * - * @param {Object} properties - * @return {Character} character - */ - - value: function create() { - var properties = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - if (properties instanceof Character) return properties; - properties.marks = _mark2.default.createSet(properties.marks); - return new Character(properties); - } - - /** - * Create a characters list from an array of characters. - * - * @param {Array} array - * @return {List} characters - */ - - }, { - key: 'createList', - value: function createList() { - var array = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; - - if (_immutable.List.isList(array)) return array; - return new _immutable.List(array.map(Character.create)); - } - }]); - - return Character; -}(CharacterRecord); - -/** - * Export. - */ - -exports.default = Character; -},{"./mark":13,"immutable":122}],10:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _immutable = require('immutable'); - -/** - * Data. - * - * This isn't an immutable record, it's just a thin wrapper around `Map` so that - * we can allow for more convenient creation. - */ - -var Data = { - - /** - * Create a new `Data` with `properties`. - * - * @param {Object} properties - * @return {Data} data - */ - - create: function create() { - var properties = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - return _immutable.Map.isMap(properties) ? properties : new _immutable.Map(properties); - } -}; - -/** - * Export. - */ - -exports.default = Data; -},{"immutable":122}],11:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _block = require('./block'); - -var _block2 = _interopRequireDefault(_block); - -require('./inline'); - -var _node = require('./node'); - -var _node2 = _interopRequireDefault(_node); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } -/** - * Prevent circuit. - */ - -/** - * Dependencies. - */ - -/** - * Defaults. - */ - -var DEFAULTS = { - nodes: new _immutable.OrderedMap() -}; - -/** - * Document. - */ - -var Document = function (_ref) { - _inherits(Document, _ref); - - function Document() { - _classCallCheck(this, Document); - - return _possibleConstructorReturn(this, Object.getPrototypeOf(Document).apply(this, arguments)); - } - - _createClass(Document, [{ - key: 'kind', - - - /** - * Get the node's kind. - * - * @return {String} kind - */ - - get: function get() { - return 'document'; - } - - /** - * Get the length of the concatenated text of the node. - * - * @return {Number} length - */ - - }, { - key: 'length', - get: function get() { - return this.text.length; - } - - /** - * Get the concatenated text `string` of all child nodes. - * - * @return {String} text - */ - - }, { - key: 'text', - get: function get() { - return this.nodes.map(function (node) { - return node.text; - }).join(''); - } - }], [{ - key: 'create', - - - /** - * Create a new `Document` with `properties`. - * - * @param {Objetc} properties - * @return {Document} document - */ - - value: function create() { - var properties = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - if (properties instanceof Document) return properties; - properties.nodes = _block2.default.createList(properties.nodes); - return new Document(properties).normalize(); - } - }]); - - return Document; -}(new _immutable.Record(DEFAULTS)); - -/** - * Mix in `Node` methods. - */ - -for (var method in _node2.default) { - Document.prototype[method] = _node2.default[method]; -} - -/** - * Export. - */ - -exports.default = Document; -},{"./block":8,"./inline":12,"./node":14,"immutable":122}],12:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _block = require('./block'); - -var _block2 = _interopRequireDefault(_block); - -require('./document'); - -var _data = require('./data'); - -var _data2 = _interopRequireDefault(_data); - -var _node = require('./node'); - -var _node2 = _interopRequireDefault(_node); - -var _text = require('./text'); - -var _text2 = _interopRequireDefault(_text); - -var _uid = require('../utils/uid'); - -var _uid2 = _interopRequireDefault(_uid); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } -/** - * Prevent circuit. - */ - -/** - * Dependencies. - */ - -/** - * Record. - */ - -var DEFAULTS = { - data: new _immutable.Map(), - isVoid: false, - key: null, - nodes: new _immutable.List(), - type: null -}; - -/** - * Inline. - */ - -var Inline = function (_ref) { - _inherits(Inline, _ref); - - function Inline() { - _classCallCheck(this, Inline); - - return _possibleConstructorReturn(this, Object.getPrototypeOf(Inline).apply(this, arguments)); - } - - _createClass(Inline, [{ - key: 'kind', - - - /** - * Get the node's kind. - * - * @return {String} kind - */ - - get: function get() { - return 'inline'; - } - - /** - * Get the length of the concatenated text of the node. - * - * @return {Number} length - */ - - }, { - key: 'length', - get: function get() { - return this.text.length; - } - - /** - * Get the concatenated text `string` of all child nodes. - * - * @return {String} text - */ - - }, { - key: 'text', - get: function get() { - return this.nodes.map(function (node) { - return node.text; - }).join(''); - } - }], [{ - key: 'create', - - - /** - * Create a new `Inline` with `properties`. - * - * @param {Object} properties - * @return {Inline} element - */ - - value: function create() { - var properties = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - if (properties instanceof _block2.default) return properties; - if (properties instanceof Inline) return properties; - if (properties instanceof _text2.default) return properties; - if (!properties.type) throw new Error('You must pass an inline `type`.'); - - properties.key = (0, _uid2.default)(4); - properties.data = _data2.default.create(properties.data); - properties.isVoid = !!properties.isVoid; - properties.nodes = Inline.createList(properties.nodes); - - return new Inline(properties).normalize(); - } - - /** - * Create a list of `Inlines` from an array. - * - * @param {Array} elements - * @return {List} map - */ - - }, { - key: 'createList', - value: function createList() { - var elements = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; - - if (_immutable.List.isList(elements)) return elements; - return new _immutable.List(elements.map(Inline.create)); - } - }]); - - return Inline; -}(new _immutable.Record(DEFAULTS)); - -/** - * Mix in `Node` methods. - */ - -for (var method in _node2.default) { - Inline.prototype[method] = _node2.default[method]; -} - -/** - * Export. - */ - -exports.default = Inline; -},{"../utils/uid":30,"./block":8,"./data":10,"./document":11,"./node":14,"./text":17,"immutable":122}],13:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _data = require('./data'); - -var _data2 = _interopRequireDefault(_data); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * Record. - */ - -var DEFAULTS = { - data: new _immutable.Map(), - type: null -}; - -/** - * Mark. - */ - -var Mark = function (_ref) { - _inherits(Mark, _ref); - - function Mark() { - _classCallCheck(this, Mark); - - return _possibleConstructorReturn(this, Object.getPrototypeOf(Mark).apply(this, arguments)); - } - - _createClass(Mark, [{ - key: 'kind', - - - /** - * Get the kind. - * - * @return {String} kind - */ - - get: function get() { - return 'mark'; - } - }], [{ - key: 'create', - - - /** - * Create a new `Mark` with `properties`. - * - * @param {Object} properties - * @return {Mark} mark - */ - - value: function create() { - var properties = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - if (properties instanceof Mark) return properties; - if (!properties.type) throw new Error('You must provide a `type` for the mark.'); - properties.data = _data2.default.create(properties.data); - return new Mark(properties); - } - - /** - * Create a marks set from an array of marks. - * - * @param {Array} array - * @return {Set} marks - */ - - }, { - key: 'createSet', - value: function createSet() { - var array = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; - - if (_immutable.Set.isSet(array)) return array; - return new _immutable.Set(array.map(Mark.create)); - } - }]); - - return Mark; -}(new _immutable.Record(DEFAULTS)); - -/** - * Export. - */ - -exports.default = Mark; -},{"./data":10,"immutable":122}],14:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _block = require('./block'); - -var _block2 = _interopRequireDefault(_block); - -var _character = require('./character'); - -var _character2 = _interopRequireDefault(_character); - -var _data = require('./data'); - -var _data2 = _interopRequireDefault(_data); - -var _document = require('./document'); - -var _document2 = _interopRequireDefault(_document); - -var _inline = require('./inline'); - -var _inline2 = _interopRequireDefault(_inline); - -var _mark = require('./mark'); - -var _mark2 = _interopRequireDefault(_mark); - -var _selection = require('./selection'); - -var _selection2 = _interopRequireDefault(_selection); - -var _transforms = require('./transforms'); - -var _transforms2 = _interopRequireDefault(_transforms); - -var _text3 = require('./text'); - -var _text4 = _interopRequireDefault(_text3); - -var _includes = require('lodash/includes'); - -var _includes2 = _interopRequireDefault(_includes); - -var _uid = require('../utils/uid'); - -var _uid2 = _interopRequireDefault(_uid); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * Node. - * - * And interface that `Document`, `Block` and `Inline` all implement, to make - * working with the recursive node tree easier. - */ - -var Node = { - - /** - * Assert that the node has a child by `key`. - * - * @param {String or Node} key - */ - - assertHasChild: function assertHasChild(key) { - key = normalizeKey(key); - if (!this.hasChild(key)) { - throw new Error('Could not find a child node with key "' + key + '".'); - } - }, - - - /** - * Assert that the node has a descendant by `key`. - * - * @param {String or Node} key - */ - - assertHasDescendant: function assertHasDescendant(key) { - key = normalizeKey(key); - if (!this.hasDescendant(key)) { - throw new Error('Could not find a descendant node with key "' + key + '".'); - } - }, - - - /** - * Concat children `nodes` on to the end of the node. - * - * @param {List} nodes - * @return {Node} node - */ - - concatChildren: function concatChildren(nodes) { - nodes = this.nodes.concat(nodes); - return this.merge({ nodes: nodes }); - }, - - - /** - * Decorate all of the text nodes with a `decorator` function. - * - * @param {Function} decorator - * @return {Node} node - */ - - decorateTexts: function decorateTexts(decorator) { - return this.mapDescendants(function (child) { - return child.kind == 'text' ? child.decorateCharacters(decorator) : child; - }); - }, - - - /** - * Recursively find all ancestor nodes by `iterator`. - * - * @param {Function} iterator - * @return {Node} node - */ - - findDescendant: function findDescendant(iterator) { - return this.nodes.find(iterator) || this.nodes.map(function (node) { - return node.kind == 'text' ? null : node.findDescendant(iterator); - }).find(function (exists) { - return exists; - }); - }, - - - /** - * Recursively filter all ancestor nodes with `iterator`. - * - * @param {Function} iterator - * @return {List} nodes - */ - - filterDescendants: function filterDescendants(iterator) { - return this.nodes.reduce(function (matches, child, i, nodes) { - if (iterator(child, i, nodes)) matches = matches.push(child); - if (child.kind != 'text') matches = matches.concat(child.filterDescendants(iterator)); - return matches; - }, _block2.default.createList()); - }, - - - /** - * Get the closest block nodes for each text node in the node. - * - * @return {List} nodes - */ - - getBlocks: function getBlocks() { - var _this = this; - - return this.getTextNodes().reduce(function (blocks, text) { - var block = _this.getClosestBlock(text); - return blocks.includes(block) ? blocks : blocks.push(block); - }, _block2.default.createList()); - }, - - - /** - * Get the closest block nodes for each text node in a `range`. - * - * @param {Selection} range - * @return {List} nodes - */ - - getBlocksAtRange: function getBlocksAtRange(range) { - var _this2 = this; - - range = range.normalize(this); - return this.getTextsAtRange(range).map(function (text) { - return _this2.getClosestBlock(text); - }); - }, - - - /** - * Get a list of the characters in a `range`. - * - * @param {Selection} range - * @return {List} characters - */ - - getCharactersAtRange: function getCharactersAtRange(range) { - range = range.normalize(this); - return this.getTextsAtRange(range).reduce(function (characters, text) { - var chars = text.characters.filter(function (char, i) { - return isInRange(i, text, range); - }); - return characters.concat(chars); - }, _character2.default.createList()); - }, - - - /** - * Get children after a child by `key`. - * - * @param {String or Node} key - * @return {Node} node - */ - - getChildrenAfter: function getChildrenAfter(key) { - var child = this.getChild(key); - var index = this.nodes.indexOf(child); - var nodes = this.nodes.slice(index + 1); - return nodes; - }, - - - /** - * Get children after a child by `key`, including the child. - * - * @param {String or Node} key - * @return {Node} node - */ - - getChildrenAfterIncluding: function getChildrenAfterIncluding(key) { - var child = this.getChild(key); - var index = this.nodes.indexOf(child); - var nodes = this.nodes.slice(index); - return nodes; - }, - - - /** - * Get children before a child by `key`. - * - * @param {String or Node} key - * @return {Node} node - */ - - getChildrenBefore: function getChildrenBefore(key) { - var child = this.getChild(key); - var index = this.nodes.indexOf(child); - var nodes = this.nodes.slice(0, index); - return nodes; - }, - - - /** - * Get children before a child by `key`, including the child. - * - * @param {String or Node} key - * @return {Node} node - */ - - getChildrenBeforeIncluding: function getChildrenBeforeIncluding(key) { - var child = this.getChild(key); - var index = this.nodes.indexOf(child); - var nodes = this.nodes.slice(0, index + 1); - return nodes; - }, - - - /** - * Get children between two child keys. - * - * @param {String or Node} start - * @param {String or Node} end - * @return {Node} node - */ - - getChildrenBetween: function getChildrenBetween(start, end) { - start = this.getChild(start); - start = this.nodes.indexOf(start); - end = this.getChild(end); - end = this.nodes.indexOf(end); - return this.nodes.slice(start + 1, end); - }, - - - /** - * Get children between two child keys, including the two children. - * - * @param {String or Node} start - * @param {String or Node} end - * @return {Node} node - */ - - getChildrenBetweenIncluding: function getChildrenBetweenIncluding(start, end) { - start = this.getChild(start); - start = this.nodes.indexOf(start); - end = this.getChild(end); - end = this.nodes.indexOf(end); - return this.nodes.slice(start, end + 1); - }, - - - /** - * Get closest parent of node by `key` that matches `iterator`. - * - * @param {String or Node} key - * @param {Function} iterator - * @return {Node or Null} node - */ - - getClosest: function getClosest(key, iterator) { - var node = this.getDescendant(key); - - while (node = this.getParent(node)) { - if (node == this) return null; - if (iterator(node)) return node; - } - - return null; - }, - - - /** - * Get the closest block parent of a `node`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getClosestBlock: function getClosestBlock(key) { - return this.getClosest(key, function (parent) { - return parent.kind == 'block'; - }); - }, - - - /** - * Get the closest inline parent of a `node`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getClosestInline: function getClosestInline(key) { - return this.getClosest(key, function (parent) { - return parent.kind == 'inline'; - }); - }, - - - /** - * Get a child node by `key`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getChild: function getChild(key) { - key = normalizeKey(key); - return this.nodes.find(function (node) { - return node.key == key; - }); - }, - - - /** - * Get all of the blocks closest to text nodes. - * - * @return {List} nodes - */ - - getDeepestBlocks: function getDeepestBlocks() { - var _this3 = this; - - var texts = this.getTextNodes(); - var set = texts.reduce(function (memo, text) { - return memo.add(_this3.getClosestBlock(text)); - }, new _immutable.OrderedSet()); - - return set.toList(); - }, - - - /** - * Get a descendant node by `key`. - * - * @param {String} key - * @return {Node or Null} node - */ - - getDescendant: function getDescendant(key) { - key = normalizeKey(key); - return this.findDescendant(function (node) { - return node.key == key; - }); - }, - - - /** - * Get the depth of a child node by `key`, with optional `startAt`. - * - * @param {String or Node} key - * @param {Number} startAt (optional) - * @return {Number} depth - */ - - getDepth: function getDepth(key) { - var startAt = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1]; - - key = normalizeKey(key); - this.assertHasDescendant(key); - if (this.hasChild(key)) return startAt; - return this.getHighestChild(key).getDepth(key, startAt + 1); - }, - - - /** - * Get a fragment of the node at a `range`. - * - * @param {Selection} range - * @return {List} nodes - */ - - getFragmentAtRange: function getFragmentAtRange(range) { - var node = this; - var nodes = _block2.default.createList(); - - // If the range is collapsed, there's nothing to do. - if (range.isCollapsed) return _document2.default.create({ nodes: nodes }); - - // Make sure the children exist. - var startKey = range.startKey; - var startOffset = range.startOffset; - var endKey = range.endKey; - var endOffset = range.endOffset; - - node.assertHasDescendant(startKey); - node.assertHasDescendant(endKey); - - // Split at the start and end. - var start = range.collapseToStart(); - node = node.splitBlockAtRange(start, Infinity); - - var next = node.getNextText(startKey); - var end = startKey == endKey ? range.collapseToStartOf(next).moveForward(endOffset - startOffset) : range.collapseToEnd(); - node = node.splitBlockAtRange(end, Infinity); - - // Get the start and end nodes. - var startNode = node.getNextSibling(node.getHighestChild(startKey)); - var endNode = startKey == endKey ? node.getHighestChild(next) : node.getHighestChild(endKey); - - nodes = node.getChildrenBetweenIncluding(startNode, endNode); - - // Return a new document fragment. - return _document2.default.create({ nodes: nodes }); - }, - - - /** - * Get the furthest block parent of a node by `key`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getFurthestBlock: function getFurthestBlock(key) { - var node = this.getDescendant(key); - var furthest = null; - - while (node = this.getClosestBlock(node)) { - furthest = node; - } - - return furthest; - }, - - - /** - * Get the furthest inline parent of a node by `key`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getFurthestInline: function getFurthestInline(key) { - var node = this.getDescendant(key); - var furthest = null; - - while (node = this.getClosestInline(node)) { - furthest = node; - } - - return furthest; - }, - - - /** - * Get the highest child ancestor of a node by `key`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getHighestChild: function getHighestChild(key) { - key = normalizeKey(key); - return this.nodes.find(function (node) { - if (node.key == key) return true; - if (node.kind == 'text') return false; - return node.hasDescendant(key); - }); - }, - - - /** - * Get the highest parent of a node by `key` which has an only child. - * - * @param {String or Node} key - * @return {Node or Null} - */ - - getHighestOnlyChildParent: function getHighestOnlyChildParent(key) { - var child = this.getChild(key); - var match = null; - var parent = void 0; - - while (parent = this.getParent(child)) { - if (parent == null || parent.nodes.size > 1) return match; - match = parent; - child = parent; - } - }, - - - /** - * Get the closest inline nodes for each text node in a `range`. - * - * @param {Selection} range - * @return {List} nodes - */ - - getInlinesAtRange: function getInlinesAtRange(range) { - var _this4 = this; - - range = range.normalize(this); - return this.getTextsAtRange(range).map(function (text) { - return _this4.getClosestInline(text); - }).filter(function (exists) { - return exists; - }); - }, - - - /** - * Get a set of the marks in a `range`. - * - * @param {Selection} range - * @return {Set} marks - */ - - getMarksAtRange: function getMarksAtRange(range) { - range = range.normalize(this); - var _range = range; - var startKey = _range.startKey; - var startOffset = _range.startOffset; - - var marks = _mark2.default.createSet(); - - // If the range is collapsed at the start of the node, check the previous. - if (range.isCollapsed && startOffset == 0) { - var text = this.getDescendant(startKey); - var previous = this.getPreviousText(startKey); - if (!previous || !previous.length) return marks; - var char = previous.characters.get(previous.length - 1); - return char.marks; - } - - // If the range is collapsed, check the character before the start. - if (range.isCollapsed) { - var _text = this.getDescendant(startKey); - var _char = _text.characters.get(range.startOffset - 1); - return _char.marks; - } - - // Otherwise, get a set of the marks for each character in the range. - return this.getCharactersAtRange(range).reduce(function (memo, char) { - return memo.union(char.marks); - }, marks); - }, - - - /** - * Get the block node before a descendant text node by `key`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getNextBlock: function getNextBlock(key) { - key = normalizeKey(key); - var child = this.getDescendant(key); - var last = void 0; - - if (child.kind == 'block') { - last = child.getTextNodes().last(); - } else { - var block = this.getClosestBlock(key); - last = block.getTextNodes().last(); - } - - var next = this.getNextText(last); - if (!next) return null; - - return this.getClosestBlock(next); - }, - - - /** - * Get the node after a descendant by `key`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getNextSibling: function getNextSibling(key) { - var node = this.getDescendant(key); - if (!node) return null; - return this.getParent(node).nodes.skipUntil(function (child) { - return child == node; - }).get(1); - }, - - - /** - * Get the text node after a descendant text node by `key`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getNextText: function getNextText(key) { - key = normalizeKey(key); - return this.getTextNodes().skipUntil(function (text) { - return text.key == key; - }).get(1); - }, - - - /** - * Get the offset for a descendant text node by `key`. - * - * @param {String or Node} key - * @return {Number} offset - */ - - getOffset: function getOffset(key) { - key = normalizeKey(key); - this.assertHasDescendant(key); - - // Calculate the offset of the nodes before the highest child. - var child = this.getHighestChild(key); - var offset = this.nodes.takeUntil(function (n) { - return n == child; - }).reduce(function (memo, n) { - return memo + n.length; - }, 0); - - // Recurse if need be. - return this.hasChild(key) ? offset : offset + child.getOffset(key); - }, - - - /** - * Get the offset from a `range`. - * - * @param {Selection} range - * @return {Number} offset - */ - - getOffsetAtRange: function getOffsetAtRange(range) { - if (range.isExpanded) { - throw new Error('The range must be collapsed to calculcate its offset.'); - } - - var startKey = range.startKey; - var startOffset = range.startOffset; - - var startNode = this.getDescendant(startKey); - - if (!startNode) { - throw new Error('Could not find a node by startKey "' + startKey + '".'); - } - - return this.getOffset(startKey) + startOffset; - }, - - - /** - * Get the parent of a child node by `key`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getParent: function getParent(key) { - key = normalizeKey(key); - if (this.hasChild(key)) return this; - - var node = null; - - this.nodes.forEach(function (child) { - if (child.kind == 'text') return; - var match = child.getParent(key); - if (match) node = match; - }); - - return node; - }, - - - /** - * Get the node before a descendant node by `key`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getPreviousSibling: function getPreviousSibling(key) { - var node = this.getDescendant(key); - if (!node) return null; - return this.getParent(node).nodes.takeUntil(function (child) { - return child == node; - }).last(); - }, - - - /** - * Get the text node before a descendant text node by `key`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getPreviousText: function getPreviousText(key) { - key = normalizeKey(key); - return this.getTextNodes().takeUntil(function (text) { - return text.key == key; - }).last(); - }, - - - /** - * Get the block node before a descendant text node by `key`. - * - * @param {String or Node} key - * @return {Node or Null} node - */ - - getPreviousBlock: function getPreviousBlock(key) { - key = normalizeKey(key); - var child = this.getDescendant(key); - var first = void 0; - - if (child.kind == 'block') { - first = child.getTextNodes().first(); - } else { - var block = this.getClosestBlock(key); - first = block.getTextNodes().first(); - } - - var previous = this.getPreviousText(first); - if (!previous) return null; - - return this.getClosestBlock(previous); - }, - - - /** - * Get the descendent text node at an `offset`. - * - * @param {String} offset - * @return {Node or Null} node - */ - - getTextAtOffset: function getTextAtOffset(offset) { - var length = 0; - return this.getTextNodes().find(function (text) { - length += text.length; - return length >= offset; - }); - }, - - - /** - * Recursively get all of the child text nodes in order of appearance. - * - * @return {List} nodes - */ - - getTextNodes: function getTextNodes() { - return this.nodes.reduce(function (texts, node) { - return node.kind == 'text' ? texts.push(node) : texts.concat(node.getTextNodes()); - }, _block2.default.createList()); - }, - - - /** - * Get all of the text nodes in a `range`. - * - * @param {Selection} range - * @return {List} nodes - */ - - getTextsAtRange: function getTextsAtRange(range) { - range = range.normalize(this); - var _range2 = range; - var startKey = _range2.startKey; - var endKey = _range2.endKey; - - var texts = this.getTextNodes(); - var startText = this.getDescendant(startKey); - var endText = this.getDescendant(endKey); - var start = texts.indexOf(startText); - var end = texts.indexOf(endText); - return texts.slice(start, end + 1); - }, - - - /** - * Check if a child node exists by `key`. - * - * @param {String or Node} key - * @return {Boolean} exists - */ - - hasChild: function hasChild(key) { - key = normalizeKey(key); - return !!this.nodes.find(function (node) { - return node.key == key; - }); - }, - - - /** - * Recursively check if a child node exists by `key`. - * - * @param {String or Node} key - * @return {Boolean} exists - */ - - hasDescendant: function hasDescendant(key) { - key = normalizeKey(key); - return !!this.nodes.find(function (node) { - return node.kind == 'text' ? node.key == key : node.key == key || node.hasDescendant(key); - }); - }, - - - /** - * Check if a node has a void parent by `key`. - * - * @param {String or Node} key - * @return {Boolean} - */ - - hasVoidParent: function hasVoidParent(key) { - return !!this.getClosest(key, function (n) { - return n.isVoid; - }); - }, - - - /** - * Insert child `nodes` after child by `key`. - * - * @param {String or Node} key - * @param {List} nodes - * @return {Node} node - */ - - insertChildrenAfter: function insertChildrenAfter(key, nodes) { - var child = this.getChild(key); - var index = this.nodes.indexOf(child); - - nodes = this.nodes.slice(0, index + 1).concat(nodes).concat(this.nodes.slice(index + 1)); - - return this.merge({ nodes: nodes }); - }, - - - /** - * Insert child `nodes` before child by `key`. - * - * @param {String or Node} key - * @param {List} nodes - * @return {Node} node - */ - - insertChildrenBefore: function insertChildrenBefore(key, nodes) { - key = normalizeKey(key); - var child = this.getChild(key); - var index = this.nodes.indexOf(child); - - nodes = this.nodes.slice(0, index).concat(nodes).concat(this.nodes.slice(index)); - - return this.merge({ nodes: nodes }); - }, - - - /** - * Check if the inline nodes are split at a `range`. - * - * @param {Selection} range - * @return {Boolean} isSplit - */ - - isInlineSplitAtRange: function isInlineSplitAtRange(range) { - range = range.normalize(this); - if (range.isExpanded) throw new Error(); - - var _range3 = range; - var startKey = _range3.startKey; - - var start = this.getFurthestInline(startKey) || this.getDescendant(startKey); - return range.isAtStartOf(start) || range.isAtEndOf(start); - }, - - - /** - * Map all child nodes, updating them in their parents. This method is - * optimized to not return a new node if no changes are made. - * - * @param {Function} iterator - * @return {Node} node - */ - - mapChildren: function mapChildren(iterator) { - var _this5 = this; - - var nodes = this.nodes; - - nodes.forEach(function (node, i) { - var ret = iterator(node, i, _this5.nodes); - if (ret != node) nodes = nodes.set(ret.key, ret); - }); - - return this.merge({ nodes: nodes }); - }, - - - /** - * Map all descendant nodes, updating them in their parents. This method is - * optimized to not return a new node if no changes are made. - * - * @param {Function} iterator - * @return {Node} node - */ - - mapDescendants: function mapDescendants(iterator) { - var _this6 = this; - - var nodes = this.nodes; - - nodes.forEach(function (node, i) { - var ret = node; - if (ret.kind != 'text') ret = ret.mapDescendants(iterator); - ret = iterator(ret, i, _this6.nodes); - if (ret == node) return; - - var index = nodes.indexOf(node); - nodes = nodes.set(index, ret); - }); - - return this.merge({ nodes: nodes }); - }, - - - /** - * Normalize the node by joining any two adjacent text child nodes. - * - * @return {Node} node - */ - - normalize: function normalize() { - var node = this; - - // Map this node's descendants, ensuring... ensuring there are no duplicate keys. - var keys = []; - - node = node.mapDescendants(function (desc) { - // That there are no duplicate keys. - if ((0, _includes2.default)(keys, desc.key)) desc = desc.set('key', (0, _uid2.default)()); - keys.push(desc.key); - - // That void nodes contain no text. - if (desc.isVoid && desc.length) { - var text = desc.getTextNodes().first(); - var _characters = text.characters.clear(); - text = text.merge({ characters: _characters }); - var nodes = desc.nodes.clear().push(text); - desc = desc.merge({ nodes: nodes }); - } - - // That no block or inline node is empty. - if (desc.kind != 'text' && desc.nodes.size == 0) { - var _text2 = _text4.default.create(); - var _nodes = desc.nodes.push(_text2); - desc = desc.merge({ nodes: _nodes }); - } - - return desc; - }); - - // See if there are any adjacent text nodes. - var first = node.findDescendant(function (child) { - if (child.kind != 'text') return; - var parent = node.getParent(child); - var next = parent.getNextSibling(child); - return next && next.kind == 'text'; - }); - - // If no text nodes are adjacent, abort. - if (!first) return node; - - // Fix an adjacent text node if one exists. - var parent = node.getParent(first); - var isParent = node == parent; - var second = parent.getNextSibling(first); - var characters = first.characters.concat(second.characters); - first = first.merge({ characters: characters }); - parent = parent.updateDescendant(first); - - // Then remove the second text node. - parent = parent.removeDescendant(second); - - // And update the node. - node = isParent ? parent : node.updateDescendant(parent); - - // Recurse by normalizing again. - return node.normalize(); - }, - - - /** - * Remove children after a child by `key`. - * - * @param {String or Node} key - * @return {Node} node - */ - - removeChildrenAfter: function removeChildrenAfter(key) { - var child = this.getChild(key); - var index = this.nodes.indexOf(child); - var nodes = this.nodes.slice(0, index + 1); - return this.merge({ nodes: nodes }); - }, - - - /** - * Remove children after a child by `key`, including the child. - * - * @param {String or Node} key - * @return {Node} node - */ - - removeChildrenAfterIncluding: function removeChildrenAfterIncluding(key) { - var child = this.getChild(key); - var index = this.nodes.indexOf(child); - var nodes = this.nodes.slice(0, index); - return this.merge({ nodes: nodes }); - }, - - - /** - * Remove a `node` from the children node map. - * - * @param {String or Node} key - * @return {Node} node - */ - - removeDescendant: function removeDescendant(key) { - key = normalizeKey(key); - this.assertHasDescendant(key); - - var child = this.getChild(key); - - if (child) { - var _nodes2 = this.nodes.filterNot(function (node) { - return node == child; - }); - return this.merge({ nodes: _nodes2 }); - } - - var nodes = this.mapChildren(function (n) { - return n.kind == 'text' ? n : n.removeDescendant(key); - }); - return this.merge({ nodes: nodes }); - }, - - - /** - * Set a new value for a child node by `key`. - * - * @param {Node} node - * @return {Node} node - */ - - updateDescendant: function updateDescendant(node) { - this.assertHasDescendant(node); - return this.mapDescendants(function (d) { - return d.key == node.key ? node : d; - }); - } -}; - -/** - * Normalize a `key`, from a key string or a node. - * - * @param {String or Node} key - * @return {String} key - */ - -function normalizeKey(key) { - if (typeof key == 'string') return key; - return key.key; -} - -/** - * Check if an `index` of a `text` node is in a `range`. - * - * @param {Number} index - * @param {Text} text - * @param {Selection} range - * @return {Set} characters - */ - -function isInRange(index, text, range) { - var startKey = range.startKey; - var startOffset = range.startOffset; - var endKey = range.endKey; - var endOffset = range.endOffset; - - var matcher = void 0; - - if (text.key == startKey && text.key == endKey) { - return startOffset <= index && index < endOffset; - } else if (text.key == startKey) { - return startOffset <= index; - } else if (text.key == endKey) { - return index < endOffset; - } else { - return true; - } -} - -/** - * Transforms. - */ - -for (var key in _transforms2.default) { - Node[key] = _transforms2.default[key]; -} - -/** - * Export. - */ - -exports.default = Node; -},{"../utils/uid":30,"./block":8,"./character":9,"./data":10,"./document":11,"./inline":12,"./mark":13,"./selection":15,"./text":17,"./transforms":19,"immutable":122,"lodash/includes":188}],15:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); - -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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _includes = require('lodash/includes'); - -var _includes2 = _interopRequireDefault(_includes); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * Start-and-end convenience methods to auto-generate. - */ - -var START_END_METHODS = ['collapseTo%']; - -/** - * Start-end-and-edge convenience methods to auto-generate. - */ - -var EDGE_METHODS = ['has%AtStartOf', 'has%AtEndOf', 'has%Between', 'has%In']; - -/** - * Default properties. - */ - -var DEFAULTS = { - anchorKey: null, - anchorOffset: 0, - focusKey: null, - focusOffset: 0, - isBackward: null, - isFocused: false -}; - -/** - * Selection. - */ - -var Selection = function (_ref) { - _inherits(Selection, _ref); - - function Selection() { - _classCallCheck(this, Selection); - - return _possibleConstructorReturn(this, Object.getPrototypeOf(Selection).apply(this, arguments)); - } - - _createClass(Selection, [{ - key: 'hasAnchorAtStartOf', - - - /** - * Check whether anchor point of the selection is at the start of a `node`. - * - * @param {Node} node - * @return {Boolean} - */ - - value: function hasAnchorAtStartOf(node) { - var first = node.kind == 'text' ? node : node.getTextNodes().first(); - return this.anchorKey == first.key && this.anchorOffset == 0; - } - - /** - * Check whether anchor point of the selection is at the end of a `node`. - * - * @param {Node} node - * @return {Boolean} - */ - - }, { - key: 'hasAnchorAtEndOf', - value: function hasAnchorAtEndOf(node) { - var last = node.kind == 'text' ? node : node.getTextNodes().last(); - return this.anchorKey == last.key && this.anchorOffset == last.length; - } - - /** - * Check whether the anchor edge of a selection is in a `node` and at an - * offset between `start` and `end`. - * - * @param {Node} node - * @param {Number} start - * @param {Number} end - * @return {Boolean} - */ - - }, { - key: 'hasAnchorBetween', - value: function hasAnchorBetween(node, start, end) { - return this.hasAnchorIn(node) && start <= this.anchorOffset && this.anchorOffset <= end; - } - - /** - * Check whether the anchor edge of a selection is in a `node`. - * - * @param {Node} node - * @return {Boolean} - */ - - }, { - key: 'hasAnchorIn', - value: function hasAnchorIn(node) { - var _this2 = this; - - var nodes = node.kind == 'text' ? [node] : node.getTextNodes(); - return nodes.some(function (n) { - return n.key == _this2.anchorKey; - }); - } - - /** - * Check whether focus point of the selection is at the end of a `node`. - * - * @param {Node} node - * @return {Boolean} - */ - - }, { - key: 'hasFocusAtEndOf', - value: function hasFocusAtEndOf(node) { - var last = node.kind == 'text' ? node : node.getTextNodes().last(); - return this.focusKey == last.key && this.focusOffset == last.length; - } - - /** - * Check whether focus point of the selection is at the start of a `node`. - * - * @param {Node} node - * @return {Boolean} - */ - - }, { - key: 'hasFocusAtStartOf', - value: function hasFocusAtStartOf(node) { - var first = node.kind == 'text' ? node : node.getTextNodes().first(); - return this.focusKey == first.key && this.focusOffset == 0; - } - - /** - * Check whether the focus edge of a selection is in a `node` and at an - * offset between `start` and `end`. - * - * @param {Node} node - * @param {Number} start - * @param {Number} end - * @return {Boolean} - */ - - }, { - key: 'hasFocusBetween', - value: function hasFocusBetween(node, start, end) { - return this.hasFocusIn(node) && start <= this.focusOffset && this.focusOffset <= end; - } - - /** - * Check whether the focus edge of a selection is in a `node`. - * - * @param {Node} node - * @return {Boolean} - */ - - }, { - key: 'hasFocusIn', - value: function hasFocusIn(node) { - var _this3 = this; - - var nodes = node.kind == 'text' ? [node] : node.getTextNodes(); - return nodes.some(function (n) { - return n.key == _this3.focusKey; - }); - } - - /** - * Check whether the selection is at the start of a `node`. - * - * @param {Node} node - * @return {Boolean} isAtStart - */ - - }, { - key: 'isAtStartOf', - value: function isAtStartOf(node) { - var startKey = this.startKey; - var startOffset = this.startOffset; - - var first = node.kind == 'text' ? node : node.getTextNodes().first(); - return this.isCollapsed && startKey == first.key && startOffset == 0; - } - - /** - * Check whether the selection is at the end of a `node`. - * - * @param {Node} node - * @return {Boolean} isAtEnd - */ - - }, { - key: 'isAtEndOf', - value: function isAtEndOf(node) { - var endKey = this.endKey; - var endOffset = this.endOffset; - - var last = node.kind == 'text' ? node : node.getTextNodes().last(); - return this.isCollapsed && endKey == last.key && endOffset == last.length; - } - - /** - * Normalize the selection, relative to a `node`, ensuring that the anchor - * and focus nodes of the selection always refer to leaf text nodes. - * - * @param {Node} node - * @return {Selection} selection - */ - - }, { - key: 'normalize', - value: function normalize(node) { - var selection = this; - var isCollapsed = selection.isCollapsed; - var anchorKey = selection.anchorKey; - var anchorOffset = selection.anchorOffset; - var focusKey = selection.focusKey; - var focusOffset = selection.focusOffset; - var isBackward = selection.isBackward; - - // If the selection isn't formed yet or is malformed, set it to the - // beginning of the node. - - if (anchorKey == null || focusKey == null || !node.hasDescendant(anchorKey) || !node.hasDescendant(focusKey)) { - var first = node.getTextNodes().first(); - return selection.merge({ - anchorKey: first.key, - anchorOffset: 0, - focusKey: first.key, - focusOffset: 0, - isBackward: false - }); - } - - // Get the anchor and focus nodes. - var anchorNode = node.getDescendant(anchorKey); - var focusNode = node.getDescendant(focusKey); - - // If the anchor node isn't a text node, match it to one. - if (anchorNode.kind != 'text') { - var anchorText = anchorNode.getTextAtOffset(anchorOffset); - var offset = anchorNode.getOffset(anchorText); - anchorOffset = anchorOffset - offset; - anchorNode = anchorText; - } - - // If the focus node isn't a text node, match it to one. - if (focusNode.kind != 'text') { - var focusText = focusNode.getTextAtOffset(focusOffset); - var _offset = focusNode.getOffset(focusText); - focusOffset = focusOffset - _offset; - focusNode = focusText; - } - - // If `isBackward` is not set, derive it. - if (isBackward == null) { - var texts = node.getTextNodes(); - var anchorIndex = texts.indexOf(anchorNode); - var focusIndex = texts.indexOf(focusNode); - isBackward = anchorIndex == focusIndex ? anchorOffset > focusOffset : anchorIndex > focusIndex; - } - - // Merge in any updated properties. - return selection.merge({ - anchorKey: anchorNode.key, - anchorOffset: anchorOffset, - focusKey: focusNode.key, - focusOffset: focusOffset, - isBackward: isBackward - }); - } - - /** - * Focus the selection. - * - * @return {Selection} selection - */ - - }, { - key: 'focus', - value: function focus() { - return this.merge({ - isFocused: true - }); - } - - /** - * Blur the selection. - * - * @return {Selection} selection - */ - - }, { - key: 'blur', - value: function blur() { - return this.merge({ - isFocused: false - }); - } - - /** - * Move the focus point to the anchor point. - * - * @return {Selection} selection - */ - - }, { - key: 'collapseToAnchor', - value: function collapseToAnchor() { - return this.merge({ - focusKey: this.anchorKey, - focusOffset: this.anchorOffset, - isBackward: false - }); - } - - /** - * Move the anchor point to the focus point. - * - * @return {Selection} selection - */ - - }, { - key: 'collapseToFocus', - value: function collapseToFocus() { - return this.merge({ - anchorKey: this.focusKey, - anchorOffset: this.focusOffset, - isBackward: false - }); - } - - /** - * Move to the start of a `node`. - * - * @return {Selection} selection - */ - - }, { - key: 'collapseToStartOf', - value: function collapseToStartOf(node) { - return this.merge({ - anchorKey: node.key, - anchorOffset: 0, - focusKey: node.key, - focusOffset: 0, - isBackward: false - }); - } - - /** - * Move to the end of a `node`. - * - * @return {Selection} selection - */ - - }, { - key: 'collapseToEndOf', - value: function collapseToEndOf(node) { - return this.merge({ - anchorKey: node.key, - anchorOffset: node.length, - focusKey: node.key, - focusOffset: node.length, - isBackward: false - }); - } - - /** - * Move to the entire range of `start` and `end` nodes. - * - * @param {Node} start - * @param {Node} end (optional) - * @return {Selection} selection - */ - - }, { - key: 'moveToRangeOf', - value: function moveToRangeOf(start) { - var end = arguments.length <= 1 || arguments[1] === undefined ? start : arguments[1]; - - return this.merge({ - anchorKey: start.key, - anchorOffset: 0, - focusKey: end.key, - focusOffset: end.length, - isBackward: null - }); - } - - /** - * Move the selection forward `n` characters. - * - * @param {Number} n (optional) - * @return {Selection} selection - */ - - }, { - key: 'moveForward', - value: function moveForward() { - var n = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0]; - - return this.merge({ - anchorOffset: this.anchorOffset + n, - focusOffset: this.focusOffset + n - }); - } - - /** - * Move the selection backward `n` characters. - * - * @param {Number} n (optional) - * @return {Selection} selection - */ - - }, { - key: 'moveBackward', - value: function moveBackward() { - var n = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0]; - - return this.merge({ - anchorOffset: this.anchorOffset - n, - focusOffset: this.focusOffset - n - }); - } - - /** - * Move the selection to `anchor` and `focus` offsets. - * - * @param {Number} anchor - * @param {Number} focus (optional) - * @return {Selection} selection - */ - - }, { - key: 'moveToOffsets', - value: function moveToOffsets(anchor) { - var focus = arguments.length <= 1 || arguments[1] === undefined ? anchor : arguments[1]; - - return this.merge({ - anchorOffset: anchor, - focusOffset: focus, - isBackward: null - }); - } - - /** - * Extend the focus point forward `n` characters. - * - * @param {Number} n (optional) - * @return {Selection} selection - */ - - }, { - key: 'extendForward', - value: function extendForward() { - var n = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0]; - - return this.merge({ - focusOffset: this.focusOffset + n, - isBackward: null - }); - } - - /** - * Extend the focus point backward `n` characters. - * - * @param {Number} n (optional) - * @return {Selection} selection - */ - - }, { - key: 'extendBackward', - value: function extendBackward() { - var n = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0]; - - return this.merge({ - focusOffset: this.focusOffset - n, - isBackward: null - }); - } - - /** - * Extend the focus point to the start of a `node`. - * - * @param {Node} node - * @return {Selection} selection - */ - - }, { - key: 'extendToStartOf', - value: function extendToStartOf(node) { - return this.merge({ - focusKey: node.key, - focusOffset: 0, - isBackward: null - }); - } - - /** - * Extend the focus point to the end of a `node`. - * - * @param {Node} node - * @return {Selection} selection - */ - - }, { - key: 'extendToEndOf', - value: function extendToEndOf(node) { - return this.merge({ - focusKey: node.key, - focusOffset: node.length, - isBackward: null - }); - } - }, { - key: 'kind', - - - /** - * Get the kind. - * - * @return {String} kind - */ - - get: function get() { - return 'selection'; - } - - /** - * Get whether the selection is blurred. - * - * @return {Boolean} isBlurred - */ - - }, { - key: 'isBlurred', - get: function get() { - return !this.isFocused; - } - - /** - * Get whether the selection is collapsed. - * - * @return {Boolean} isCollapsed - */ - - }, { - key: 'isCollapsed', - get: function get() { - return this.anchorKey == this.focusKey && this.anchorOffset == this.focusOffset; - } - - /** - * Get whether the selection is expanded. - * - * @return {Boolean} isExpanded - */ - - }, { - key: 'isExpanded', - get: function get() { - return !this.isCollapsed; - } - - /** - * Get whether the selection is forward. - * - * @return {Boolean} isForward - */ - - }, { - key: 'isForward', - get: function get() { - return this.isBackward == null ? null : !this.isBackward; - } - - /** - * Get the start key. - * - * @return {String} startKey - */ - - }, { - key: 'startKey', - get: function get() { - return this.isBackward ? this.focusKey : this.anchorKey; - } - }, { - key: 'startOffset', - get: function get() { - return this.isBackward ? this.focusOffset : this.anchorOffset; - } - }, { - key: 'endKey', - get: function get() { - return this.isBackward ? this.anchorKey : this.focusKey; - } - }, { - key: 'endOffset', - get: function get() { - return this.isBackward ? this.anchorOffset : this.focusOffset; - } - }], [{ - key: 'create', - - - /** - * Create a new `Selection` with `properties`. - * - * @param {Object} properties - * @return {Selection} selection - */ - - value: function create() { - var properties = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - if (properties instanceof Selection) return properties; - return new Selection(properties); - } - }]); - - return Selection; -}(new _immutable.Record(DEFAULTS)); - -/** - * Add start, end and edge convenience methods. - */ - -START_END_METHODS.concat(EDGE_METHODS).forEach(function (pattern) { - var _pattern$split = pattern.split('%'); - - var _pattern$split2 = _slicedToArray(_pattern$split, 2); - - var p = _pattern$split2[0]; - var s = _pattern$split2[1]; - - var anchor = p + 'Anchor' + s; - var edge = p + 'Edge' + s; - var end = p + 'End' + s; - var focus = p + 'Focus' + s; - var start = p + 'Start' + s; - - Selection.prototype[start] = function () { - return this.isBackward ? this[focus].apply(this, arguments) : this[anchor].apply(this, arguments); - }; - - Selection.prototype[end] = function () { - return this.isBackward ? this[anchor].apply(this, arguments) : this[focus].apply(this, arguments); - }; - - if (!(0, _includes2.default)(EDGE_METHODS, pattern)) return; - - Selection.prototype[edge] = function () { - return this[anchor].apply(this, arguments) || this[focus].apply(this, arguments); - }; -}); - -/** - * Add edge methods. - */ - -/** - * Export. - */ - -exports.default = Selection; -},{"immutable":122,"lodash/includes":188}],16:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _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; }; - -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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _document = require('./document'); - -var _document2 = _interopRequireDefault(_document); - -var _mark = require('./mark'); - -var _mark2 = _interopRequireDefault(_mark); - -var _selection5 = require('./selection'); - -var _selection6 = _interopRequireDefault(_selection5); - -var _transform = require('./transform'); - -var _transform2 = _interopRequireDefault(_transform); - -var _uid = require('../utils/uid'); - -var _uid2 = _interopRequireDefault(_uid); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * History. - */ - -var History = new _immutable.Record({ - undos: new _immutable.Stack(), - redos: new _immutable.Stack() -}); - -/** - * Default properties. - */ - -var DEFAULTS = { - cursorMarks: null, - document: new _document2.default(), - selection: new _selection6.default(), - history: new History(), - isNative: false -}; - -/** - * State. - */ - -var State = function (_ref) { - _inherits(State, _ref); - - function State() { - _classCallCheck(this, State); - - return _possibleConstructorReturn(this, Object.getPrototypeOf(State).apply(this, arguments)); - } - - _createClass(State, [{ - key: 'transform', - - - /** - * Return a new `Transform` with the current state as a starting point. - * - * @return {Transform} transform - */ - - value: function transform() { - var state = this; - return new _transform2.default({ state: state }); - } - - /** - * Move the selection to the start of the previous block. - * - * @return {State} state - */ - - }, { - key: 'collapseToStartOfPreviousBlock', - value: function collapseToStartOfPreviousBlock() { - var state = this; - var _state = state; - var document = _state.document; - var selection = _state.selection; - - var blocks = document.getBlocksAtRange(selection); - var block = blocks.first(); - if (!block) return state; - - var previous = document.getPreviousBlock(block); - if (!previous) return state; - - selection = selection.collapseToStartOf(previous); - selection = selection.normalize(document); - state = state.merge({ selection: selection }); - return state; - } - - /** - * Move the selection to the end of the previous block. - * - * @return {State} state - */ - - }, { - key: 'collapseToEndOfPreviousBlock', - value: function collapseToEndOfPreviousBlock() { - var state = this; - var _state2 = state; - var document = _state2.document; - var selection = _state2.selection; - - var blocks = document.getBlocksAtRange(selection); - var block = blocks.first(); - if (!block) return state; - - var previous = document.getPreviousBlock(block); - if (!previous) return state; - - selection = selection.collapseToEndOf(previous); - selection = selection.normalize(document); - state = state.merge({ selection: selection }); - return state; - } - - /** - * Move the selection to the start of the next block. - * - * @return {State} state - */ - - }, { - key: 'collapseToStartOfNextBlock', - value: function collapseToStartOfNextBlock() { - var state = this; - var _state3 = state; - var document = _state3.document; - var selection = _state3.selection; - - var blocks = document.getBlocksAtRange(selection); - var block = blocks.last(); - if (!block) return state; - - var next = document.getNextBlock(block); - if (!next) return state; - - selection = selection.collapseToStartOf(next); - selection = selection.normalize(document); - state = state.merge({ selection: selection }); - return state; - } - - /** - * Move the selection to the end of the next block. - * - * @return {State} state - */ - - }, { - key: 'collapseToEndOfNextBlock', - value: function collapseToEndOfNextBlock() { - var state = this; - var _state4 = state; - var document = _state4.document; - var selection = _state4.selection; - - var blocks = document.getBlocksAtRange(selection); - var block = blocks.last(); - if (!block) return state; - - var next = document.getNextBlock(block); - if (!next) return state; - - selection = selection.collapseToEndOf(next); - selection = selection.normalize(document); - state = state.merge({ selection: selection }); - return state; - } - - /** - * Move the selection to the start of the previous text. - * - * @return {State} state - */ - - }, { - key: 'collapseToStartOfPreviousText', - value: function collapseToStartOfPreviousText() { - var state = this; - var _state5 = state; - var document = _state5.document; - var selection = _state5.selection; - - var texts = document.getTextsAtRange(selection); - var text = texts.first(); - if (!text) return state; - - var previous = document.getPreviousText(text); - if (!previous) return state; - - selection = selection.collapseToStartOf(previous); - selection = selection.normalize(document); - state = state.merge({ selection: selection }); - return state; - } - - /** - * Move the selection to the end of the previous text. - * - * @return {State} state - */ - - }, { - key: 'collapseToEndOfPreviousText', - value: function collapseToEndOfPreviousText() { - var state = this; - var _state6 = state; - var document = _state6.document; - var selection = _state6.selection; - - var texts = document.getTextsAtRange(selection); - var text = texts.first(); - if (!text) return state; - - var previous = document.getPreviousText(text); - if (!previous) return state; - - selection = selection.collapseToEndOf(previous); - selection = selection.normalize(document); - state = state.merge({ selection: selection }); - return state; - } - - /** - * Move the selection to the start of the next text. - * - * @return {State} state - */ - - }, { - key: 'collapseToStartOfNextText', - value: function collapseToStartOfNextText() { - var state = this; - var _state7 = state; - var document = _state7.document; - var selection = _state7.selection; - - var texts = document.getTextsAtRange(selection); - var text = texts.last(); - if (!text) return state; - - var next = document.getNextText(text); - if (!next) return state; - - selection = selection.collapseToStartOf(next); - selection = selection.normalize(document); - state = state.merge({ selection: selection }); - return state; - } - - /** - * Move the selection to the end of the next text. - * - * @return {State} state - */ - - }, { - key: 'collapseToEndOfNextText', - value: function collapseToEndOfNextText() { - var state = this; - var _state8 = state; - var document = _state8.document; - var selection = _state8.selection; - - var texts = document.getTextsAtRange(selection); - var text = texts.last(); - if (!text) return state; - - var next = document.getNextText(text); - if (!next) return state; - - selection = selection.collapseToEndOf(next); - selection = selection.normalize(document); - state = state.merge({ selection: selection }); - return state; - } - - /** - * Delete at the current selection. - * - * @return {State} state - */ - - }, { - key: 'delete', - value: function _delete() { - var state = this; - var _state9 = state; - var document = _state9.document; - var selection = _state9.selection; - - // When collapsed, there's nothing to do. - - if (selection.isCollapsed) return state; - - // Otherwise, delete and update the selection. - document = document.deleteAtRange(selection); - selection = selection.collapseToStart(); - state = state.merge({ document: document, selection: selection }); - return state; - } - - /** - * Delete backward `n` characters at the current selection. - * - * @param {Number} n (optional) - * @return {State} state - */ - - }, { - key: 'deleteBackward', - value: function deleteBackward() { - var n = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0]; - - var state = this; - var _state10 = state; - var document = _state10.document; - var selection = _state10.selection; - - var after = selection; - - // Determine what the selection should be after deleting. - var _selection = selection; - var startKey = _selection.startKey; - - var startNode = document.getDescendant(startKey); - - if (selection.isExpanded) { - after = selection.collapseToStart(); - } else if (selection.isAtStartOf(document)) { - after = selection; - } else if (selection.isAtStartOf(startNode)) { - var previous = document.getPreviousText(startNode); - var prevBlock = document.getClosestBlock(previous); - var prevInline = document.getClosestInline(previous); - - if (prevBlock && prevBlock.isVoid) { - after = selection; - } else if (prevInline && prevInline.isVoid) { - after = selection; - } else { - after = selection.collapseToEndOf(previous); - } - } else { - after = selection.moveBackward(n); - } - - // Delete backward and then update the selection. - document = document.deleteBackwardAtRange(selection, n); - selection = after; - state = state.merge({ document: document, selection: selection }); - return state; - } - - /** - * Delete forward `n` characters at the current selection. - * - * @param {Number} n (optional) - * @return {State} state - */ - - }, { - key: 'deleteForward', - value: function deleteForward() { - var n = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0]; - - var state = this; - var _state11 = state; - var document = _state11.document; - var selection = _state11.selection; - var _selection2 = selection; - var startKey = _selection2.startKey; - - var after = selection; - - // Determine what the selection should be after deleting. - var block = document.getClosestBlock(startKey); - var inline = document.getClosestInline(startKey); - - if (selection.isExpanded) { - after = selection.collapseToStart(); - } else if (block && block.isVoid || inline && inline.isVoid) { - var next = document.getNextText(startKey); - var previous = document.getPreviousText(startKey); - after = next ? selection.collapseToStartOf(next) : selection.collapseToEndOf(previous); - } - - // Delete forward and then update the selection. - document = document.deleteForwardAtRange(selection, n); - selection = after; - state = state.merge({ document: document, selection: selection }); - return state; - } - - /** - * Insert a `fragment` at the current selection. - * - * @param {List} fragment - * @return {State} state - */ - - }, { - key: 'insertFragment', - value: function insertFragment(fragment) { - var state = this; - var _state12 = state; - var document = _state12.document; - var selection = _state12.selection; - - var after = selection; - - // If there's nothing in the fragment, do nothing. - if (!fragment.length) return state; - - // Lookup some nodes for determining the selection next. - var texts = fragment.getTextNodes(); - var lastText = texts.last(); - var lastInline = fragment.getClosestInline(lastText); - var startText = document.getDescendant(selection.startKey); - var startBlock = document.getClosestBlock(startText); - var startInline = document.getClosestInline(startText); - var nextText = document.getNextText(startText); - var nextBlock = nextText ? document.getClosestBlock(nextText) : null; - var nextNextText = nextText ? document.getNextText(nextText) : null; - - var docTexts = document.getTextNodes(); - - // Insert the fragment. - document = document.insertFragmentAtRange(selection, fragment); - - // Determine what the selection should be after inserting. - var keys = docTexts.map(function (text) { - return text.key; - }); - var text = document.getTextNodes().findLast(function (n) { - return !keys.includes(n.key); - }); - - after = text ? selection.collapseToStartOf(text).moveForward(lastText.length) : selection.collapseToStart().moveForward(lastText.length); - - // Update the document and selection. - selection = after; - state = state.merge({ document: document, selection: selection }); - return state; - } - - /** - * Insert a `text` string at the current selection. - * - * @param {String} text - * @return {State} state - */ - - }, { - key: 'insertText', - value: function insertText(text) { - var state = this; - var _state13 = state; - var cursorMarks = _state13.cursorMarks; - var document = _state13.document; - var selection = _state13.selection; - - var after = selection; - - // Determine what the selection should be after inserting. - if (selection.isExpanded) { - after = selection.collapseToStart().moveForward(text.length); - } else { - after = selection.moveForward(text.length); - } - - // Insert the text and update the selection. - document = document.insertTextAtRange(selection, text, cursorMarks); - selection = after; - state = state.merge({ document: document, selection: selection }); - return state; - } - - /** - * Add a `mark` to the characters in the current selection. - * - * @param {Mark} mark - * @return {State} state - */ - - }, { - key: 'addMark', - value: function addMark(mark) { - var state = this; - var _state14 = state; - var cursorMarks = _state14.cursorMarks; - var document = _state14.document; - var selection = _state14.selection; - - // If the selection is collapsed, add the mark to the cursor instead. - - if (selection.isCollapsed) { - if (typeof mark == 'string') mark = new _mark2.default({ type: mark }); - var marks = document.getMarksAtRange(selection); - state = state.merge({ cursorMarks: marks.add(mark) }); - return state; - } - - document = document.addMarkAtRange(selection, mark); - state = state.merge({ document: document }); - return state; - } - - /** - * Move the selection to a specific anchor and focus point. - * - * @param {Object} properties - * @return {State} state - */ - - }, { - key: 'moveTo', - value: function moveTo(properties) { - var state = this; - var _state15 = state; - var document = _state15.document; - var selection = _state15.selection; - - // Pass in properties, and force `isBackward` to be re-resolved. - - selection = selection.merge(_extends({}, properties, { - isBackward: null - })); - - selection = selection.normalize(document); - state = state.merge({ selection: selection }); - return state; - } - - /** - * Set `properties` of the block nodes in the current selection. - * - * @param {Object} properties - * @return {State} state - */ - - }, { - key: 'setBlock', - value: function setBlock(properties) { - var state = this; - var _state16 = state; - var document = _state16.document; - var selection = _state16.selection; - - document = document.setBlockAtRange(selection, properties); - state = state.merge({ document: document }); - return state; - } - - /** - * Set `properties` of the inline nodes in the current selection. - * - * @param {Object} properties - * @return {State} state - */ - - }, { - key: 'setInline', - value: function setInline(properties) { - var state = this; - var _state17 = state; - var document = _state17.document; - var selection = _state17.selection; - - document = document.setInlineAtRange(selection, properties); - state = state.merge({ document: document }); - return state; - } - - /** - * Split the block node at the current selection. - * - * @return {State} state - */ - - }, { - key: 'splitBlock', - value: function splitBlock() { - var state = this; - var _state18 = state; - var document = _state18.document; - var selection = _state18.selection; - - // Split the document. - - document = document.splitBlockAtRange(selection); - - // Determine what the selection should be after splitting. - var _selection3 = selection; - var startKey = _selection3.startKey; - - var startNode = document.getDescendant(startKey); - var nextNode = document.getNextText(startNode); - selection = selection.collapseToStartOf(nextNode); - - state = state.merge({ document: document, selection: selection }); - return state; - } - - /** - * Split the inline nodes at the current selection. - * - * @return {State} state - */ - - }, { - key: 'splitInline', - value: function splitInline() { - var state = this; - var _state19 = state; - var document = _state19.document; - var selection = _state19.selection; - - // Split the document. - - document = document.splitInlineAtRange(selection); - - // Determine what the selection should be after splitting. - var _selection4 = selection; - var startKey = _selection4.startKey; - - var inlineParent = document.getClosestInline(startKey); - - if (inlineParent) { - var startNode = document.getDescendant(startKey); - var nextNode = document.getNextText(startNode); - selection = selection.collapseToStartOf(nextNode); - } - - state = state.merge({ document: document, selection: selection }); - return state; - } - - /** - * Remove a `mark` from the characters in the current selection. - * - * @param {Mark} mark - * @return {State} state - */ - - }, { - key: 'removeMark', - value: function removeMark(mark) { - var state = this; - var _state20 = state; - var cursorMarks = _state20.cursorMarks; - var document = _state20.document; - var selection = _state20.selection; - - // If the selection is collapsed, remove the mark from the cursor instead. - - if (selection.isCollapsed) { - if (typeof mark == 'string') mark = new _mark2.default({ type: mark }); - var marks = document.getMarksAtRange(selection); - state = state.merge({ cursorMarks: marks.remove(mark) }); - return state; - } - - document = document.removeMarkAtRange(selection, mark); - state = state.merge({ document: document }); - return state; - } - - /** - * Wrap the block nodes in the current selection in new nodes of `type`. - * - * @param {String} type - * @param {Data} data (optional) - * @return {State} state - */ - - }, { - key: 'wrapBlock', - value: function wrapBlock(type, data) { - var state = this; - var _state21 = state; - var document = _state21.document; - var selection = _state21.selection; - - document = document.wrapBlockAtRange(selection, type, data); - state = state.merge({ document: document }); - return state; - } - - /** - * Unwrap the current selection from a block parent of `type`. - * - * @param {String} type (optional) - * @param {Data} data (optional) - * @return {State} state - */ - - }, { - key: 'unwrapBlock', - value: function unwrapBlock(type, data) { - var state = this; - var _state22 = state; - var document = _state22.document; - var selection = _state22.selection; - - document = document.unwrapBlockAtRange(selection, type, data); - state = state.merge({ document: document, selection: selection }); - return state; - } - - /** - * Wrap the current selection in new inline nodes of `type`. - * - * @param {String} type - * @param {Data} data (optional) - * @return {State} state - */ - - }, { - key: 'wrapInline', - value: function wrapInline(type, data) { - var state = this; - var _state23 = state; - var document = _state23.document; - var selection = _state23.selection; - - document = document.wrapInlineAtRange(selection, type, data); - - // Determine what the selection should be after wrapping. - if (selection.isCollapsed) { - selection = selection; - } else if (selection.startOffset == 0) { - var text = document.getDescendant(selection.startKey); - selection = selection.moveToRangeOf(text); - selection = selection.normalize(document); - } else { - var _text = document.getNextText(selection.startKey); - selection = selection.moveToRangeOf(_text); - selection = selection.normalize(document); - } - - state = state.merge({ document: document, selection: selection }); - return state; - } - - /** - * Unwrap the current selection from an inline parent of `type`. - * - * @param {String} type (optional) - * @param {Data} data (optional) - * @return {State} state - */ - - }, { - key: 'unwrapInline', - value: function unwrapInline(type, data) { - var state = this; - var _state24 = state; - var document = _state24.document; - var selection = _state24.selection; - - document = document.unwrapInlineAtRange(selection, type, data); - state = state.merge({ document: document, selection: selection }); - return state; - } - }, { - key: 'kind', - - - /** - * Get the kind. - * - * @return {String} kind - */ - - get: function get() { - return 'state'; - } - - /** - * Is the current selection blurred? - * - * @return {Boolean} isBlurred - */ - - }, { - key: 'isBlurred', - get: function get() { - return this.selection.isBlurred; - } - - /** - * Is the current selection focused? - * - * @return {Boolean} isFocused - */ - - }, { - key: 'isFocused', - get: function get() { - return this.selection.isFocused; - } - - /** - * Is the current selection collapsed? - * - * @return {Boolean} isCollapsed - */ - - }, { - key: 'isCollapsed', - get: function get() { - return this.selection.isCollapsed; - } - - /** - * Is the current selection expanded? - * - * @return {Boolean} isExpanded - */ - - }, { - key: 'isExpanded', - get: function get() { - return this.selection.isExpanded; - } - - /** - * Is the current selection backward? - * - * @return {Boolean} isBackward - */ - - }, { - key: 'isBackward', - get: function get() { - return this.selection.isBackward; - } - - /** - * Is the current selection forward? - * - * @return {Boolean} isForward - */ - - }, { - key: 'isForward', - get: function get() { - return this.selection.isForward; - } - - /** - * Get the current start key. - * - * @return {String} startKey - */ - - }, { - key: 'startKey', - get: function get() { - return this.selection.startKey; - } - - /** - * Get the current end key. - * - * @return {String} endKey - */ - - }, { - key: 'endKey', - get: function get() { - return this.selection.endKey; - } - - /** - * Get the current start offset. - * - * @return {String} startOffset - */ - - }, { - key: 'startOffset', - get: function get() { - return this.selection.startOffset; - } - - /** - * Get the current end offset. - * - * @return {String} endOffset - */ - - }, { - key: 'endOffset', - get: function get() { - return this.selection.endOffset; - } - - /** - * Get the current anchor key. - * - * @return {String} anchorKey - */ - - }, { - key: 'anchorKey', - get: function get() { - return this.selection.anchorKey; - } - - /** - * Get the current focus key. - * - * @return {String} focusKey - */ - - }, { - key: 'focusKey', - get: function get() { - return this.selection.focusKey; - } - - /** - * Get the current anchor offset. - * - * @return {String} anchorOffset - */ - - }, { - key: 'anchorOffset', - get: function get() { - return this.selection.anchorOffset; - } - - /** - * Get the current focus offset. - * - * @return {String} focusOffset - */ - - }, { - key: 'focusOffset', - get: function get() { - return this.selection.focusOffset; - } - - /** - * Get the current start text node. - * - * @return {Text} text - */ - - }, { - key: 'startText', - get: function get() { - return this.document.getDescendant(this.selection.startKey); - } - - /** - * Get the current end node. - * - * @return {Text} text - */ - - }, { - key: 'endText', - get: function get() { - return this.document.getDescendant(this.selection.endKey); - } - - /** - * Get the current anchor node. - * - * @return {Text} text - */ - - }, { - key: 'anchorText', - get: function get() { - return this.document.getDescendant(this.selection.anchorKey); - } - - /** - * Get the current focus node. - * - * @return {Text} text - */ - - }, { - key: 'focusText', - get: function get() { - return this.document.getDescendant(this.selection.focusKey); - } - - /** - * Get the current start text node's closest block parent. - * - * @return {Block} block - */ - - }, { - key: 'startBlock', - get: function get() { - return this.document.getClosestBlock(this.selection.startKey); - } - - /** - * Get the current end text node's closest block parent. - * - * @return {Block} block - */ - - }, { - key: 'endBlock', - get: function get() { - return this.document.getClosestBlock(this.selection.endKey); - } - - /** - * Get the current anchor text node's closest block parent. - * - * @return {Block} block - */ - - }, { - key: 'anchorBlock', - get: function get() { - return this.document.getClosestBlock(this.selection.anchorKey); - } - - /** - * Get the current focus text node's closest block parent. - * - * @return {Block} block - */ - - }, { - key: 'focusBlock', - get: function get() { - return this.document.getClosestBlock(this.selection.focusKey); - } - - /** - * Get the characters in the current selection. - * - * @return {List} characters - */ - - }, { - key: 'characters', - get: function get() { - return this.document.getCharactersAtRange(this.selection); - } - - /** - * Get the marks of the current selection. - * - * @return {Set} marks - */ - - }, { - key: 'marks', - get: function get() { - return this.cursorMarks || this.document.getMarksAtRange(this.selection); - } - - /** - * Get the block nodes in the current selection. - * - * @return {List} nodes - */ - - }, { - key: 'blocks', - get: function get() { - return this.document.getBlocksAtRange(this.selection); - } - - /** - * Get the fragment of the current selection. - * - * @return {List} nodes - */ - - }, { - key: 'fragment', - get: function get() { - return this.document.getFragmentAtRange(this.selection); - } - - /** - * Get the inline nodes in the current selection. - * - * @return {List} nodes - */ - - }, { - key: 'inlines', - get: function get() { - return this.document.getInlinesAtRange(this.selection); - } - - /** - * Get the text nodes in the current selection. - * - * @return {List} nodes - */ - - }, { - key: 'texts', - get: function get() { - return this.document.getTextsAtRange(this.selection); - } - }], [{ - key: 'create', - - - /** - * Create a new `State` with `properties`. - * - * @param {Object} properties - * @return {State} state - */ - - value: function create() { - var properties = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - if (properties instanceof State) return properties; - properties.document = _document2.default.create(properties.document); - properties.selection = _selection6.default.create(properties.selection).normalize(properties.document); - return new State(properties); - } - }]); - - return State; -}(new _immutable.Record(DEFAULTS)); - -/** - * Export. - */ - -exports.default = State; -},{"../utils/uid":30,"./document":11,"./mark":13,"./selection":15,"./transform":18,"immutable":122}],17:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _character = require('./character'); - -var _character2 = _interopRequireDefault(_character); - -var _mark = require('./mark'); - -var _mark2 = _interopRequireDefault(_mark); - -var _uid = require('../utils/uid'); - -var _uid2 = _interopRequireDefault(_uid); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * Default properties. - */ - -var DEFAULTS = { - characters: new _immutable.List(), - decorations: null, - key: null, - cache: null -}; - -/** - * Text. - */ - -var Text = function (_ref) { - _inherits(Text, _ref); - - function Text() { - _classCallCheck(this, Text); - - return _possibleConstructorReturn(this, Object.getPrototypeOf(Text).apply(this, arguments)); - } - - _createClass(Text, [{ - key: 'decorateCharacters', - - - /** - * Decorate the text node's characters with a `decorator` function. - * - * @param {Function} decorator - * @return {Text} text - */ - - value: function decorateCharacters(decorator) { - var characters = this.characters; - var cache = this.cache; - - if (characters == cache) return this; - - var decorations = decorator(this); - if (decorations == characters) return this; - - return this.merge({ - cache: characters, - decorations: decorations - }); - } - - /** - * Remove characters from the text node from `start` to `end`. - * - * @param {Number} start - * @param {Number} end - * @return {Text} text - */ - - }, { - key: 'removeCharacters', - value: function removeCharacters(start, end) { - var characters = this.characters; - - - characters = characters.filterNot(function (char, i) { - return start <= i && i < end; - }); - - return this.merge({ characters: characters }); - } - - /** - * Insert text `string` at `index`. - * - * @param {Numbder} index - * @param {String} string - * @param {String} marks (optional) - * @return {Text} text - */ - - }, { - key: 'insertText', - value: function insertText(index, string, marks) { - var characters = this.characters; - - - if (!marks) { - var prev = index ? characters.get(index - 1) : null; - marks = prev ? prev.marks : _mark2.default.createSet(); - } - - var chars = _character2.default.createList(string.split('').map(function (char) { - return { - text: char, - marks: marks - }; - })); - - characters = characters.slice(0, index).concat(chars).concat(characters.slice(index)); - - return this.merge({ characters: characters }); - } - }, { - key: 'kind', - - - /** - * Get the node's kind. - * - * @return {String} kind - */ - - get: function get() { - return 'text'; - } - - /** - * Get the length of the concatenated text of the node. - * - * @return {Number} length - */ - - }, { - key: 'length', - get: function get() { - return this.text.length; - } - - /** - * Get the concatenated text of the node. - * - * @return {String} text - */ - - }, { - key: 'text', - get: function get() { - return this.characters.map(function (char) { - return char.text; - }).join(''); - } - }], [{ - key: 'create', - - - /** - * Create a new `Text` with `properties`. - * - * @param {Object} properties - * @return {Text} text - */ - - value: function create() { - var properties = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - if (properties instanceof Text) return properties; - properties.key = (0, _uid2.default)(4); - properties.characters = _character2.default.createList(properties.characters); - properties.decorations = null; - properties.cache = null; - return new Text(properties); - } - - /** - * Create a list of `Texts` from an array. - * - * @param {Array} elements - * @return {List} map - */ - - }, { - key: 'createList', - value: function createList() { - var elements = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; - - if (_immutable.List.isList(elements)) return elements; - return new _immutable.List(elements.map(Text.create)); - } - }]); - - return Text; -}(new _immutable.Record(DEFAULTS)); - -/** - * Export. - */ - -exports.default = Text; -},{"../utils/uid":30,"./character":9,"./mark":13,"immutable":122}],18:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _includes = require('lodash/includes'); - -var _includes2 = _interopRequireDefault(_includes); - -var _xor = require('lodash/xor'); - -var _xor2 = _interopRequireDefault(_xor); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _toConsumableArray(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); } } - -function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * Snapshot, with a state-like shape. - */ - -var Snapshot = new _immutable.Record({ - document: null, - selection: null, - steps: new _immutable.List() -}); - -/** - * Step. - */ - -var Step = new _immutable.Record({ - type: null, - args: null -}); - -/** - * Document transforms. - */ - -var DOCUMENT_TRANSFORMS = ['deleteAtRange', 'deleteBackwardAtRange', 'deleteForwardAtRange', 'insertFragmentAtRange', 'insertTextAtRange', 'addMarkAtRange', 'setBlockAtRange', 'setInlineAtRange', 'splitBlockAtRange', 'splitInlineAtRange', 'removeMarkAtRange', 'unwrapBlockAtRange', 'unwrapInlineAtRange', 'wrapBlockAtRange', 'wrapInlineAtRange']; - -/** - * Selection transforms. - */ - -var SELECTION_TRANSFORMS = ['blur', 'collapseToAnchor', 'collapseToEnd', 'collapseToEndOf', 'collapseToFocus', 'collapseToStart', 'collapseToStartOf', 'extendBackward', 'extendForward', 'extendToEndOf', 'extendToStartOf', 'focus', 'moveBackward', 'moveForward', 'moveToOffsets', 'moveToRangeOf']; - -/** - * State-level document transforms. - */ - -var STATE_DOCUMENT_TRANSFORMS = ['delete', 'deleteBackward', 'deleteForward', 'insertFragment', 'insertText', 'addMark', 'setBlock', 'setInline', 'splitBlock', 'splitInline', 'removeMark', 'unwrapBlock', 'unwrapInline', 'wrapBlock', 'wrapInline']; - -/** - * State selection transforms. - */ - -var STATE_SELECTION_TRANSFORMS = ['collapseToEndOfNextBlock', 'collapseToEndOfNextText', 'collapseToEndOfPreviousBlock', 'collapseToEndOfPreviousText', 'collapseToStartOfNextBlock', 'collapseToStartOfNextText', 'collapseToStartOfPreviousBlock', 'collapseToStartOfPreviousText', 'moveTo']; - -/** - * All state-level transforms. - */ - -var STATE_TRANSFORMS = [].concat(STATE_DOCUMENT_TRANSFORMS).concat(STATE_SELECTION_TRANSFORMS); - -/** - * All transforms. - */ - -var TRANSFORMS = [].concat(DOCUMENT_TRANSFORMS).concat(SELECTION_TRANSFORMS).concat(STATE_TRANSFORMS); - -/** - * Defaults. - */ - -var DEFAULT_PROPERTIES = { - state: null, - steps: new _immutable.List() -}; - -/** - * Transform. - */ - -var Transform = function (_ref) { - _inherits(Transform, _ref); - - function Transform() { - _classCallCheck(this, Transform); - - return _possibleConstructorReturn(this, Object.getPrototypeOf(Transform).apply(this, arguments)); - } - - _createClass(Transform, [{ - key: 'apply', - - - /** - * Apply the transform and return the new state. - * - * @param {Object} options - * @property {Boolean} isNative - * @property {Boolean} snapshot - * @return {State} state - */ - - value: function apply() { - var _this2 = this; - - var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - var transform = this; - var state = transform.state; - var steps = transform.steps; - var _state = state; - var cursorMarks = _state.cursorMarks; - var history = _state.history; - var selection = _state.selection; - var _history = history; - var undos = _history.undos; - var redos = _history.redos; - - // Determine whether we need to create a new snapshot. - - var shouldSnapshot = options.snapshot == null ? this.shouldSnapshot() : options.snapshot; - - // If we should, save a snapshot into the history before transforming. - if (shouldSnapshot) { - var snapshot = transform.snapshot(); - undos = undos.push(snapshot); - if (undos.size > 100) undos = undos.take(100); - redos = redos.clear(); - history = history.merge({ undos: undos, redos: redos }); - state = state.merge({ history: history }); - } - - // Apply each of the steps in the transform, arriving at a new state. - state = steps.reduce(function (memo, step) { - return _this2.applyStep(memo, step); - }, state); - - // If the selection has changed, clear any existing cursor marks. - if (state.selection != selection) { - state = state.merge({ - cursorMarks: null - }); - } - - // Apply the "isNative" flag, which is used to allow for natively-handled - // content changes to skip rerendering the editor for performance. - state = state.merge({ - isNative: !!options.isNative - }); - - return state; - } - - /** - * Apply a single `step` to a `state`, differentiating between types. - * - * @param {State} state - * @param {Step} step - * @return {State} state - */ - - }, { - key: 'applyStep', - value: function applyStep(state, step) { - var type = step.type; - var args = step.args; - - - if ((0, _includes2.default)(DOCUMENT_TRANSFORMS, type)) { - var _document; - - var _state2 = state; - var document = _state2.document; - var selection = _state2.selection; - - var _args = _toArray(args); - - var range = _args[0]; - - var rest = _args.slice(1); - - range = range.normalize(document); - document = (_document = document)[type].apply(_document, [range].concat(_toConsumableArray(rest))); - selection = selection.normalize(document); - state = state.merge({ document: document, selection: selection }); - return state; - } else if ((0, _includes2.default)(SELECTION_TRANSFORMS, type)) { - var _selection2; - - var _state3 = state; - var _document2 = _state3.document; - var _selection = _state3.selection; - - _selection = (_selection2 = _selection)[type].apply(_selection2, _toConsumableArray(args)); - _selection = _selection.normalize(_document2); - state = state.merge({ selection: _selection }); - return state; - } else if ((0, _includes2.default)(STATE_TRANSFORMS, type)) { - var _state4; - - state = (_state4 = state)[type].apply(_state4, _toConsumableArray(args)); - return state; - } - } - - /** - * Check whether the current transform steps should create a snapshot. - * - * @return {Boolean} - */ - - }, { - key: 'shouldSnapshot', - value: function shouldSnapshot() { - var transform = this; - var state = transform.state; - var steps = transform.steps; - var cursorMarks = state.cursorMarks; - var history = state.history; - var selection = state.selection; - var undos = history.undos; - var redos = history.redos; - - var previous = undos.peek(); - - // If the only steps applied are selection transforms, don't snapshot. - var onlySelections = steps.every(function (step) { - return (0, _includes2.default)(SELECTION_TRANSFORMS, step.type) || (0, _includes2.default)(STATE_SELECTION_TRANSFORMS, step.type); - }); - - if (onlySelections) return false; - - // If there isn't a previous state, snapshot. - if (!previous) return true; - - // If there is a previous state but the steps are different, snapshot. - var types = steps.map(function (step) { - return step.type; - }); - var prevTypes = previous.steps.map(function (step) { - return step.type; - }); - var diff = (0, _xor2.default)(types.toArray(), prevTypes.toArray()); - if (diff.length) return true; - - // If the current steps aren't one of the "combinable" types, snapshot. - var allCombinable = steps.every(function (step) { - return step.type == 'insertText'; - }) || steps.every(function (step) { - return step.type == 'deleteForward'; - }) || steps.every(function (step) { - return step.type == 'deleteBackward'; - }); - - if (!allCombinable) return true; - - // Otherwise, don't snapshot. - return false; - } - - /** - * Create a history-ready snapshot of the current state. - * - * @return {Snapshot} snapshot - */ - - }, { - key: 'snapshot', - value: function snapshot() { - var state = this.state; - var steps = this.steps; - var document = state.document; - var selection = state.selection; - - return new Snapshot({ document: document, selection: selection, steps: steps }); - } - - /** - * Undo to the previous state in the history. - * - * @return {State} state - */ - - }, { - key: 'undo', - value: function undo() { - var transform = this; - var state = transform.state; - var _state5 = state; - var history = _state5.history; - var _history2 = history; - var undos = _history2.undos; - var redos = _history2.redos; - - // If there's no previous snapshot, return the current state. - - var previous = undos.peek(); - if (!previous) return state; - - // Remove the previous snapshot from the undo stack. - undos = undos.pop(); - - // Snapshot the current state, and move it into the redos stack. - var snapshot = transform.snapshot(); - redos = redos.push(snapshot); - - // Return the previous state, with the updated history. - var document = previous.document; - var selection = previous.selection; - - history = history.merge({ undos: undos, redos: redos }); - state = state.merge({ document: document, selection: selection, history: history }); - return state; - } - - /** - * Redo to the next state in the history. - * - * @return {State} state - */ - - }, { - key: 'redo', - value: function redo() { - var transform = this; - var state = transform.state; - var _state6 = state; - var history = _state6.history; - var _history3 = history; - var undos = _history3.undos; - var redos = _history3.redos; - - // If there's no next snapshot, return the current state. - - var next = redos.peek(); - if (!next) return state; - - // Remove the next history from the redo stack. - redos = redos.pop(); - - // Snapshot the current state, and move it into the undos stack. - var snapshot = transform.snapshot(); - undos = undos.push(snapshot); - - // Return the next state, with the updated history. - var document = next.document; - var selection = next.selection; - - history = history.merge({ undos: undos, redos: redos }); - state = state.merge({ document: document, selection: selection, history: history }); - return state; - } - }, { - key: 'kind', - - - /** - * Get the kind. - * - * @return {String} kind - */ - - get: function get() { - return 'transform'; - } - }]); - - return Transform; -}(new _immutable.Record(DEFAULT_PROPERTIES)); - -/** - * Add a step-creating method for each of the transforms. - */ - -TRANSFORMS.forEach(function (type) { - Transform.prototype[type] = function () { - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - var transform = this; - var _transform = transform; - var steps = _transform.steps; - - steps = steps.push(new Step({ type: type, args: args })); - transform = transform.merge({ steps: steps }); - return transform; - }; -}); - -/** - * Export. - */ - -exports.default = Transform; -},{"immutable":122,"lodash/includes":188,"lodash/xor":207}],19:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; - -var _block = require('./block'); - -var _block2 = _interopRequireDefault(_block); - -var _character = require('./character'); - -var _character2 = _interopRequireDefault(_character); - -var _data = require('./data'); - -var _data2 = _interopRequireDefault(_data); - -var _document = require('./document'); - -var _document2 = _interopRequireDefault(_document); - -var _inline = require('./inline'); - -var _inline2 = _interopRequireDefault(_inline); - -var _mark = require('./mark'); - -var _mark2 = _interopRequireDefault(_mark); - -var _selection = require('./selection'); - -var _selection2 = _interopRequireDefault(_selection); - -var _text = require('./text'); - -var _text2 = _interopRequireDefault(_text); - -var _uid = require('../utils/uid'); - -var _uid2 = _interopRequireDefault(_uid); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * Transforms. - * - * These are pulled out into their own file because they can get complex. - */ - -var Transforms = { - - /** - * Delete everything in a `range`. - * - * @param {Selection} range - * @return {Node} node - */ - - deleteAtRange: function deleteAtRange(range) { - if (range.isCollapsed) return this; - - var node = this; - - // Make sure the children exist. - var startKey = range.startKey; - var startOffset = range.startOffset; - var endKey = range.endKey; - var endOffset = range.endOffset; - - node.assertHasDescendant(startKey); - node.assertHasDescendant(endKey); - - // If the start and end nodes are the same, just remove characters. - if (startKey == endKey) { - var text = node.getDescendant(startKey); - text = text.removeCharacters(startOffset, endOffset); - node = node.updateDescendant(text); - return node; - } - - // Split the blocks and determine the edge boundaries. - var start = range.collapseToStart(); - var end = range.collapseToEnd(); - node = node.splitBlockAtRange(start, Infinity); - node = node.splitBlockAtRange(end, Infinity); - - var startText = node.getDescendant(startKey); - var startEdgeText = node.getNextText(startKey); - - var endText = node.getNextText(endKey); - var endEdgeText = node.getDescendant(endKey); - - // Remove the new blocks inside the edges. - var startEdgeBlock = node.getFurthestBlock(startEdgeText); - var endEdgeBlock = node.getFurthestBlock(endEdgeText); - - var nodes = node.nodes.takeUntil(function (n) { - return n == startEdgeBlock; - }).concat(node.nodes.skipUntil(function (n) { - return n == endEdgeBlock; - }).rest()); - - node = node.merge({ nodes: nodes }); - - // Take the end edge's split text and move it to the start edge. - var startBlock = node.getFurthestBlock(startText); - var endChild = node.getFurthestInline(endText) || endText; - - var startNodes = startBlock.nodes.push(endChild); - startBlock = startBlock.merge({ nodes: startNodes }); - node = node.updateDescendant(startBlock); - - // While the end child is an only child, remove the block it's in. - var endParent = node.getClosestBlock(endChild); - - while (endParent && endParent.nodes.size == 1) { - endChild = endParent; - endParent = node.getClosestBlock(endParent); - } - - node = node.removeDescendant(endChild); - - // Normalize the adjacent text nodes. - return node.normalize(); - }, - - - /** - * Delete backward `n` characters at a `range`. - * - * @param {Selection} range - * @param {Number} n (optional) - * @return {Node} node - */ - - deleteBackwardAtRange: function deleteBackwardAtRange(range) { - var n = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1]; - - var node = this; - var _range = range; - var startKey = _range.startKey; - var startOffset = _range.startOffset; - - // When the range is still expanded, just do a regular delete. - - if (range.isExpanded) return node.deleteAtRange(range); - - // When collapsed at the start of the node, there's nothing to do. - if (range.isAtStartOf(node)) return node; - - // When collapsed in a void node, remove that node. - var block = node.getClosestBlock(startKey); - if (block && block.isVoid) return node.removeDescendant(block); - - var inline = node.getClosestInline(startKey); - if (inline && inline.isVoid) return node.removeDescendant(inline); - - // When at start of a text node, merge forwards into the next text node. - var startNode = node.getDescendant(startKey); - - if (range.isAtStartOf(startNode)) { - var previous = node.getPreviousText(startNode); - - // If the previous descendant is void, remove it. - var prevBlock = node.getClosestBlock(previous); - if (prevBlock && prevBlock.isVoid) return node.removeDescendant(prevBlock); - - var prevInline = node.getClosestInline(previous); - if (prevInline && prevInline.isVoid) return node.removeDescendant(prevInline); - - range = range.extendToEndOf(previous); - range = range.normalize(node); - return node.deleteAtRange(range); - } - - // Otherwise, remove `n` characters behind of the cursor. - range = range.extendBackward(n); - range = range.normalize(node); - return node.deleteAtRange(range); - }, - - - /** - * Delete forward `n` characters at a `range`. - * - * @param {Selection} range - * @param {Number} n (optional) - * @return {Node} node - */ - - deleteForwardAtRange: function deleteForwardAtRange(range) { - var n = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1]; - - var node = this; - var _range2 = range; - var startKey = _range2.startKey; - - // When the range is still expanded, just do a regular delete. - - if (range.isExpanded) return node.deleteAtRange(range); - - // When collapsed at the end of the node, there's nothing to do. - if (range.isAtEndOf(node)) return node; - - // When collapsed in a void node, remove that node. - var block = node.getClosestBlock(startKey); - if (block && block.isVoid) return node.removeDescendant(block); - - var inline = node.getClosestInline(startKey); - if (inline && inline.isVoid) return node.removeDescendant(inline); - - // When at end of a text node, merge forwards into the next text node. - var startNode = node.getDescendant(startKey); - if (range.isAtEndOf(startNode)) { - var next = node.getNextText(startNode); - range = range.extendToStartOf(next); - range = range.normalize(node); - return node.deleteAtRange(range); - } - - // Otherwise, remove `n` characters ahead of the cursor. - range = range.extendForward(n); - range = range.normalize(node); - return node.deleteAtRange(range); - }, - - - /** - * Insert a `fragment` at a `range`. - * - * @param {Selection} range - * @param {List} fragment - * @return {Node} node - */ - - insertFragmentAtRange: function insertFragmentAtRange(range, fragment) { - range = range.normalize(this); - var node = this; - - // If the range is expanded, delete first. - if (range.isExpanded) { - node = node.deleteAtRange(range); - range = range.collapseToStart(); - } - - // If the fragment is empty, do nothing. - if (!fragment.length) return node; - - // Make sure each node in the fragment has a unique key. - fragment = fragment.mapDescendants(function (child) { - return child.set('key', (0, _uid2.default)()); - }); - - // Split the inlines if need be. - if (!node.isInlineSplitAtRange(range)) { - node = node.splitInlineAtRange(range); - } - - // Determine the start and next children to insert into. - var _range3 = range; - var startKey = _range3.startKey; - var endKey = _range3.endKey; - - var block = node.getClosestBlock(startKey); - var start = node.getDescendant(startKey); - var startChild = void 0; - var nextChild = void 0; - - if (range.isAtStartOf(node)) { - nextChild = node.getClosestBlock(node.getTextNodes().first()); - } - - if (range.isAtStartOf(block)) { - nextChild = block.getHighestChild(block.getTextNodes().first()); - } else if (range.isAtStartOf(start)) { - startChild = block.getHighestChild(block.getPreviousText(start)); - nextChild = block.getNextSibling(startChild); - } else { - startChild = block.getHighestChild(start); - nextChild = block.getNextSibling(startChild); - } - - // Get the first and last block of the fragment. - var blocks = fragment.getDeepestBlocks(); - var firstBlock = blocks.first(); - var lastBlock = blocks.last(); - - // If the block is empty, merge in the first block's type and data. - if (block.length == 0) { - block = block.merge({ - type: firstBlock.type, - data: firstBlock.data - }); - } - - // Insert the first blocks nodes into the starting block. - if (startChild) { - block = block.insertChildrenAfter(startChild, firstBlock.nodes); - } else { - block = block.insertChildrenBefore(nextChild, firstBlock.nodes); - } - - node = node.updateDescendant(block); - - // If there are no other siblings, that's it. - if (firstBlock == lastBlock) return node.normalize(); - - // Otherwise, remove the fragment's first block's highest solo parent... - var highestParent = fragment.getHighestOnlyChildParent(firstBlock); - fragment = fragment.removeDescendant(highestParent || firstBlock); - - // Then, add the inlines after the cursor from the current block to the - // start of the last block in the fragment. - if (nextChild) { - lastBlock = lastBlock.concatChildren(block.getChildrenAfterIncluding(nextChild)); - fragment = fragment.updateDescendant(lastBlock); - - block = block.removeChildrenAfterIncluding(nextChild); - node = node.updateDescendant(block); - } - - // Finally, add the fragment's children after the block. - node = node.insertChildrenAfter(block, fragment.nodes); - return node.normalize(); - }, - - - /** - * Insert text `string` at a `range`, with optional `marks`. - * - * @param {Selection} range - * @param {String} string - * @param {Set} marks (optional) - * @return {Node} node - */ - - insertTextAtRange: function insertTextAtRange(range, string, marks) { - var node = this; - - // When still expanded, remove the current range first. - if (range.isExpanded) { - node = node.deleteAtRange(range); - range = range.collapseToStart(); - } - - // Insert text at the range's offset. - var _range4 = range; - var startKey = _range4.startKey; - var startOffset = _range4.startOffset; - - var text = node.getDescendant(startKey); - text = text.insertText(startOffset, string, marks); - node = node.updateDescendant(text); - - return node; - }, - - - /** - * Add a new `mark` to the characters at `range`. - * - * @param {Selection} range - * @param {Mark or String} mark - * @return {Node} node - */ - - addMarkAtRange: function addMarkAtRange(range, mark) { - var node = this; - - // Allow for just passing a type for convenience. - if (typeof mark == 'string') { - mark = new _mark2.default({ type: mark }); - } - - // When the range is collapsed, do nothing. - if (range.isCollapsed) return node; - - // Otherwise, find each of the text nodes within the range. - var startKey = range.startKey; - var startOffset = range.startOffset; - var endKey = range.endKey; - var endOffset = range.endOffset; - - var texts = node.getTextsAtRange(range); - - // Apply the mark to each of the text nodes's matching characters. - texts = texts.map(function (text) { - var characters = text.characters.map(function (char, i) { - if (!isInRange(i, text, range)) return char; - var marks = char.marks; - - marks = marks.add(mark); - return char.merge({ marks: marks }); - }); - - return text.merge({ characters: characters }); - }); - - // Update each of the text nodes. - texts.forEach(function (text) { - node = node.updateDescendant(text); - }); - - return node; - }, - - - /** - * Set the `properties` of block nodes in a `range`. - * - * @param {Selection} range - * @param {Object or String} properties - * @return {Node} node - */ - - setBlockAtRange: function setBlockAtRange(range) { - var properties = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; - - var node = this; - - // Allow for properties to be a string `type` for convenience. - if (typeof properties == 'string') { - properties = { type: properties }; - } - - // Update each of the blocks. - var blocks = node.getBlocksAtRange(range); - blocks.forEach(function (block) { - if (properties.data) properties.data = _data2.default.create(properties.data); - block = block.merge(properties); - node = node.updateDescendant(block); - }); - - return node.normalize(); - }, - - - /** - * Set the `properties` of inline nodes in a `range`. - * - * @param {Selection} range - * @param {Object or String} properties - * @return {Node} node - */ - - setInlineAtRange: function setInlineAtRange(range) { - var properties = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; - - var node = this; - - // Allow for properties to be a string `type` for convenience. - if (typeof properties == 'string') { - properties = { type: properties }; - } - - // Update each of the inlines. - var inlines = node.getInlinesAtRange(range); - inlines.forEach(function (inline) { - if (properties.data) properties.data = _data2.default.create(properties.data); - inline = inline.merge(properties); - node = node.updateDescendant(inline); - }); - - return node.normalize(); - }, - - - /** - * Split the block nodes at a `range`, to optional `depth`. - * - * @param {Selection} range - * @param {Number} depth (optional) - * @return {Node} node - */ - - splitBlockAtRange: function splitBlockAtRange(range) { - var depth = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1]; - - var node = this; - - // If the range is expanded, remove it first. - if (range.isExpanded) { - node = node.deleteAtRange(range); - range = range.collapseToStart(); - } - - // Split the inline nodes at the range. - node = node.splitInlineAtRange(range); - - // Find the highest inline elements that were split. - var _range5 = range; - var startKey = _range5.startKey; - - var firstText = node.getDescendant(startKey); - var secondText = node.getNextText(startKey); - var firstChild = node.getFurthestInline(firstText) || firstText; - var secondChild = node.getFurthestInline(secondText) || secondText; - var parent = node.getClosestBlock(firstChild); - var firstChildren = parent.nodes.takeUntil(function (n) { - return n == firstChild; - }).push(firstChild); - var secondChildren = parent.nodes.skipUntil(function (n) { - return n == secondChild; - }); - var d = 0; - - // While the parent is a block, split the block nodes. - while (parent && d < depth) { - firstChild = parent.merge({ nodes: firstChildren }); - secondChild = _block2.default.create({ - nodes: secondChildren, - type: parent.type, - data: parent.data - }); - - firstChildren = _block2.default.createList([firstChild]); - secondChildren = _block2.default.createList([secondChild]); - - // Add the new children. - var grandparent = node.getParent(parent); - var nodes = grandparent.nodes.takeUntil(function (n) { - return n.key == firstChild.key; - }).push(firstChild).push(secondChild).concat(grandparent.nodes.skipUntil(function (n) { - return n.key == firstChild.key; - }).rest()); - - // Update the grandparent. - node = grandparent == node ? node.merge({ nodes: nodes }) : node.updateDescendant(grandparent.merge({ nodes: nodes })); - - d++; - parent = node.getClosestBlock(firstChild); - } - - return node; - }, - - - /** - * Split the inline nodes at a `range`, to optional `depth`. - * - * @param {Selection} range - * @param {Number} depth (optiona) - * @return {Node} node - */ - - splitInlineAtRange: function splitInlineAtRange(range) { - var depth = arguments.length <= 1 || arguments[1] === undefined ? Infinity : arguments[1]; - - var node = this; - - // If the range is expanded, remove it first. - if (range.isExpanded) { - node = node.deleteAtRange(range); - range = range.collapseToStart(); - } - - // First split the text nodes. - node = node.splitTextAtRange(range); - - // Find the children that were split. - var _range6 = range; - var startKey = _range6.startKey; - - var firstChild = node.getDescendant(startKey); - var secondChild = node.getNextText(firstChild); - var parent = node.getClosestInline(firstChild); - var d = 0; - - // While the parent is an inline parent, split the inline nodes. - while (parent && d < depth) { - firstChild = parent.merge({ nodes: _inline2.default.createList([firstChild]) }); - secondChild = _inline2.default.create({ - nodes: [secondChild], - type: parent.type, - data: parent.data - }); - - // Split the children. - var grandparent = node.getParent(parent); - var nodes = grandparent.nodes.takeUntil(function (n) { - return n.key == firstChild.key; - }).push(firstChild).push(secondChild).concat(grandparent.nodes.skipUntil(function (n) { - return n.key == firstChild.key; - }).rest()); - - // Update the grandparent. - node = grandparent == node ? node.merge({ nodes: nodes }) : node.updateDescendant(grandparent.merge({ nodes: nodes })); - - d++; - parent = node.getClosestInline(firstChild); - } - - return node; - }, - - - /** - * Split the text nodes at a `range`. - * - * @param {Selection} range - * @return {Node} node - */ - - splitTextAtRange: function splitTextAtRange(range) { - var node = this; - - // If the range is expanded, remove it first. - if (range.isExpanded) { - node = node.deleteAtRange(range); - range = range.collapseToStart(); - } - - // Split the text node's characters. - var _range7 = range; - var startKey = _range7.startKey; - var startOffset = _range7.startOffset; - - var text = node.getDescendant(startKey); - var characters = text.characters; - - var firstChars = characters.take(startOffset); - var secondChars = characters.skip(startOffset); - var firstChild = text.merge({ characters: firstChars }); - var secondChild = _text2.default.create({ characters: secondChars }); - - // Split the text nodes. - var parent = node.getParent(text); - var nodes = parent.nodes.takeUntil(function (c) { - return c.key == firstChild.key; - }).push(firstChild).push(secondChild).concat(parent.nodes.skipUntil(function (n) { - return n.key == firstChild.key; - }).rest()); - - // Update the nodes. - parent = parent.merge({ nodes: nodes }); - node = node.updateDescendant(parent); - return node; - }, - - - /** - * Remove an existing `mark` to the characters at `range`. - * - * @param {Selection} range - * @param {Mark or String} mark (optional) - * @return {Node} node - */ - - removeMarkAtRange: function removeMarkAtRange(range, mark) { - var node = this; - - // Allow for just passing a type for convenience. - if (typeof mark == 'string') { - mark = new _mark2.default({ type: mark }); - } - - // When the range is collapsed, do nothing. - if (range.isCollapsed) return node; - - // Otherwise, find each of the text nodes within the range. - var texts = node.getTextsAtRange(range); - - // Apply the mark to each of the text nodes's matching characters. - texts = texts.map(function (text) { - var characters = text.characters.map(function (char, i) { - if (!isInRange(i, text, range)) return char; - var marks = char.marks; - - marks = mark ? marks.remove(mark) : marks.clear(); - return char.merge({ marks: marks }); - }); - - return text.merge({ characters: characters }); - }); - - // Update each of the text nodes. - texts.forEach(function (text) { - node = node.updateDescendant(text); - }); - - return node; - }, - - - /** - * Unwrap all of the block nodes in a `range` from a block node of `type.` - * - * @param {Selection} range - * @param {String} type (optional) - * @param {Data or Object} data (optional) - * @return {Node} node - */ - - unwrapBlockAtRange: function unwrapBlockAtRange(range, type, data) { - var node = this; - - // Allow for only data. - if ((typeof type === 'undefined' ? 'undefined' : _typeof(type)) == 'object') { - data = type; - type = null; - } - - // Ensure that data is immutable. - if (data) data = _data2.default.create(data); - - // Find the closest wrapping blocks of each text node. - var texts = node.getBlocksAtRange(range); - var wrappers = texts.reduce(function (memo, text) { - var match = node.getClosest(text, function (parent) { - if (parent.kind != 'block') return false; - if (type && parent.type != type) return false; - if (data && !parent.data.isSuperset(data)) return false; - return true; - }); - - if (match) memo = memo.add(match); - return memo; - }, new _immutable.Set()); - - // Replace each of the wrappers with their child nodes. - wrappers.forEach(function (wrapper) { - var parent = node.getParent(wrapper); - - // Replace the wrapper in the parent's nodes with the block. - var nodes = parent.nodes.takeUntil(function (n) { - return n == wrapper; - }).concat(wrapper.nodes).concat(parent.nodes.skipUntil(function (n) { - return n == wrapper; - }).rest()); - - // Update the parent. - node = parent == node ? node.merge({ nodes: nodes }) : node.updateDescendant(parent.merge({ nodes: nodes })); - }); - - return node.normalize(); - }, - - - /** - * Unwrap the inline nodes in a `range` from an parent inline with `type`. - * - * @param {Selection} range - * @param {String} type (optional) - * @param {Data} data (optional) - * @return {Node} node - */ - - unwrapInlineAtRange: function unwrapInlineAtRange(range, type, data) { - var node = this; - var blocks = node.getInlinesAtRange(range); - - // Allow for no type. - if ((typeof type === 'undefined' ? 'undefined' : _typeof(type)) == 'object') { - data = type; - type = null; - } - - // Ensure that data is immutable. - if (data) data = _data2.default.create(data); - - // Find the closest matching inline wrappers of each text node. - var texts = this.getTextNodes(); - var wrappers = texts.reduce(function (memo, text) { - var match = node.getClosest(text, function (parent) { - if (parent.kind != 'inline') return false; - if (type && parent.type != type) return false; - if (data && !parent.data.isSuperset(data)) return false; - return true; - }); - - if (match) memo = memo.add(match); - return memo; - }, new _immutable.Set()); - - // Replace each of the wrappers with their child nodes. - wrappers.forEach(function (wrapper) { - var parent = node.getParent(wrapper); - - // Replace the wrapper in the parent's nodes with the block. - var nodes = parent.nodes.takeUntil(function (n) { - return n == wrapper; - }).concat(wrapper.nodes).concat(parent.nodes.skipUntil(function (n) { - return n == wrapper; - }).rest()); - - // Update the parent. - node = parent == node ? node.merge({ nodes: nodes }) : node.updateDescendant(parent.merge({ nodes: nodes })); - }); - - return node.normalize(); - }, - - - /** - * Wrap all of the blocks in a `range` in a new block node of `type`. - * - * @param {Selection} range - * @param {String} type - * @param {Data} data (optional) - * @return {Node} node - */ - - wrapBlockAtRange: function wrapBlockAtRange(range, type, data) { - data = _data2.default.create(data); - var node = this; - - // Get the block nodes, sorted by depth. - var blocks = node.getBlocksAtRange(range); - var sorted = blocks.sort(function (a, b) { - var da = node.getDepth(a); - var db = node.getDepth(b); - if (da == db) return 0;else if (da > db) return -1;else return 1; - }); - - // Get the lowest common siblings, relative to the highest block. - var highest = sorted.first(); - var depth = node.getDepth(highest); - var siblings = blocks.reduce(function (memo, block) { - var sibling = node.getDepth(block) == depth ? block : node.getClosest(block, function (p) { - return node.getDepth(p) == depth; - }); - memo = memo.push(sibling); - return memo; - }, _block2.default.createList()); - - // Wrap the siblings in a new block. - var wrapper = _block2.default.create({ - nodes: siblings, - type: type, - data: data - }); - - // Replace the siblings with the wrapper. - var first = siblings.first(); - var last = siblings.last(); - var parent = node.getParent(highest); - var nodes = parent.nodes.takeUntil(function (n) { - return n == first; - }).push(wrapper).concat(parent.nodes.skipUntil(function (n) { - return n == last; - }).rest()); - - // Update the parent. - node = parent == node ? node.merge({ nodes: nodes }) : node.updateDescendant(parent.merge({ nodes: nodes })); - - return node; - }, - - - /** - * Wrap the text and inline nodes in a `range` with a new inline node. - * - * @param {Selection} range - * @param {String} type - * @param {Data} data (optional) - * @return {Node} node - */ - - wrapInlineAtRange: function wrapInlineAtRange(range, type, data) { - data = _data2.default.create(data); - var node = this; - - // If collapsed, there's nothing to wrap. - if (range.isCollapsed) return node; - - // Split at the start of the range. - var start = range.collapseToStart(); - node = node.splitInlineAtRange(start); - - // Determine the new end of the range, and split there. - var _range8 = range; - var startKey = _range8.startKey; - var startOffset = _range8.startOffset; - var endKey = _range8.endKey; - var endOffset = _range8.endOffset; - - var firstNode = node.getDescendant(startKey); - var nextNode = node.getNextText(startKey); - var end = startKey != endKey ? range.collapseToEnd() : _selection2.default.create({ - anchorKey: nextNode.key, - anchorOffset: endOffset - startOffset, - focusKey: nextNode.key, - focusOffset: endOffset - startOffset - }); - - node = node.splitInlineAtRange(end); - - // Calculate the new range to wrap around. - var endNode = node.getDescendant(end.anchorKey); - range = _selection2.default.create({ - anchorKey: nextNode.key, - anchorOffset: 0, - focusKey: endNode.key, - focusOffset: endNode.length - }); - - // Get the furthest inline nodes in the range. - var texts = node.getTextsAtRange(range); - var children = texts.map(function (text) { - return node.getFurthestInline(text) || text; - }); - - // Iterate each of the child nodes, wrapping them. - children.forEach(function (child) { - var obj = {}; - obj.nodes = [child]; - obj.type = type; - if (data) obj.data = data; - var wrapper = _inline2.default.create(obj); - - // Replace the child in it's parent with the wrapper. - var parent = node.getParent(child); - var nodes = parent.nodes.takeUntil(function (n) { - return n == child; - }).push(wrapper).concat(parent.nodes.skipUntil(function (n) { - return n == child; - }).rest()); - - // Update the parent. - node = parent == node ? node.merge({ nodes: nodes }) : node.updateDescendant(parent.merge({ nodes: nodes })); - }); - - return node; - } -}; - -/** - * Check if an `index` of a `text` node is in a `range`. - * - * @param {Number} index - * @param {Text} text - * @param {Selection} range - * @return {Set} characters - */ - -function isInRange(index, text, range) { - var startKey = range.startKey; - var startOffset = range.startOffset; - var endKey = range.endKey; - var endOffset = range.endOffset; - - var matcher = void 0; - - if (text.key == startKey && text.key == endKey) { - return startOffset <= index && index < endOffset; - } else if (text.key == startKey) { - return startOffset <= index; - } else if (text.key == endKey) { - return index < endOffset; - } else { - return true; - } -} - -/** - * Export. - */ - -exports.default = Transforms; -},{"../utils/uid":30,"./block":8,"./character":9,"./data":10,"./document":11,"./inline":12,"./mark":13,"./selection":15,"./text":17,"immutable":122}],20:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _key3 = require('../utils/key'); - -var _key4 = _interopRequireDefault(_key3); - -var _placeholder = require('../components/placeholder'); - -var _placeholder2 = _interopRequireDefault(_placeholder); - -var _react = require('react'); - -var _react2 = _interopRequireDefault(_react); - -var _string = require('../utils/string'); - -var _string2 = _interopRequireDefault(_string); - -var _keycode = require('keycode'); - -var _keycode2 = _interopRequireDefault(_keycode); - -var _environment = require('../utils/environment'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -/** - * The default plugin. - * - * @param {Object} options - * @property {Element} placeholder - * @property {String} placeholderClassName - * @property {Object} placeholderStyle - * @return {Object} - */ - -function Plugin() { - var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - var placeholder = options.placeholder; - var placeholderClassName = options.placeholderClassName; - var placeholderStyle = options.placeholderStyle; - - /** - * Define a default block renderer. - * - * @type {Component} - */ - - var DEFAULT_BLOCK = function (_React$Component) { - _inherits(DEFAULT_BLOCK, _React$Component); - - function DEFAULT_BLOCK() { - var _Object$getPrototypeO; - - var _temp, _this, _ret; - - _classCallCheck(this, DEFAULT_BLOCK); - - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(DEFAULT_BLOCK)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.shouldComponentUpdate = function (props, state) { - return props.node != _this.props.node || props.state.selection.hasEdgeIn(props.node); - }, _this.render = function () { - var _this$props = _this.props; - var attributes = _this$props.attributes; - var children = _this$props.children; - - return _react2.default.createElement( - 'div', - attributes, - _this.renderPlaceholder(), - children - ); - }, _this.renderPlaceholder = function () { - if (!placeholder) return null; - var _this$props2 = _this.props; - var node = _this$props2.node; - var state = _this$props2.state; - - return _react2.default.createElement( - _placeholder2.default, - { - className: placeholderClassName, - node: node, - parent: state.document, - state: state, - style: placeholderStyle - }, - placeholder - ); - }, _temp), _possibleConstructorReturn(_this, _ret); - } - - return DEFAULT_BLOCK; - }(_react2.default.Component); - - /** - * Define a default inline renderer. - * - * @type {Component} - */ - - DEFAULT_BLOCK.propTypes = { - attributes: _react2.default.PropTypes.object.isRequired, - children: _react2.default.PropTypes.any.isRequired, - node: _react2.default.PropTypes.object.isRequired, - state: _react2.default.PropTypes.object.isRequired - }; - - var DEFAULT_INLINE = function (_React$Component2) { - _inherits(DEFAULT_INLINE, _React$Component2); - - function DEFAULT_INLINE() { - var _Object$getPrototypeO2; - - var _temp2, _this2, _ret2; - - _classCallCheck(this, DEFAULT_INLINE); - - for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args[_key2] = arguments[_key2]; - } - - return _ret2 = (_temp2 = (_this2 = _possibleConstructorReturn(this, (_Object$getPrototypeO2 = Object.getPrototypeOf(DEFAULT_INLINE)).call.apply(_Object$getPrototypeO2, [this].concat(args))), _this2), _this2.shouldComponentUpdate = function (props, state) { - return props.node != _this2.props.node || props.state.selection.hasEdgeIn(props.node); - }, _this2.render = function () { - var _this2$props = _this2.props; - var attributes = _this2$props.attributes; - var children = _this2$props.children; - - return _react2.default.createElement( - 'span', - attributes, - children - ); - }, _temp2), _possibleConstructorReturn(_this2, _ret2); - } - - return DEFAULT_INLINE; - }(_react2.default.Component); - - /** - * Define a default mark renderer. - * - * @type {Object} - */ - - DEFAULT_INLINE.propTypes = { - attributes: _react2.default.PropTypes.object.isRequired, - children: _react2.default.PropTypes.any.isRequired, - node: _react2.default.PropTypes.object.isRequired, - state: _react2.default.PropTypes.object.isRequired - }; - var DEFAULT_MARK = {}; - - /** - * Return the plugin. - */ - - return { - - /** - * The core `onBeforeInput` handler. - * - * If the current selection is expanded, we have to re-render. - * - * If the next state resolves a new list of decorations for any of its text - * nodes, we have to re-render. - * - * Otherwise, we can allow the default, native text insertion, avoiding a - * re-render for improved performance. - * - * @param {Event} e - * @param {State} state - * @param {Editor} editor - * @return {State or Null} newState - */ - - onBeforeInput: function onBeforeInput(e, state, editor) { - var transform = state.transform().insertText(e.data); - var synthetic = transform.apply(); - var resolved = editor.resolveState(synthetic); - - var isSynthenic = state.isExpanded || !resolved.equals(synthetic); - - if (isSynthenic) e.preventDefault(); - - return isSynthenic ? synthetic : transform.apply({ isNative: true }); - }, - - - /** - * The core `onKeyDown` handler. - * - * @param {Event} e - * @param {State} state - * @param {Editor} editor - * @return {State or Null} newState - */ - - onKeyDown: function onKeyDown(e, state, editor) { - var key = (0, _keycode2.default)(e.which); - var transform = state.transform(); - - switch (key) { - case 'enter': - { - var startBlock = state.startBlock; - - if (startBlock && !startBlock.isVoid) return transform.splitBlock().apply(); - - var document = state.document; - var startKey = state.startKey; - - var text = document.getNextText(startKey); - if (!text) return; - - return transform.collapseToStartOf(text).apply(); - } - - case 'backspace': - { - if (state.isExpanded) return transform.delete().apply(); - var startOffset = state.startOffset; - var _startBlock = state.startBlock; - - var _text = _startBlock.text; - var n = void 0; - - if (_key4.default.isWord(e)) { - n = _string2.default.getWordOffsetBackward(_text, startOffset); - } else if (_key4.default.isLine(e)) { - n = startOffset; - } else { - n = _string2.default.getCharOffsetBackward(_text, startOffset); - } - - return transform.deleteBackward(n).apply(); - } - - case 'delete': - { - if (state.isExpanded) return transform.delete().apply(); - var _startOffset = state.startOffset; - var _startBlock2 = state.startBlock; - - var _text2 = _startBlock2.text; - var _n = void 0; - - if (_key4.default.isWord(e)) { - _n = _string2.default.getWordOffsetForward(_text2, _startOffset); - } else if (_key4.default.isLine(e)) { - _n = _text2.length - _startOffset; - } else { - _n = _string2.default.getCharOffsetForward(_text2, _startOffset); - } - - return transform.deleteForward(_n).apply(); - } - - case 'up': - { - if (state.isExpanded) return; - var first = state.blocks.first(); - if (!first || !first.isVoid) return; - e.preventDefault(); - return transform.collapseToEndOfPreviousBlock().apply(); - } - - case 'down': - { - if (state.isExpanded) return; - var _first = state.blocks.first(); - if (!_first || !_first.isVoid) return; - e.preventDefault(); - return transform.collapseToStartOfNextBlock().apply(); - } - - case 'left': - { - if (state.isExpanded) return; - var node = state.blocks.first() || state.inlines.first(); - if (!node || !node.isVoid) return; - e.preventDefault(); - return transform.collapseToEndOfPreviousText().apply(); - } - - case 'right': - { - if (state.isExpanded) return; - var _node = state.blocks.first() || state.inlines.first(); - if (!_node || !_node.isVoid) return; - e.preventDefault(); - return transform.collapseToStartOfNextText().apply(); - } - - case 'y': - { - if (!_key4.default.isWindowsCommand(e)) return; - return transform.redo(); - } - - case 'z': - { - if (!_key4.default.isCommand(e)) return; - return _environment.IS_MAC && _key4.default.isShift(e) ? transform.redo() : transform.undo(); - } - } - }, - - - /** - * The core `onPaste` handler, which treats everything as plain text. - * - * @param {Event} e - * @param {Object} paste - * @param {State} state - * @param {Editor} editor - * @return {State or Null} newState - */ - - onPaste: function onPaste(e, paste, state, editor) { - if (paste.type == 'files') return; - - var transform = state.transform(); - - paste.text.split('\n').forEach(function (line, i) { - if (i > 0) transform = transform.splitBlock(); - transform = transform.insertText(line); - }); - - return transform.apply(); - }, - - - /** - * The core `node` renderer, which uses plain `
` or `` depending on - * what kind of node it is. - * - * @param {Node} node - * @return {Component} component - */ - - renderNode: function renderNode(node) { - return node.kind == 'block' ? DEFAULT_BLOCK : DEFAULT_INLINE; - }, - - - /** - * The core `mark` renderer, with no styles. - * - * @param {Mark} mark - * @return {Object} style - */ - - renderMark: function renderMark(mark) { - return DEFAULT_MARK; - } - }; -} - -/** - * Export. - */ - -exports.default = Plugin; -},{"../components/placeholder":4,"../utils/environment":24,"../utils/key":27,"../utils/string":29,"keycode":125,"react":362}],21:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _block2 = require('../models/block'); - -var _block3 = _interopRequireDefault(_block2); - -var _document = require('../models/document'); - -var _document2 = _interopRequireDefault(_document); - -var _inline = require('../models/inline'); - -var _inline2 = _interopRequireDefault(_inline); - -var _mark = require('../models/mark'); - -var _mark2 = _interopRequireDefault(_mark); - -var _raw = require('./raw'); - -var _raw2 = _interopRequireDefault(_raw); - -var _react = require('react'); - -var _react2 = _interopRequireDefault(_react); - -var _server = require('react-dom/server'); - -var _server2 = _interopRequireDefault(_server); - -var _state = require('../models/state'); - -var _state2 = _interopRequireDefault(_state); - -var _text = require('../models/text'); - -var _text2 = _interopRequireDefault(_text); - -var _cheerio = require('cheerio'); - -var _cheerio2 = _interopRequireDefault(_cheerio); - -var _groupByMarks = require('../utils/group-by-marks'); - -var _groupByMarks2 = _interopRequireDefault(_groupByMarks); - -var _immutable = require('immutable'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _toConsumableArray(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); } } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -/** - * String. - */ - -var String = new _immutable.Record({ - kind: 'string', - text: '' -}); - -/** - * A rule to (de)serialize text nodes. This is automatically added to the HTML - * serializer so that users don't have to worry about text-level serialization. - * - * @type {Object} - */ - -var TEXT_RULE = { - deserialize: function deserialize(el) { - if (el.tagName == 'br') { - return { - kind: 'text', - ranges: [{ text: '\n' }] - }; - } - - if (el.type == 'text') { - return { - kind: 'text', - ranges: [{ text: el.data }] - }; - } - }, - serialize: function serialize(obj, children) { - if (obj.kind == 'string') { - return children.split('\n').reduce(function (array, text, i) { - if (i != 0) array.push(_react2.default.createElement('br', null)); - array.push(text); - return array; - }, []); - } - } -}; - -/** - * HTML serializer. - * - * @type {Html} - */ - -var Html = - -/** - * Create a new serializer with `rules`. - * - * @param {Object} options - * @property {Array} rules - * @return {Html} serializer - */ - -function Html() { - var _this = this; - - var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - _classCallCheck(this, Html); - - this.deserialize = function (html) { - var $ = _cheerio2.default.load(html).root(); - var children = $.children().toArray(); - var nodes = _this.deserializeElements(children); - - // HACK: ensure for now that all top-level inline are wrapped into a block. - nodes = nodes.reduce(function (memo, node, i, original) { - if (node.kind == 'block') { - memo.push(node); - return memo; - } - - if (i > 0 && original[i - 1].kind != 'block') { - var _block = memo[memo.length - 1]; - _block.nodes.push(node); - return memo; - } - - var block = { - kind: 'block', - type: 'paragraph', - nodes: [node] - }; - - memo.push(block); - return memo; - }, []); - - var state = _raw2.default.deserialize({ nodes: nodes }); - return state; - }; - - this.deserializeElements = function () { - var elements = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; - - var nodes = []; - - elements.forEach(function (element) { - var node = _this.deserializeElement(element); - if (!node) return; - if (Array.isArray(node)) { - nodes = nodes.concat(node); - } else { - nodes.push(node); - } - }); - - return nodes; - }; - - this.deserializeElement = function (element) { - var node = void 0; - - var next = function next(elements) { - return Array.isArray(elements) ? _this.deserializeElements(elements) : _this.deserializeElement(elements); - }; - - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = _this.rules[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var rule = _step.value; - - if (!rule.deserialize) continue; - var ret = rule.deserialize(element, next); - if (!ret) continue; - node = ret.kind == 'mark' ? _this.deserializeMark(ret) : ret; - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - return node || next(element.children); - }; - - this.deserializeMark = function (mark) { - var type = mark.type; - var data = mark.data; - - - var applyMark = function applyMark(node) { - if (node.kind == 'mark') { - return _this.deserializeMark(node); - } else if (node.kind == 'text') { - node.ranges = node.ranges.map(function (range) { - range.marks = range.marks || []; - range.marks.push({ type: type, data: data }); - return range; - }); - } else { - node.nodes = node.nodes.map(applyMark); - } - - return node; - }; - - return mark.nodes.reduce(function (nodes, node) { - var ret = applyMark(node); - if (Array.isArray(ret)) return nodes.concat(ret); - nodes.push(ret); - return nodes; - }, []); - }; - - this.serialize = function (state) { - var document = state.document; - - var elements = document.nodes.map(_this.serializeNode); - var html = _server2.default.renderToStaticMarkup(_react2.default.createElement( - 'body', - null, - elements - )); - var inner = html.slice(6, -7); - return inner; - }; - - this.serializeNode = function (node) { - if (node.kind == 'text') { - var ranges = (0, _groupByMarks2.default)(node.characters); - return ranges.map(_this.serializeRange); - } - - var children = node.nodes.map(_this.serializeNode); - - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = _this.rules[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var rule = _step2.value; - - if (!rule.serialize) continue; - var ret = rule.serialize(node, children); - if (ret) return addKey(ret); - throw new Error('No serializer defined for node of type "' + node.type + '".'); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2.return) { - _iterator2.return(); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - }; - - this.serializeRange = function (range) { - var string = new String({ text: range.text }); - var text = _this.serializeString(string); - - return range.marks.reduce(function (children, mark) { - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = _this.rules[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var rule = _step3.value; - - if (!rule.serialize) continue; - var ret = rule.serialize(mark, children); - if (ret) return addKey(ret); - throw new Error('No serializer defined for mark of type "' + mark.type + '".'); - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3.return) { - _iterator3.return(); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - }, text); - }; - - this.serializeString = function (string) { - var _iteratorNormalCompletion4 = true; - var _didIteratorError4 = false; - var _iteratorError4 = undefined; - - try { - for (var _iterator4 = _this.rules[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var rule = _step4.value; - - if (!rule.serialize) continue; - var ret = rule.serialize(string, string.text); - if (ret) return ret; - } - } catch (err) { - _didIteratorError4 = true; - _iteratorError4 = err; - } finally { - try { - if (!_iteratorNormalCompletion4 && _iterator4.return) { - _iterator4.return(); - } - } finally { - if (_didIteratorError4) { - throw _iteratorError4; - } - } - } - }; - - this.rules = [].concat(_toConsumableArray(options.rules || []), [TEXT_RULE]); -} - -/** - * Deserialize pasted HTML. - * - * @param {String} html - * @return {State} state - */ - -/** - * Deserialize an array of Cheerio `elements`. - * - * @param {Array} elements - * @return {Array} nodes - */ - -/** - * Deserialize a Cheerio `element`. - * - * @param {Object} element - * @return {Mixed} node - */ - -/** - * Deserialize a `mark` object. - * - * @param {Object} mark - * @return {Array} nodes - */ - -/** - * Serialize a `state` object into an HTML string. - * - * @param {State} state - * @return {String} html - */ - -/** - * Serialize a `node`. - * - * @param {Node} node - * @return {String} - */ - -/** - * Serialize a `range`. - * - * @param {Range} range - * @return {String} - */ - -/** - * Serialize a `string`. - * - * @param {String} string - * @return {String} - */ - -; - -/** - * Add a unique key to a React `element`. - * - * @param {Element} element - * @return {Element} - */ - -var key = 0; - -function addKey(element) { - return _react2.default.cloneElement(element, { key: key++ }); -} - -/** - * Export. - */ - -exports.default = Html; -},{"../models/block":8,"../models/document":11,"../models/inline":12,"../models/mark":13,"../models/state":16,"../models/text":17,"../utils/group-by-marks":26,"./raw":23,"cheerio":37,"immutable":122,"react":362,"react-dom/server":215}],22:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _block = require('../models/block'); - -var _block2 = _interopRequireDefault(_block); - -var _document = require('../models/document'); - -var _document2 = _interopRequireDefault(_document); - -var _state = require('../models/state'); - -var _state2 = _interopRequireDefault(_state); - -var _text = require('../models/text'); - -var _text2 = _interopRequireDefault(_text); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * Deserialize a plain text `string` to a state. - * - * @param {String} string - * @return {State} - */ - -function deserialize(string) { - return _state2.default.create({ - document: _document2.default.create({ - nodes: string.split('\n').map(deserializeLine) - }) - }); -} - -/** - * Deserialize a `line` of text. - * - * @param {String} line - * @return {Block} - */ - -function deserializeLine(line) { - return _block2.default.create({ - type: 'line', - nodes: [_text2.default.create({ - characters: line.split('').map(deserializeCharacter) - })] - }); -} - -/** - * Deserialize a `character`. - * - * @param {String} char - * @return {Character} - */ - -function deserializeCharacter(char) { - return { text: char }; -} - -/** - * Serialize a `state` to plain text. - * - * @param {State} state - * @return {String} - */ - -function serialize(state) { - return state.document.nodes.map(function (block) { - return block.text; - }).join('\n'); -} - -/** - * Export. - */ - -exports.default = { - deserialize: deserialize, - serialize: serialize -}; -},{"../models/block":8,"../models/document":11,"../models/state":16,"../models/text":17}],23:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _block = require('../models/block'); - -var _block2 = _interopRequireDefault(_block); - -var _character = require('../models/character'); - -var _character2 = _interopRequireDefault(_character); - -var _document = require('../models/document'); - -var _document2 = _interopRequireDefault(_document); - -var _inline = require('../models/inline'); - -var _inline2 = _interopRequireDefault(_inline); - -var _mark = require('../models/mark'); - -var _mark2 = _interopRequireDefault(_mark); - -var _state = require('../models/state'); - -var _state2 = _interopRequireDefault(_state); - -var _text = require('../models/text'); - -var _text2 = _interopRequireDefault(_text); - -var _groupByMarks = require('../utils/group-by-marks'); - -var _groupByMarks2 = _interopRequireDefault(_groupByMarks); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _toConsumableArray(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); } } - -/** - * Serialize a `state`. - * - * @param {State} state - * @return {Object} object - */ - -function serialize(state) { - return serializeNode(state.document); -} - -/** - * Serialize a `node`. - * - * @param {Node} node - * @return {Object} object - */ - -function serializeNode(node) { - switch (node.kind) { - case 'document': - { - return { - nodes: node.nodes.toArray().map(function (child) { - return serializeNode(child); - }) - }; - } - case 'text': - { - return { - kind: node.kind, - ranges: serializeCharacters(node.characters) - }; - } - case 'block': - case 'inline': - { - var obj = {}; - obj.kind = node.kind; - obj.type = node.type; - obj.nodes = node.nodes.toArray().map(function (child) { - return serializeNode(child); - }); - if (node.isVoid) obj.isVoid = node.isVoid; - if (node.data.size) obj.data = node.data.toJSON(); - return obj; - } - default: - { - throw new Error('Unknown node kind "' + node.kind + '".'); - } - } -} - -/** - * Serialize a list of `characters`. - * - * @param {List} characters - * @return {Array} - */ - -function serializeCharacters(characters) { - return (0, _groupByMarks2.default)(characters).toArray().map(function (range) { - var obj = {}; - obj.text = range.text; - if (range.marks.size) obj.marks = range.marks.toArray().map(serializeMark); - return obj; - }); -} - -/** - * Serialize a `mark`. - * - * @param {Mark} mark - * @return {Object} Object - */ - -function serializeMark(mark) { - var obj = {}; - obj.type = mark.type; - if (mark.data.size) obj.data = mark.data.toJSON(); - return obj; -} - -/** - * Deserialize a state JSON `object`. - * - * @param {Object} object - * @return {State} state - */ - -function deserialize(object) { - return _state2.default.create({ - document: _document2.default.create({ - nodes: _block2.default.createList(object.nodes.map(deserializeNode)) - }) - }); -} - -/** - * Deserialize a node JSON `object`. - * - * @param {Object} object - * @return {Node} node - */ - -function deserializeNode(object) { - switch (object.kind) { - case 'block': - { - return _block2.default.create({ - type: object.type, - data: object.data, - isVoid: object.isVoid, - nodes: _block2.default.createList((object.nodes || []).map(deserializeNode)) - }); - } - case 'inline': - { - return _inline2.default.create({ - type: object.type, - data: object.data, - isVoid: object.isVoid, - nodes: _inline2.default.createList((object.nodes || []).map(deserializeNode)) - }); - } - case 'text': - { - return _text2.default.create({ - characters: object.ranges ? deserializeRanges(object.ranges) : '' - }); - } - default: - { - throw new Error('Unknown node kind "' + object.kind + '".'); - } - } -} - -/** - * Deserialize a JSON `array` of ranges. - * - * @param {Array} array - * @return {List} characters - */ - -function deserializeRanges(array) { - return array.reduce(function (characters, object) { - var marks = object.marks || []; - var chars = object.text.split('').map(function (char) { - return _character2.default.create({ - text: char, - marks: _mark2.default.createSet(marks.map(deserializeMark)) - }); - }); - - return characters.push.apply(characters, _toConsumableArray(chars)); - }, _character2.default.createList()); -} - -/** - * Deserialize a mark JSON `object`. - * - * @param {Object} object - * @return {Mark} mark - */ - -function deserializeMark(object) { - return _mark2.default.create(object); -} - -/** - * Export. - */ - -exports.default = { - serialize: serialize, - serializeCharacters: serializeCharacters, - serializeMark: serializeMark, - serializeNode: serializeNode, - deserialize: deserialize, - deserializeNode: deserializeNode, - deserializeRanges: deserializeRanges -}; -},{"../models/block":8,"../models/character":9,"../models/document":11,"../models/inline":12,"../models/mark":13,"../models/state":16,"../models/text":17,"../utils/group-by-marks":26}],24:[function(require,module,exports){ -(function (process){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.IS_WINDOWS = exports.IS_UBUNTU = exports.IS_SAFARI = exports.IS_MAC = exports.IS_IOS = exports.IS_IE = exports.IS_FIREFOX = exports.IS_EDGE = exports.IS_CHROME = exports.IS_ANDROID = undefined; - -var _uaParserJs = require('ua-parser-js'); - -var _uaParserJs2 = _interopRequireDefault(_uaParserJs); - -var _detectBrowser = require('detect-browser'); - -var _detectBrowser2 = _interopRequireDefault(_detectBrowser); - -var _includes = require('lodash/includes'); - -var _includes2 = _interopRequireDefault(_includes); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * Export. - */ - -var IS_ANDROID = exports.IS_ANDROID = process.browser && _detectBrowser2.default.name == 'android'; -var IS_CHROME = exports.IS_CHROME = process.browser && _detectBrowser2.default.name == 'chrome'; -var IS_EDGE = exports.IS_EDGE = process.browser && _detectBrowser2.default.name == 'edge'; -var IS_FIREFOX = exports.IS_FIREFOX = process.browser && _detectBrowser2.default.name == 'firefox'; -var IS_IE = exports.IS_IE = process.browser && _detectBrowser2.default.name == 'ie'; -var IS_IOS = exports.IS_IOS = process.browser && _detectBrowser2.default.name == 'ios'; -var IS_MAC = exports.IS_MAC = process.browser && new _uaParserJs2.default().getOS().name == 'Mac OS'; -var IS_SAFARI = exports.IS_SAFARI = process.browser && _detectBrowser2.default.name == 'safari'; -var IS_UBUNTU = exports.IS_UBUNTU = process.browser && new _uaParserJs2.default().getOS().name == 'Ubuntu'; -var IS_WINDOWS = exports.IS_WINDOWS = process.browser && (0, _includes2.default)(new _uaParserJs2.default().getOS().name, 'Windows'); - -exports.default = { - IS_ANDROID: IS_ANDROID, - IS_CHROME: IS_CHROME, - IS_EDGE: IS_EDGE, - IS_FIREFOX: IS_FIREFOX, - IS_IE: IS_IE, - IS_IOS: IS_IOS, - IS_MAC: IS_MAC, - IS_SAFARI: IS_SAFARI, - IS_UBUNTU: IS_UBUNTU, - IS_WINDOWS: IS_WINDOWS -}; -}).call(this,require('_process')) -},{"_process":213,"detect-browser":57,"lodash/includes":188,"ua-parser-js":376}],25:[function(require,module,exports){ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -/** - * Find the DOM node for a `node`. - * - * @param {Node} node - * @return {Element} el - */ - -function findDOMNode(node) { - return window.document.querySelector("[data-key=\"" + node.key + "\"]"); -} - -/** - * Export. - */ - -exports.default = findDOMNode; -},{}],26:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _immutable = require('immutable'); - -/** - * Range. - */ - -var Range = new _immutable.Record({ - kind: 'range', - marks: new _immutable.Set(), - text: '' -}); - -/** - * Group a list of `characters` into ranges by the marks they have. - * - * @param {List} characters - * @return {List} ranges - */ - -function groupByMarks(characters) { - if (characters.size == 0) { - var ranges = new _immutable.List(); - ranges = ranges.push(new Range()); - return ranges; - } - - return characters.toList().reduce(function (ranges, char, i) { - var marks = char.marks; - var text = char.text; - - // The first one can always just be created. - - if (i == 0) { - return ranges.push(new Range({ text: text, marks: marks })); - } - - // Otherwise, compare to the previous and see if a new range should be - // created, or whether the text should be added to the previous range. - var previous = characters.get(i - 1); - var prevMarks = previous.marks; - var added = marks.filterNot(function (mark) { - return prevMarks.includes(mark); - }); - var removed = prevMarks.filterNot(function (mark) { - return marks.includes(mark); - }); - var isSame = !added.size && !removed.size; - - // If the marks are the same, add the text to the previous range. - if (isSame) { - var index = ranges.size - 1; - var prevRange = ranges.get(index); - var prevText = prevRange.get('text'); - prevRange = prevRange.set('text', prevText += text); - return ranges.set(index, prevRange); - } - - // Otherwise, create a new range. - return ranges.push(new Range({ text: text, marks: marks })); - }, new _immutable.List()); -} - -/** - * Export. - */ - -exports.default = groupByMarks; -},{"immutable":122}],27:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _environment = require('./environment'); - -/** - * Does an `e` have the alt modifier? - * - * @param {Event} e - * @return {Boolean} - */ - -function isAlt(e) { - return e.altKey; -} - -/** - * Does an `e` have the command modifier? - * - * @param {Event} e - * @return {Boolean} - */ - -function isCommand(e) { - return _environment.IS_MAC ? e.metaKey && !e.altKey : e.ctrlKey && !e.altKey; -} - -/** - * Does an `e` have the control modifier? - * - * @param {Event} e - * @return {Boolean} - */ - -function isCtrl(e) { - return e.ctrlKey && !e.altKey; -} - -/** - * Does an `e` have the line-level modifier? - * - * @param {Event} e - * @return {Boolean} - */ - -function isLine(e) { - return _environment.IS_MAC ? e.metaKey : false; -} - -/** - * Does an `e` have the Mac command modifier? - * - * @param {Event} e - * @return {Boolean} - */ - -function isMacCommand(e) { - return _environment.IS_MAC && isCommand(e); -} - -/** - * Does an `e` have the option modifier? - * - * @param {Event} e - * @return {Boolean} - */ - -function isOption(e) { - return _environment.IS_MAC && e.altKey; -} - -/** - * Does an `e` have the shift modifier? - * - * @param {Event} e - * @return {Boolean} - */ - -function isShift(e) { - return e.shiftKey; -} - -/** - * Does an `e` have the Windows command modifier? - * - * @param {Event} e - * @return {Boolean} - */ - -function isWindowsCommand(e) { - return _environment.IS_WINDOWS && isCommand(e); -} - -/** - * Does an `e` have the word-level modifier? - * - * @param {Event} e - * @return {Boolean} - */ - -function isWord(e) { - return _environment.IS_MAC ? e.altKey : e.ctrlKey; -} - -/** - * Export. - */ - -exports.default = { - isAlt: isAlt, - isCommand: isCommand, - isCtrl: isCtrl, - isLine: isLine, - isMacCommand: isMacCommand, - isOption: isOption, - isShift: isShift, - isWindowsCommand: isWindowsCommand, - isWord: isWord -}; -},{"./environment":24}],28:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); - -/** - * Offset key parser regex. - */ - -var PARSER = /^(\w+)(?::(\d+)-(\d+))?$/; - -/** - * Offset key attribute name. - */ - -var ATTRIBUTE = 'data-offset-key'; -var SELECTOR = '[' + ATTRIBUTE + ']'; - -/** - * From a `node`, find the closest parent's offset key. - * - * @param {Node} node - * @return {String} key - */ - -function findKey(node) { - if (node.nodeType == 3) node = node.parentNode; - - // If a parent with an offset key exists, use it. - var parent = node.closest(SELECTOR); - if (parent) return parent.getAttribute(ATTRIBUTE); - - // Otherwise, if a child with an offset key exists, use it. - var child = node.querySelector(SELECTOR); - if (child) return child.getAttribute(ATTRIBUTE); - - // Otherwise, move up the tree looking for cousin offset keys in parents. - while (node = node.parentNode) { - var cousin = node.querySelector(SELECTOR); - if (cousin) return cousin.getAttribute(ATTRIBUTE); - } - - // Shouldn't get here... else we have an edge case to handle. - throw new Error('No offset key found for node.'); -} - -/** - * From a `node` and `offset`, find the closest parent's point. - * - * @param {Node} node - * @param {Offset} offset - * @return {String} key - */ - -function findPoint(node, offset) { - var key = findKey(node); - var parsed = parse(key); - - // Don't let the offset be outside the start and end bounds. - offset = parsed.start + offset; - offset = Math.max(offset, parsed.start); - offset = Math.min(offset, parsed.end); - - return { - key: parsed.key, - offset: offset - }; -} - -/** - * Parse an offset key `string`. - * - * @param {String} string - * @return {Object} parsed - */ - -function parse(string) { - var matches = PARSER.exec(string); - if (!matches) throw new Error('Invalid offset key string "' + string + '".'); - - var _matches = _slicedToArray(matches, 4); - - var original = _matches[0]; - var key = _matches[1]; - var start = _matches[2]; - var end = _matches[3]; - - start = parseInt(start, 10); - end = parseInt(end, 10); - - return { - key: key, - start: start, - end: end - }; -} - -/** - * Stringify an offset key `object`. - * - * @param {Object} object - * @property {String} key - * @property {Number} start - * @property {Number} end - * @return {String} key - */ - -function stringify(object) { - return object.key + ':' + object.start + '-' + object.end; -} - -/** - * Export. - */ - -exports.default = { - findKey: findKey, - findPoint: findPoint, - parse: parse, - stringify: stringify -}; -},{}],29:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _esrever = require('esrever'); - -/** - * Surrogate pair start and end points. - * - * @type {Number} - */ - -var SURROGATE_START = 0xD800; -var SURROGATE_END = 0xDFFF; - -/** - * A regex to match space characters. - * - * @type {RegExp} - */ - -var SPACE = /\s/; - -/** - * A regex to match chameleon characters, that count as word characters as long - * as they are inside of a word. - * - * @type {RegExp} - */ - -var CHAMELEON = /['\u2018\u2019]/; - -/** - * A regex that matches punctuation. - * - * @type {RegExp} - */ - -var PUNCTUATION = /[\u0021-\u0023\u0025-\u002A\u002C-\u002F\u003A\u003B\u003F\u0040\u005B-\u005D\u005F\u007B\u007D\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/; - -/** - * Is a character `code` in a surrogate character. - * - * @param {Number} code - * @return {Boolean} - */ - -function isSurrogate(code) { - return SURROGATE_START <= code && code <= SURROGATE_END; -} - -/** - * Is a character a word character? Needs the `remaining` characters too. - * - * @param {String} char - * @param {String || Void} remaining - * @return {Boolean} - */ - -function isWord(char, remaining) { - if (SPACE.test(char)) return false; - - // If it's a chameleon character, recurse to see if the next one is or not. - if (CHAMELEON.test(char)) { - var next = remaining.charAt(0); - var length = getCharLength(next); - var rest = remaining.slice(length); - if (isWord(next, rest)) return true; - } - - if (PUNCTUATION.test(char)) return false; - return true; -} - -/** - * Get the length of a `character`. - * - * @param {String} char - * @return {Number} - */ - -function getCharLength(char) { - return isSurrogate(char.charCodeAt(0)) ? 2 : 1; -} - -/** - * Get the offset to the end of the first character in `text`. - * - * @param {String} text - * @return {Number} - */ - -function getCharOffset(text) { - var char = text.charAt(0); - return getCharLength(char); -} - -/** - * Get the offset to the end of the character before an `offset` in `text`. - * - * @param {String} text - * @param {Number} offset - * @return {Number} - */ - -function getCharOffsetBackward(text, offset) { - text = text.slice(0, offset); - text = (0, _esrever.reverse)(text); - return getCharOffset(text); -} - -/** - * Get the offset to the end of the character after an `offset` in `text`. - * - * @param {String} text - * @param {Number} offset - * @return {Number} - */ - -function getCharOffsetForward(text, offset) { - text = text.slice(offset); - return getCharOffset(text); -} - -/** - * Get the length of a `string`. - * - * @param {String} string - * @return {Number} - */ - -function getLength(string) { - var length = 0; - - for (var i = 0, char = string.charAt(i); i < string.length; i += getCharLength(char)) { - length++; - } - - return length; -} - -/** - * Get the offset to the end of the first word in `text`. - * - * @param {String} text - * @return {Number} - */ - -function getWordOffset(text) { - var length = 0; - var i = 0; - var started = false; - var char = void 0; - - while (char = text.charAt(i)) { - var l = getCharLength(char); - var rest = text.slice(i + l); - - if (isWord(char, rest)) { - started = true; - length++; - } else if (!started) { - length++; - } else { - break; - } - - i += l; - } - - return length; -} - -/** - * Get the offset to the end of the word before an `offset` in `text`. - * - * @param {String} text - * @param {Number} offset - * @return {Number} - */ - -function getWordOffsetBackward(text, offset) { - text = text.slice(0, offset); - text = (0, _esrever.reverse)(text); - return getWordOffset(text); -} - -/** - * Get the offset to the end of the word after an `offset` in `text`. - * - * @param {String} text - * @param {Number} offset - * @return {Number} - */ - -function getWordOffsetForward(text, offset) { - text = text.slice(offset); - return getWordOffset(text); -} - -/** - * Export. - */ - -exports.default = { - getCharOffsetForward: getCharOffsetForward, - getCharOffsetBackward: getCharOffsetBackward, - getWordOffsetBackward: getWordOffsetBackward, - getWordOffsetForward: getWordOffsetForward -}; -},{"esrever":80}],30:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _uid = require('uid'); - -var _uid2 = _interopRequireDefault(_uid); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * Create a unique identifier. - * - * @return {String} uid - */ - -function uid() { - return (0, _uid2.default)(4); -} - -/** - * Export. - */ - -exports.default = uid; -},{"uid":377}],31:[function(require,module,exports){ -'use strict' - -exports.toByteArray = toByteArray -exports.fromByteArray = fromByteArray - -var lookup = [] -var revLookup = [] -var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array - -function init () { - var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' - for (var i = 0, len = code.length; i < len; ++i) { - lookup[i] = code[i] - revLookup[code.charCodeAt(i)] = i - } - - revLookup['-'.charCodeAt(0)] = 62 - revLookup['_'.charCodeAt(0)] = 63 -} - -init() - -function toByteArray (b64) { - var i, j, l, tmp, placeHolders, arr - var len = b64.length - - if (len % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') - } - - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 - - // base64 is 4/3 + up to two characters of the original data - arr = new Arr(len * 3 / 4 - placeHolders) - - // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? len - 4 : len - - var L = 0 - - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] - arr[L++] = (tmp >> 16) & 0xFF - arr[L++] = (tmp >> 8) & 0xFF - arr[L++] = tmp & 0xFF - } - - if (placeHolders === 2) { - tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) - arr[L++] = tmp & 0xFF - } else if (placeHolders === 1) { - tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) - arr[L++] = (tmp >> 8) & 0xFF - arr[L++] = tmp & 0xFF - } - - return arr -} - -function tripletToBase64 (num) { - return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] -} - -function encodeChunk (uint8, start, end) { - var tmp - var output = [] - for (var i = start; i < end; i += 3) { - tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) - output.push(tripletToBase64(tmp)) - } - return output.join('') -} - -function fromByteArray (uint8) { - var tmp - var len = uint8.length - var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes - var output = '' - var parts = [] - var maxChunkLength = 16383 // must be multiple of 3 - - // go through the array every three bytes, we'll deal with trailing stuff later - for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) - } - - // pad the end with zeros, but make sure to not forget the extra bytes - if (extraBytes === 1) { - tmp = uint8[len - 1] - output += lookup[tmp >> 2] - output += lookup[(tmp << 4) & 0x3F] - output += '==' - } else if (extraBytes === 2) { - tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) - output += lookup[tmp >> 10] - output += lookup[(tmp >> 4) & 0x3F] - output += lookup[(tmp << 2) & 0x3F] - output += '=' - } - - parts.push(output) - - return parts.join('') -} - -},{}],32:[function(require,module,exports){ -module.exports = { - trueFunc: function trueFunc(){ - return true; - }, - falseFunc: function falseFunc(){ - return false; - } -}; -},{}],33:[function(require,module,exports){ - -},{}],34:[function(require,module,exports){ -(function (global){ -'use strict'; - -var buffer = require('buffer'); -var Buffer = buffer.Buffer; -var SlowBuffer = buffer.SlowBuffer; -var MAX_LEN = buffer.kMaxLength || 2147483647; -exports.alloc = function alloc(size, fill, encoding) { - if (typeof Buffer.alloc === 'function') { - return Buffer.alloc(size, fill, encoding); - } - if (typeof encoding === 'number') { - throw new TypeError('encoding must not be number'); - } - if (typeof size !== 'number') { - throw new TypeError('size must be a number'); - } - if (size > MAX_LEN) { - throw new RangeError('size is too large'); - } - var enc = encoding; - var _fill = fill; - if (_fill === undefined) { - enc = undefined; - _fill = 0; - } - var buf = new Buffer(size); - if (typeof _fill === 'string') { - var fillBuf = new Buffer(_fill, enc); - var flen = fillBuf.length; - var i = -1; - while (++i < size) { - buf[i] = fillBuf[i % flen]; - } - } else { - buf.fill(_fill); - } - return buf; -} -exports.allocUnsafe = function allocUnsafe(size) { - if (typeof Buffer.allocUnsafe === 'function') { - return Buffer.allocUnsafe(size); - } - if (typeof size !== 'number') { - throw new TypeError('size must be a number'); - } - if (size > MAX_LEN) { - throw new RangeError('size is too large'); - } - return new Buffer(size); -} -exports.from = function from(value, encodingOrOffset, length) { - if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) { - return Buffer.from(value, encodingOrOffset, length); - } - if (typeof value === 'number') { - throw new TypeError('"value" argument must not be a number'); - } - if (typeof value === 'string') { - return new Buffer(value, encodingOrOffset); - } - if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { - var offset = encodingOrOffset; - if (arguments.length === 1) { - return new Buffer(value); - } - if (typeof offset === 'undefined') { - offset = 0; - } - var len = length; - if (typeof len === 'undefined') { - len = value.byteLength - offset; - } - if (offset >= value.byteLength) { - throw new RangeError('\'offset\' is out of bounds'); - } - if (len > value.byteLength - offset) { - throw new RangeError('\'length\' is out of bounds'); - } - return new Buffer(value.slice(offset, offset + len)); - } - if (Buffer.isBuffer(value)) { - var out = new Buffer(value.length); - value.copy(out, 0, 0, value.length); - return out; - } - if (value) { - if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) { - return new Buffer(value); - } - if (value.type === 'Buffer' && Array.isArray(value.data)) { - return new Buffer(value.data); - } - } - - throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.'); -} -exports.allocUnsafeSlow = function allocUnsafeSlow(size) { - if (typeof Buffer.allocUnsafeSlow === 'function') { - return Buffer.allocUnsafeSlow(size); - } - if (typeof size !== 'number') { - throw new TypeError('size must be a number'); - } - if (size >= MAX_LEN) { - throw new RangeError('size is too large'); - } - return new SlowBuffer(size); -} - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"buffer":35}],35:[function(require,module,exports){ -(function (global){ -/*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ -/* eslint-disable no-proto */ - -'use strict' - -var base64 = require('base64-js') -var ieee754 = require('ieee754') -var isArray = require('isarray') - -exports.Buffer = Buffer -exports.SlowBuffer = SlowBuffer -exports.INSPECT_MAX_BYTES = 50 - -/** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * Due to various browser bugs, sometimes the Object implementation will be used even - * when the browser supports typed arrays. - * - * Note: - * - * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. - - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they - * get the Object implementation, which is slower but behaves correctly. - */ -Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined - ? global.TYPED_ARRAY_SUPPORT - : typedArraySupport() - -/* - * Export kMaxLength after typed array support is determined. - */ -exports.kMaxLength = kMaxLength() - -function typedArraySupport () { - try { - var arr = new Uint8Array(1) - arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} - return arr.foo() === 42 && // typed array instances can be augmented - typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` - } catch (e) { - return false - } -} - -function kMaxLength () { - return Buffer.TYPED_ARRAY_SUPPORT - ? 0x7fffffff - : 0x3fffffff -} - -function createBuffer (that, length) { - if (kMaxLength() < length) { - throw new RangeError('Invalid typed array length') - } - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = new Uint8Array(length) - that.__proto__ = Buffer.prototype - } else { - // Fallback: Return an object instance of the Buffer class - if (that === null) { - that = new Buffer(length) - } - that.length = length - } - - return that -} - -/** - * The Buffer constructor returns instances of `Uint8Array` that have their - * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of - * `Uint8Array`, so the returned instances will have all the node `Buffer` methods - * and the `Uint8Array` methods. Square bracket notation works as expected -- it - * returns a single octet. - * - * The `Uint8Array` prototype remains unmodified. - */ - -function Buffer (arg, encodingOrOffset, length) { - if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { - return new Buffer(arg, encodingOrOffset, length) - } - - // Common case. - if (typeof arg === 'number') { - if (typeof encodingOrOffset === 'string') { - throw new Error( - 'If encoding is specified then the first argument must be a string' - ) - } - return allocUnsafe(this, arg) - } - return from(this, arg, encodingOrOffset, length) -} - -Buffer.poolSize = 8192 // not used by this implementation - -// TODO: Legacy, not needed anymore. Remove in next major version. -Buffer._augment = function (arr) { - arr.__proto__ = Buffer.prototype - return arr -} - -function from (that, value, encodingOrOffset, length) { - if (typeof value === 'number') { - throw new TypeError('"value" argument must not be a number') - } - - if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { - return fromArrayBuffer(that, value, encodingOrOffset, length) - } - - if (typeof value === 'string') { - return fromString(that, value, encodingOrOffset) - } - - return fromObject(that, value) -} - -/** - * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError - * if value is a number. - * Buffer.from(str[, encoding]) - * Buffer.from(array) - * Buffer.from(buffer) - * Buffer.from(arrayBuffer[, byteOffset[, length]]) - **/ -Buffer.from = function (value, encodingOrOffset, length) { - return from(null, value, encodingOrOffset, length) -} - -if (Buffer.TYPED_ARRAY_SUPPORT) { - Buffer.prototype.__proto__ = Uint8Array.prototype - Buffer.__proto__ = Uint8Array - if (typeof Symbol !== 'undefined' && Symbol.species && - Buffer[Symbol.species] === Buffer) { - // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 - Object.defineProperty(Buffer, Symbol.species, { - value: null, - configurable: true - }) - } -} - -function assertSize (size) { - if (typeof size !== 'number') { - throw new TypeError('"size" argument must be a number') - } -} - -function alloc (that, size, fill, encoding) { - assertSize(size) - if (size <= 0) { - return createBuffer(that, size) - } - if (fill !== undefined) { - // Only pay attention to encoding if it's a string. This - // prevents accidentally sending in a number that would - // be interpretted as a start offset. - return typeof encoding === 'string' - ? createBuffer(that, size).fill(fill, encoding) - : createBuffer(that, size).fill(fill) - } - return createBuffer(that, size) -} - -/** - * Creates a new filled Buffer instance. - * alloc(size[, fill[, encoding]]) - **/ -Buffer.alloc = function (size, fill, encoding) { - return alloc(null, size, fill, encoding) -} - -function allocUnsafe (that, size) { - assertSize(size) - that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < size; ++i) { - that[i] = 0 - } - } - return that -} - -/** - * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. - * */ -Buffer.allocUnsafe = function (size) { - return allocUnsafe(null, size) -} -/** - * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. - */ -Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(null, size) -} - -function fromString (that, string, encoding) { - if (typeof encoding !== 'string' || encoding === '') { - encoding = 'utf8' - } - - if (!Buffer.isEncoding(encoding)) { - throw new TypeError('"encoding" must be a valid string encoding') - } - - var length = byteLength(string, encoding) | 0 - that = createBuffer(that, length) - - that.write(string, encoding) - return that -} - -function fromArrayLike (that, array) { - var length = checked(array.length) | 0 - that = createBuffer(that, length) - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 - } - return that -} - -function fromArrayBuffer (that, array, byteOffset, length) { - array.byteLength // this throws if `array` is not a valid ArrayBuffer - - if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError('\'offset\' is out of bounds') - } - - if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('\'length\' is out of bounds') - } - - if (byteOffset === undefined && length === undefined) { - array = new Uint8Array(array) - } else if (length === undefined) { - array = new Uint8Array(array, byteOffset) - } else { - array = new Uint8Array(array, byteOffset, length) - } - - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = array - that.__proto__ = Buffer.prototype - } else { - // Fallback: Return an object instance of the Buffer class - that = fromArrayLike(that, array) - } - return that -} - -function fromObject (that, obj) { - if (Buffer.isBuffer(obj)) { - var len = checked(obj.length) | 0 - that = createBuffer(that, len) - - if (that.length === 0) { - return that - } - - obj.copy(that, 0, 0, len) - return that - } - - if (obj) { - if ((typeof ArrayBuffer !== 'undefined' && - obj.buffer instanceof ArrayBuffer) || 'length' in obj) { - if (typeof obj.length !== 'number' || isnan(obj.length)) { - return createBuffer(that, 0) - } - return fromArrayLike(that, obj) - } - - if (obj.type === 'Buffer' && isArray(obj.data)) { - return fromArrayLike(that, obj.data) - } - } - - throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') -} - -function checked (length) { - // Note: cannot use `length < kMaxLength` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength()) { - throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength().toString(16) + ' bytes') - } - return length | 0 -} - -function SlowBuffer (length) { - if (+length != length) { // eslint-disable-line eqeqeq - length = 0 - } - return Buffer.alloc(+length) -} - -Buffer.isBuffer = function isBuffer (b) { - return !!(b != null && b._isBuffer) -} - -Buffer.compare = function compare (a, b) { - if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { - throw new TypeError('Arguments must be Buffers') - } - - if (a === b) return 0 - - var x = a.length - var y = b.length - - for (var i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i] - y = b[i] - break - } - } - - if (x < y) return -1 - if (y < x) return 1 - return 0 -} - -Buffer.isEncoding = function isEncoding (encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'binary': - case 'base64': - case 'raw': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true - default: - return false - } -} - -Buffer.concat = function concat (list, length) { - if (!isArray(list)) { - throw new TypeError('"list" argument must be an Array of Buffers') - } - - if (list.length === 0) { - return Buffer.alloc(0) - } - - var i - if (length === undefined) { - length = 0 - for (i = 0; i < list.length; ++i) { - length += list[i].length - } - } - - var buffer = Buffer.allocUnsafe(length) - var pos = 0 - for (i = 0; i < list.length; ++i) { - var buf = list[i] - if (!Buffer.isBuffer(buf)) { - throw new TypeError('"list" argument must be an Array of Buffers') - } - buf.copy(buffer, pos) - pos += buf.length - } - return buffer -} - -function byteLength (string, encoding) { - if (Buffer.isBuffer(string)) { - return string.length - } - if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && - (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { - return string.byteLength - } - if (typeof string !== 'string') { - string = '' + string - } - - var len = string.length - if (len === 0) return 0 - - // Use a for loop to avoid recursion - var loweredCase = false - for (;;) { - switch (encoding) { - case 'ascii': - case 'binary': - case 'raw': - case 'raws': - return len - case 'utf8': - case 'utf-8': - case undefined: - return utf8ToBytes(string).length - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return len * 2 - case 'hex': - return len >>> 1 - case 'base64': - return base64ToBytes(string).length - default: - if (loweredCase) return utf8ToBytes(string).length // assume utf8 - encoding = ('' + encoding).toLowerCase() - loweredCase = true - } - } -} -Buffer.byteLength = byteLength - -function slowToString (encoding, start, end) { - var loweredCase = false - - // No need to verify that "this.length <= MAX_UINT32" since it's a read-only - // property of a typed array. - - // This behaves neither like String nor Uint8Array in that we set start/end - // to their upper/lower bounds if the value passed is out of range. - // undefined is handled specially as per ECMA-262 6th Edition, - // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. - if (start === undefined || start < 0) { - start = 0 - } - // Return early if start > this.length. Done here to prevent potential uint32 - // coercion fail below. - if (start > this.length) { - return '' - } - - if (end === undefined || end > this.length) { - end = this.length - } - - if (end <= 0) { - return '' - } - - // Force coersion to uint32. This will also coerce falsey/NaN values to 0. - end >>>= 0 - start >>>= 0 - - if (end <= start) { - return '' - } - - if (!encoding) encoding = 'utf8' - - while (true) { - switch (encoding) { - case 'hex': - return hexSlice(this, start, end) - - case 'utf8': - case 'utf-8': - return utf8Slice(this, start, end) - - case 'ascii': - return asciiSlice(this, start, end) - - case 'binary': - return binarySlice(this, start, end) - - case 'base64': - return base64Slice(this, start, end) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return utf16leSlice(this, start, end) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = (encoding + '').toLowerCase() - loweredCase = true - } - } -} - -// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect -// Buffer instances. -Buffer.prototype._isBuffer = true - -function swap (b, n, m) { - var i = b[n] - b[n] = b[m] - b[m] = i -} - -Buffer.prototype.swap16 = function swap16 () { - var len = this.length - if (len % 2 !== 0) { - throw new RangeError('Buffer size must be a multiple of 16-bits') - } - for (var i = 0; i < len; i += 2) { - swap(this, i, i + 1) - } - return this -} - -Buffer.prototype.swap32 = function swap32 () { - var len = this.length - if (len % 4 !== 0) { - throw new RangeError('Buffer size must be a multiple of 32-bits') - } - for (var i = 0; i < len; i += 4) { - swap(this, i, i + 3) - swap(this, i + 1, i + 2) - } - return this -} - -Buffer.prototype.toString = function toString () { - var length = this.length | 0 - if (length === 0) return '' - if (arguments.length === 0) return utf8Slice(this, 0, length) - return slowToString.apply(this, arguments) -} - -Buffer.prototype.equals = function equals (b) { - if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') - if (this === b) return true - return Buffer.compare(this, b) === 0 -} - -Buffer.prototype.inspect = function inspect () { - var str = '' - var max = exports.INSPECT_MAX_BYTES - if (this.length > 0) { - str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') - if (this.length > max) str += ' ... ' - } - return '' -} - -Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { - if (!Buffer.isBuffer(target)) { - throw new TypeError('Argument must be a Buffer') - } - - if (start === undefined) { - start = 0 - } - if (end === undefined) { - end = target ? target.length : 0 - } - if (thisStart === undefined) { - thisStart = 0 - } - if (thisEnd === undefined) { - thisEnd = this.length - } - - if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { - throw new RangeError('out of range index') - } - - if (thisStart >= thisEnd && start >= end) { - return 0 - } - if (thisStart >= thisEnd) { - return -1 - } - if (start >= end) { - return 1 - } - - start >>>= 0 - end >>>= 0 - thisStart >>>= 0 - thisEnd >>>= 0 - - if (this === target) return 0 - - var x = thisEnd - thisStart - var y = end - start - var len = Math.min(x, y) - - var thisCopy = this.slice(thisStart, thisEnd) - var targetCopy = target.slice(start, end) - - for (var i = 0; i < len; ++i) { - if (thisCopy[i] !== targetCopy[i]) { - x = thisCopy[i] - y = targetCopy[i] - break - } - } - - if (x < y) return -1 - if (y < x) return 1 - return 0 -} - -function arrayIndexOf (arr, val, byteOffset, encoding) { - var indexSize = 1 - var arrLength = arr.length - var valLength = val.length - - if (encoding !== undefined) { - encoding = String(encoding).toLowerCase() - if (encoding === 'ucs2' || encoding === 'ucs-2' || - encoding === 'utf16le' || encoding === 'utf-16le') { - if (arr.length < 2 || val.length < 2) { - return -1 - } - indexSize = 2 - arrLength /= 2 - valLength /= 2 - byteOffset /= 2 - } - } - - function read (buf, i) { - if (indexSize === 1) { - return buf[i] - } else { - return buf.readUInt16BE(i * indexSize) - } - } - - var foundIndex = -1 - for (var i = byteOffset; i < arrLength; ++i) { - if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { - if (foundIndex === -1) foundIndex = i - if (i - foundIndex + 1 === valLength) return foundIndex * indexSize - } else { - if (foundIndex !== -1) i -= i - foundIndex - foundIndex = -1 - } - } - - return -1 -} - -Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { - if (typeof byteOffset === 'string') { - encoding = byteOffset - byteOffset = 0 - } else if (byteOffset > 0x7fffffff) { - byteOffset = 0x7fffffff - } else if (byteOffset < -0x80000000) { - byteOffset = -0x80000000 - } - byteOffset >>= 0 - - if (this.length === 0) return -1 - if (byteOffset >= this.length) return -1 - - // Negative offsets start from the end of the buffer - if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0) - - if (typeof val === 'string') { - val = Buffer.from(val, encoding) - } - - if (Buffer.isBuffer(val)) { - // special case: looking for empty string/buffer always fails - if (val.length === 0) { - return -1 - } - return arrayIndexOf(this, val, byteOffset, encoding) - } - if (typeof val === 'number') { - if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') { - return Uint8Array.prototype.indexOf.call(this, val, byteOffset) - } - return arrayIndexOf(this, [ val ], byteOffset, encoding) - } - - throw new TypeError('val must be string, number or Buffer') -} - -Buffer.prototype.includes = function includes (val, byteOffset, encoding) { - return this.indexOf(val, byteOffset, encoding) !== -1 -} - -function hexWrite (buf, string, offset, length) { - offset = Number(offset) || 0 - var remaining = buf.length - offset - if (!length) { - length = remaining - } else { - length = Number(length) - if (length > remaining) { - length = remaining - } - } - - // must be an even number of digits - var strLen = string.length - if (strLen % 2 !== 0) throw new Error('Invalid hex string') - - if (length > strLen / 2) { - length = strLen / 2 - } - for (var i = 0; i < length; ++i) { - var parsed = parseInt(string.substr(i * 2, 2), 16) - if (isNaN(parsed)) return i - buf[offset + i] = parsed - } - return i -} - -function utf8Write (buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) -} - -function asciiWrite (buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length) -} - -function binaryWrite (buf, string, offset, length) { - return asciiWrite(buf, string, offset, length) -} - -function base64Write (buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length) -} - -function ucs2Write (buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) -} - -Buffer.prototype.write = function write (string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = 'utf8' - length = this.length - offset = 0 - // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === 'string') { - encoding = offset - length = this.length - offset = 0 - // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset | 0 - if (isFinite(length)) { - length = length | 0 - if (encoding === undefined) encoding = 'utf8' - } else { - encoding = length - length = undefined - } - // legacy write(string, encoding, offset, length) - remove in v0.13 - } else { - throw new Error( - 'Buffer.write(string, encoding, offset[, length]) is no longer supported' - ) - } - - var remaining = this.length - offset - if (length === undefined || length > remaining) length = remaining - - if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { - throw new RangeError('Attempt to write outside buffer bounds') - } - - if (!encoding) encoding = 'utf8' - - var loweredCase = false - for (;;) { - switch (encoding) { - case 'hex': - return hexWrite(this, string, offset, length) - - case 'utf8': - case 'utf-8': - return utf8Write(this, string, offset, length) - - case 'ascii': - return asciiWrite(this, string, offset, length) - - case 'binary': - return binaryWrite(this, string, offset, length) - - case 'base64': - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return ucs2Write(this, string, offset, length) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = ('' + encoding).toLowerCase() - loweredCase = true - } - } -} - -Buffer.prototype.toJSON = function toJSON () { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) - } -} - -function base64Slice (buf, start, end) { - if (start === 0 && end === buf.length) { - return base64.fromByteArray(buf) - } else { - return base64.fromByteArray(buf.slice(start, end)) - } -} - -function utf8Slice (buf, start, end) { - end = Math.min(buf.length, end) - var res = [] - - var i = start - while (i < end) { - var firstByte = buf[i] - var codePoint = null - var bytesPerSequence = (firstByte > 0xEF) ? 4 - : (firstByte > 0xDF) ? 3 - : (firstByte > 0xBF) ? 2 - : 1 - - if (i + bytesPerSequence <= end) { - var secondByte, thirdByte, fourthByte, tempCodePoint - - switch (bytesPerSequence) { - case 1: - if (firstByte < 0x80) { - codePoint = firstByte - } - break - case 2: - secondByte = buf[i + 1] - if ((secondByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) - if (tempCodePoint > 0x7F) { - codePoint = tempCodePoint - } - } - break - case 3: - secondByte = buf[i + 1] - thirdByte = buf[i + 2] - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) - if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { - codePoint = tempCodePoint - } - } - break - case 4: - secondByte = buf[i + 1] - thirdByte = buf[i + 2] - fourthByte = buf[i + 3] - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) - if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { - codePoint = tempCodePoint - } - } - } - } - - if (codePoint === null) { - // we did not generate a valid codePoint so insert a - // replacement char (U+FFFD) and advance only 1 byte - codePoint = 0xFFFD - bytesPerSequence = 1 - } else if (codePoint > 0xFFFF) { - // encode to utf16 (surrogate pair dance) - codePoint -= 0x10000 - res.push(codePoint >>> 10 & 0x3FF | 0xD800) - codePoint = 0xDC00 | codePoint & 0x3FF - } - - res.push(codePoint) - i += bytesPerSequence - } - - return decodeCodePointsArray(res) -} - -// Based on http://stackoverflow.com/a/22747272/680742, the browser with -// the lowest limit is Chrome, with 0x10000 args. -// We go 1 magnitude less, for safety -var MAX_ARGUMENTS_LENGTH = 0x1000 - -function decodeCodePointsArray (codePoints) { - var len = codePoints.length - if (len <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, codePoints) // avoid extra slice() - } - - // Decode in chunks to avoid "call stack size exceeded". - var res = '' - var i = 0 - while (i < len) { - res += String.fromCharCode.apply( - String, - codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) - ) - } - return res -} - -function asciiSlice (buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i] & 0x7F) - } - return ret -} - -function binarySlice (buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i]) - } - return ret -} - -function hexSlice (buf, start, end) { - var len = buf.length - - if (!start || start < 0) start = 0 - if (!end || end < 0 || end > len) end = len - - var out = '' - for (var i = start; i < end; ++i) { - out += toHex(buf[i]) - } - return out -} - -function utf16leSlice (buf, start, end) { - var bytes = buf.slice(start, end) - var res = '' - for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) - } - return res -} - -Buffer.prototype.slice = function slice (start, end) { - var len = this.length - start = ~~start - end = end === undefined ? len : ~~end - - if (start < 0) { - start += len - if (start < 0) start = 0 - } else if (start > len) { - start = len - } - - if (end < 0) { - end += len - if (end < 0) end = 0 - } else if (end > len) { - end = len - } - - if (end < start) end = start - - var newBuf - if (Buffer.TYPED_ARRAY_SUPPORT) { - newBuf = this.subarray(start, end) - newBuf.__proto__ = Buffer.prototype - } else { - var sliceLen = end - start - newBuf = new Buffer(sliceLen, undefined) - for (var i = 0; i < sliceLen; ++i) { - newBuf[i] = this[i + start] - } - } - - return newBuf -} - -/* - * Need to make sure that buffer isn't trying to write out of bounds. - */ -function checkOffset (offset, ext, length) { - if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') - if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') -} - -Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul - } - - return val -} - -Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) { - checkOffset(offset, byteLength, this.length) - } - - var val = this[offset + --byteLength] - var mul = 1 - while (byteLength > 0 && (mul *= 0x100)) { - val += this[offset + --byteLength] * mul - } - - return val -} - -Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length) - return this[offset] -} - -Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - return this[offset] | (this[offset + 1] << 8) -} - -Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - return (this[offset] << 8) | this[offset + 1] -} - -Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - - return ((this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16)) + - (this[offset + 3] * 0x1000000) -} - -Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset] * 0x1000000) + - ((this[offset + 1] << 16) | - (this[offset + 2] << 8) | - this[offset + 3]) -} - -Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul - } - mul *= 0x80 - - if (val >= mul) val -= Math.pow(2, 8 * byteLength) - - return val -} - -Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var i = byteLength - var mul = 1 - var val = this[offset + --i] - while (i > 0 && (mul *= 0x100)) { - val += this[offset + --i] * mul - } - mul *= 0x80 - - if (val >= mul) val -= Math.pow(2, 8 * byteLength) - - return val -} - -Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length) - if (!(this[offset] & 0x80)) return (this[offset]) - return ((0xff - this[offset] + 1) * -1) -} - -Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset] | (this[offset + 1] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val -} - -Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset + 1] | (this[offset] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val -} - -Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16) | - (this[offset + 3] << 24) -} - -Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset] << 24) | - (this[offset + 1] << 16) | - (this[offset + 2] << 8) | - (this[offset + 3]) -} - -Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, true, 23, 4) -} - -Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, false, 23, 4) -} - -Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, true, 52, 8) -} - -Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, false, 52, 8) -} - -function checkInt (buf, value, offset, ext, max, min) { - if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') - if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') - if (offset + ext > buf.length) throw new RangeError('Index out of range') -} - -Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1 - checkInt(this, value, offset, byteLength, maxBytes, 0) - } - - var mul = 1 - var i = 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1 - checkInt(this, value, offset, byteLength, maxBytes, 0) - } - - var i = byteLength - 1 - var mul = 1 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - this[offset] = (value & 0xff) - return offset + 1 -} - -function objectWriteUInt16 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { - buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8 - } -} - -Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } - return offset + 2 -} - -Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) - } - return offset + 2 -} - -function objectWriteUInt32 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffffffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { - buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff - } -} - -Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset + 3] = (value >>> 24) - this[offset + 2] = (value >>> 16) - this[offset + 1] = (value >>> 8) - this[offset] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, true) - } - return offset + 4 -} - -Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } - return offset + 4 -} - -Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) - - checkInt(this, value, offset, byteLength, limit - 1, -limit) - } - - var i = 0 - var mul = 1 - var sub = 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { - sub = 1 - } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) - - checkInt(this, value, offset, byteLength, limit - 1, -limit) - } - - var i = byteLength - 1 - var mul = 1 - var sub = 0 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { - sub = 1 - } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - if (value < 0) value = 0xff + value + 1 - this[offset] = (value & 0xff) - return offset + 1 -} - -Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } - return offset + 2 -} - -Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) - } - return offset + 2 -} - -Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - this[offset + 2] = (value >>> 16) - this[offset + 3] = (value >>> 24) - } else { - objectWriteUInt32(this, value, offset, true) - } - return offset + 4 -} - -Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (value < 0) value = 0xffffffff + value + 1 - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } - return offset + 4 -} - -function checkIEEE754 (buf, value, offset, ext, max, min) { - if (offset + ext > buf.length) throw new RangeError('Index out of range') - if (offset < 0) throw new RangeError('Index out of range') -} - -function writeFloat (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) - } - ieee754.write(buf, value, offset, littleEndian, 23, 4) - return offset + 4 -} - -Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert) -} - -function writeDouble (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) - } - ieee754.write(buf, value, offset, littleEndian, 52, 8) - return offset + 8 -} - -Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert) -} - -// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) -Buffer.prototype.copy = function copy (target, targetStart, start, end) { - if (!start) start = 0 - if (!end && end !== 0) end = this.length - if (targetStart >= target.length) targetStart = target.length - if (!targetStart) targetStart = 0 - if (end > 0 && end < start) end = start - - // Copy 0 bytes; we're done - if (end === start) return 0 - if (target.length === 0 || this.length === 0) return 0 - - // Fatal error conditions - if (targetStart < 0) { - throw new RangeError('targetStart out of bounds') - } - if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') - if (end < 0) throw new RangeError('sourceEnd out of bounds') - - // Are we oob? - if (end > this.length) end = this.length - if (target.length - targetStart < end - start) { - end = target.length - targetStart + start - } - - var len = end - start - var i - - if (this === target && start < targetStart && targetStart < end) { - // descending copy from end - for (i = len - 1; i >= 0; --i) { - target[i + targetStart] = this[i + start] - } - } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { - // ascending copy from start - for (i = 0; i < len; ++i) { - target[i + targetStart] = this[i + start] - } - } else { - Uint8Array.prototype.set.call( - target, - this.subarray(start, start + len), - targetStart - ) - } - - return len -} - -// Usage: -// buffer.fill(number[, offset[, end]]) -// buffer.fill(buffer[, offset[, end]]) -// buffer.fill(string[, offset[, end]][, encoding]) -Buffer.prototype.fill = function fill (val, start, end, encoding) { - // Handle string cases: - if (typeof val === 'string') { - if (typeof start === 'string') { - encoding = start - start = 0 - end = this.length - } else if (typeof end === 'string') { - encoding = end - end = this.length - } - if (val.length === 1) { - var code = val.charCodeAt(0) - if (code < 256) { - val = code - } - } - if (encoding !== undefined && typeof encoding !== 'string') { - throw new TypeError('encoding must be a string') - } - if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding) - } - } else if (typeof val === 'number') { - val = val & 255 - } - - // Invalid ranges are not set to a default, so can range check early. - if (start < 0 || this.length < start || this.length < end) { - throw new RangeError('Out of range index') - } - - if (end <= start) { - return this - } - - start = start >>> 0 - end = end === undefined ? this.length : end >>> 0 - - if (!val) val = 0 - - var i - if (typeof val === 'number') { - for (i = start; i < end; ++i) { - this[i] = val - } - } else { - var bytes = Buffer.isBuffer(val) - ? val - : utf8ToBytes(new Buffer(val, encoding).toString()) - var len = bytes.length - for (i = 0; i < end - start; ++i) { - this[i + start] = bytes[i % len] - } - } - - return this -} - -// HELPER FUNCTIONS -// ================ - -var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g - -function base64clean (str) { - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = stringtrim(str).replace(INVALID_BASE64_RE, '') - // Node converts strings with length < 2 to '' - if (str.length < 2) return '' - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '=' - } - return str -} - -function stringtrim (str) { - if (str.trim) return str.trim() - return str.replace(/^\s+|\s+$/g, '') -} - -function toHex (n) { - if (n < 16) return '0' + n.toString(16) - return n.toString(16) -} - -function utf8ToBytes (string, units) { - units = units || Infinity - var codePoint - var length = string.length - var leadSurrogate = null - var bytes = [] - - for (var i = 0; i < length; ++i) { - codePoint = string.charCodeAt(i) - - // is surrogate component - if (codePoint > 0xD7FF && codePoint < 0xE000) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 0xDBFF) { - // unexpected trail - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue - } - - // valid lead - leadSurrogate = codePoint - - continue - } - - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = codePoint - continue - } - - // valid surrogate pair - codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - } - - leadSurrogate = null - - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) break - bytes.push(codePoint) - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) break - bytes.push( - codePoint >> 0x6 | 0xC0, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) break - bytes.push( - codePoint >> 0xC | 0xE0, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x110000) { - if ((units -= 4) < 0) break - bytes.push( - codePoint >> 0x12 | 0xF0, - codePoint >> 0xC & 0x3F | 0x80, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else { - throw new Error('Invalid code point') - } - } - - return bytes -} - -function asciiToBytes (str) { - var byteArray = [] - for (var i = 0; i < str.length; ++i) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 0xFF) - } - return byteArray -} - -function utf16leToBytes (str, units) { - var c, hi, lo - var byteArray = [] - for (var i = 0; i < str.length; ++i) { - if ((units -= 2) < 0) break - - c = str.charCodeAt(i) - hi = c >> 8 - lo = c % 256 - byteArray.push(lo) - byteArray.push(hi) - } - - return byteArray -} - -function base64ToBytes (str) { - return base64.toByteArray(base64clean(str)) -} - -function blitBuffer (src, dst, offset, length) { - for (var i = 0; i < length; ++i) { - if ((i + offset >= dst.length) || (i >= src.length)) break - dst[i + offset] = src[i] - } - return i -} - -function isnan (val) { - return val !== val // eslint-disable-line no-self-compare -} - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"base64-js":31,"ieee754":121,"isarray":36}],36:[function(require,module,exports){ -var toString = {}.toString; - -module.exports = Array.isArray || function (arr) { - return toString.call(arr) == '[object Array]'; -}; - -},{}],37:[function(require,module,exports){ -/** - * Export cheerio (with ) - */ - -exports = module.exports = require('./lib/cheerio'); - -/* - Export the version -*/ - -exports.version = require('./package').version; - -},{"./lib/cheerio":43,"./package":47}],38:[function(require,module,exports){ -var _ = require('lodash'), - $ = require('../static'), - utils = require('../utils'), - isTag = utils.isTag, - domEach = utils.domEach, - hasOwn = Object.prototype.hasOwnProperty, - camelCase = utils.camelCase, - cssCase = utils.cssCase, - rspace = /\s+/, - dataAttrPrefix = 'data-', - - // Lookup table for coercing string data-* attributes to their corresponding - // JavaScript primitives - primitives = { - null: null, - true: true, - false: false - }, - - // Attributes that are booleans - rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i, - // Matches strings that look like JSON objects or arrays - rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/; - - -var getAttr = function(elem, name) { - if (!elem || !isTag(elem)) return; - - if (!elem.attribs) { - elem.attribs = {}; - } - - // Return the entire attribs object if no attribute specified - if (!name) { - return elem.attribs; - } - - if (hasOwn.call(elem.attribs, name)) { - // Get the (decoded) attribute - return rboolean.test(name) ? name : elem.attribs[name]; - } - - // Mimic the DOM and return text content as value for `option's` - if (elem.name === 'option' && name === 'value') { - return $.text(elem.children); - } -}; - -var setAttr = function(el, name, value) { - - if (value === null) { - removeAttribute(el, name); - } else { - el.attribs[name] = value+''; - } -}; - -exports.attr = function(name, value) { - // Set the value (with attr map support) - if (typeof name === 'object' || value !== undefined) { - if (typeof value === 'function') { - return domEach(this, function(i, el) { - setAttr(el, name, value.call(el, i, el.attribs[name])); - }); - } - return domEach(this, function(i, el) { - if (!isTag(el)) return; - - if (typeof name === 'object') { - _.each(name, function(value, name) { - setAttr(el, name, value); - }); - } else { - setAttr(el, name, value); - } - }); - } - - return getAttr(this[0], name); -}; - -var getProp = function (el, name) { - return el.hasOwnProperty(name) - ? el[name] - : rboolean.test(name) - ? getAttr(el, name) !== undefined - : getAttr(el, name); -}; - -var setProp = function (el, name, value) { - el[name] = rboolean.test(name) ? !!value : value; -}; - -exports.prop = function (name, value) { - var i = 0, - property; - - if (typeof name === 'string' && value === undefined) { - - switch (name) { - case 'style': - property = this.css(); - - _.each(property, function (v, p) { - property[i++] = p; - }); - - property.length = i; - - break; - case 'tagName': - case 'nodeName': - property = this[0].name.toUpperCase(); - break; - default: - property = getProp(this[0], name); - } - - return property; - } - - if (typeof name === 'object' || value !== undefined) { - - if (typeof value === 'function') { - return domEach(this, function(i, el) { - setProp(el, name, value.call(el, i, getProp(el, name))); - }); - } - - return domEach(this, function(i, el) { - if (!isTag(el)) return; - - if (typeof name === 'object') { - - _.each(name, function(val, name) { - setProp(el, name, val); - }); - - } else { - setProp(el, name, value); - } - }); - - } -}; - -var setData = function(el, name, value) { - if (!el.data) { - el.data = {}; - } - - if (typeof name === 'object') return _.extend(el.data, name); - if (typeof name === 'string' && value !== undefined) { - el.data[name] = value; - } else if (typeof name === 'object') { - _.exend(el.data, name); - } -}; - -// Read the specified attribute from the equivalent HTML5 `data-*` attribute, -// and (if present) cache the value in the node's internal data store. If no -// attribute name is specified, read *all* HTML5 `data-*` attributes in this -// manner. -var readData = function(el, name) { - var readAll = arguments.length === 1; - var domNames, domName, jsNames, jsName, value, idx, length; - - if (readAll) { - domNames = Object.keys(el.attribs).filter(function(attrName) { - return attrName.slice(0, dataAttrPrefix.length) === dataAttrPrefix; - }); - jsNames = domNames.map(function(domName) { - return camelCase(domName.slice(dataAttrPrefix.length)); - }); - } else { - domNames = [dataAttrPrefix + cssCase(name)]; - jsNames = [name]; - } - - for (idx = 0, length = domNames.length; idx < length; ++idx) { - domName = domNames[idx]; - jsName = jsNames[idx]; - if (hasOwn.call(el.attribs, domName)) { - value = el.attribs[domName]; - - if (hasOwn.call(primitives, value)) { - value = primitives[value]; - } else if (value === String(Number(value))) { - value = Number(value); - } else if (rbrace.test(value)) { - try { - value = JSON.parse(value); - } catch(e){ } - } - - el.data[jsName] = value; - } - } - - return readAll ? el.data : value; -}; - -exports.data = function(name, value) { - var elem = this[0]; - - if (!elem || !isTag(elem)) return; - - if (!elem.data) { - elem.data = {}; - } - - // Return the entire data object if no data specified - if (!name) { - return readData(elem); - } - - // Set the value (with attr map support) - if (typeof name === 'object' || value !== undefined) { - domEach(this, function(i, el) { - setData(el, name, value); - }); - return this; - } else if (hasOwn.call(elem.data, name)) { - return elem.data[name]; - } - - return readData(elem, name); -}; - -/** - * Get the value of an element - */ - -exports.val = function(value) { - var querying = arguments.length === 0, - element = this[0]; - - if(!element) return; - - switch (element.name) { - case 'textarea': - return this.text(value); - case 'input': - switch (this.attr('type')) { - case 'radio': - if (querying) { - return this.attr('value'); - } else { - this.attr('value', value); - return this; - } - break; - default: - return this.attr('value', value); - } - return; - case 'select': - var option = this.find('option:selected'), - returnValue; - if (option === undefined) return undefined; - if (!querying) { - if (!this.attr().hasOwnProperty('multiple') && typeof value == 'object') { - return this; - } - if (typeof value != 'object') { - value = [value]; - } - this.find('option').removeAttr('selected'); - for (var i = 0; i < value.length; i++) { - this.find('option[value="' + value[i] + '"]').attr('selected', ''); - } - return this; - } - returnValue = option.attr('value'); - if (this.attr().hasOwnProperty('multiple')) { - returnValue = []; - domEach(option, function(i, el) { - returnValue.push(getAttr(el, 'value')); - }); - } - return returnValue; - case 'option': - if (!querying) { - this.attr('value', value); - return this; - } - return this.attr('value'); - } -}; - -/** - * Remove an attribute - */ - -var removeAttribute = function(elem, name) { - if (!elem.attribs || !hasOwn.call(elem.attribs, name)) - return; - - delete elem.attribs[name]; -}; - - -exports.removeAttr = function(name) { - domEach(this, function(i, elem) { - removeAttribute(elem, name); - }); - - return this; -}; - -exports.hasClass = function(className) { - return _.some(this, function(elem) { - var attrs = elem.attribs, - clazz = attrs && attrs['class'], - idx = -1, - end; - - if (clazz) { - while ((idx = clazz.indexOf(className, idx+1)) > -1) { - end = idx + className.length; - - if ((idx === 0 || rspace.test(clazz[idx-1])) - && (end === clazz.length || rspace.test(clazz[end]))) { - return true; - } - } - } - }); -}; - -exports.addClass = function(value) { - // Support functions - if (typeof value === 'function') { - return domEach(this, function(i, el) { - var className = el.attribs['class'] || ''; - exports.addClass.call([el], value.call(el, i, className)); - }); - } - - // Return if no value or not a string or function - if (!value || typeof value !== 'string') return this; - - var classNames = value.split(rspace), - numElements = this.length; - - - for (var i = 0; i < numElements; i++) { - // If selected element isn't a tag, move on - if (!isTag(this[i])) continue; - - // If we don't already have classes - var className = getAttr(this[i], 'class'), - numClasses, - setClass; - - if (!className) { - setAttr(this[i], 'class', classNames.join(' ').trim()); - } else { - setClass = ' ' + className + ' '; - numClasses = classNames.length; - - // Check if class already exists - for (var j = 0; j < numClasses; j++) { - var appendClass = classNames[j] + ' '; - if (setClass.indexOf(' ' + appendClass) < 0) - setClass += appendClass; - } - - setAttr(this[i], 'class', setClass.trim()); - } - } - - return this; -}; - -var splitClass = function(className) { - return className ? className.trim().split(rspace) : []; -}; - -exports.removeClass = function(value) { - var classes, - numClasses, - removeAll; - - // Handle if value is a function - if (typeof value === 'function') { - return domEach(this, function(i, el) { - exports.removeClass.call( - [el], value.call(el, i, el.attribs['class'] || '') - ); - }); - } - - classes = splitClass(value); - numClasses = classes.length; - removeAll = arguments.length === 0; - - return domEach(this, function(i, el) { - if (!isTag(el)) return; - - if (removeAll) { - // Short circuit the remove all case as this is the nice one - el.attribs.class = ''; - } else { - var elClasses = splitClass(el.attribs.class), - index, - changed; - - for (var j = 0; j < numClasses; j++) { - index = elClasses.indexOf(classes[j]); - - if (index >= 0) { - elClasses.splice(index, 1); - changed = true; - - // We have to do another pass to ensure that there are not duplicate - // classes listed - j--; - } - } - if (changed) { - el.attribs.class = elClasses.join(' '); - } - } - }); -}; - -exports.toggleClass = function(value, stateVal) { - // Support functions - if (typeof value === 'function') { - return domEach(this, function(i, el) { - exports.toggleClass.call( - [el], - value.call(el, i, el.attribs['class'] || '', stateVal), - stateVal - ); - }); - } - - // Return if no value or not a string or function - if (!value || typeof value !== 'string') return this; - - var classNames = value.split(rspace), - numClasses = classNames.length, - state = typeof stateVal === 'boolean' ? stateVal ? 1 : -1 : 0, - numElements = this.length, - elementClasses, - index; - - for (var i = 0; i < numElements; i++) { - // If selected element isn't a tag, move on - if (!isTag(this[i])) continue; - - elementClasses = splitClass(this[i].attribs.class); - - // Check if class already exists - for (var j = 0; j < numClasses; j++) { - // Check if the class name is currently defined - index = elementClasses.indexOf(classNames[j]); - - // Add if stateValue === true or we are toggling and there is no value - if (state >= 0 && index < 0) { - elementClasses.push(classNames[j]); - } else if (state <= 0 && index >= 0) { - // Otherwise remove but only if the item exists - elementClasses.splice(index, 1); - } - } - - this[i].attribs.class = elementClasses.join(' '); - } - - return this; -}; - -exports.is = function (selector) { - if (selector) { - return this.filter(selector).length > 0; - } - return false; -}; - - -},{"../static":45,"../utils":46,"lodash":200}],39:[function(require,module,exports){ -var _ = require('lodash'), - domEach = require('../utils').domEach; -var toString = Object.prototype.toString; - -/** - * Set / Get css. - * - * @param {String|Object} prop - * @param {String} val - * @return {self} - * @api public - */ - -exports.css = function(prop, val) { - if (arguments.length === 2 || - // When `prop` is a "plain" object - (toString.call(prop) === '[object Object]')) { - return domEach(this, function(idx, el) { - setCss(el, prop, val, idx); - }); - } else { - return getCss(this[0], prop); - } -}; - -/** - * Set styles of all elements. - * - * @param {String|Object} prop - * @param {String} val - * @param {Number} idx - optional index within the selection - * @return {self} - * @api private - */ - -function setCss(el, prop, val, idx) { - if ('string' == typeof prop) { - var styles = getCss(el); - if (typeof val === 'function') { - val = val.call(el, idx, styles[prop]); - } - - if (val === '') { - delete styles[prop]; - } else if (val != null) { - styles[prop] = val; - } - - el.attribs.style = stringify(styles); - } else if ('object' == typeof prop) { - Object.keys(prop).forEach(function(k){ - setCss(el, k, prop[k]); - }); - } -} - -/** - * Get parsed styles of the first element. - * - * @param {String} prop - * @return {Object} - * @api private - */ - -function getCss(el, prop) { - var styles = parse(el.attribs.style); - if (typeof prop === 'string') { - return styles[prop]; - } else if (Array.isArray(prop)) { - return _.pick(styles, prop); - } else { - return styles; - } -} - -/** - * Stringify `obj` to styles. - * - * @param {Object} obj - * @return {Object} - * @api private - */ - -function stringify(obj) { - return Object.keys(obj || {}) - .reduce(function(str, prop){ - return str += '' - + (str ? ' ' : '') - + prop - + ': ' - + obj[prop] - + ';'; - }, ''); -} - -/** - * Parse `styles`. - * - * @param {String} styles - * @return {Object} - * @api private - */ - -function parse(styles) { - styles = (styles || '').trim(); - - if (!styles) return {}; - - return styles - .split(';') - .reduce(function(obj, str){ - var n = str.indexOf(':'); - // skip if there is no :, or if it is the first/last character - if (n < 1 || n === str.length-1) return obj; - obj[str.slice(0,n).trim()] = str.slice(n+1).trim(); - return obj; - }, {}); -} - -},{"../utils":46,"lodash":200}],40:[function(require,module,exports){ -// https://github.com/jquery/jquery/blob/2.1.3/src/manipulation/var/rcheckableType.js -// https://github.com/jquery/jquery/blob/2.1.3/src/serialize.js -var _ = require('lodash'), - submittableSelector = 'input,select,textarea,keygen', - rCRLF = /\r?\n/g; - -exports.serializeArray = function() { - // Resolve all form elements from either forms or collections of form elements - var Cheerio = this.constructor; - return this.map(function() { - var elem = this; - var $elem = Cheerio(elem); - if (elem.name === 'form') { - return $elem.find(submittableSelector).toArray(); - } else { - return $elem.filter(submittableSelector).toArray(); - } - }).filter( - // Verify elements have a name (`attr.name`) and are not disabled (`:disabled`) - '[name!=""]:not(:disabled)' - // and cannot be clicked (`[type=submit]`) or are used in `x-www-form-urlencoded` (`[type=file]`) - + ':not(:submit, :button, :image, :reset, :file)' - // and are either checked/don't have a checkable state - + ':matches([checked], :not(:checkbox, :radio))' - // Convert each of the elements to its value(s) - ).map(function(i, elem) { - var $elem = Cheerio(elem); - var name = $elem.attr('name'); - var val = $elem.val(); - - // If there is no value set (e.g. `undefined`, `null`), then return nothing - if (val == null) { - return null; - } else { - // If we have an array of values (e.g. `