UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

51 lines 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); var react_1 = require("react"); var styled_components_1 = require("styled-components"); var Media_1 = require("../../ui/Media"); var media_1 = require("../../plugins/media"); // tslint:disable-next-line:variable-name var Wrapper = (_a = ["\n margin: 0;\n display: inline-block;\n verticalAlign: middle;\n userSelect: all;\n border: 3px solid ", "\n border-radius: 5px;\n"], _a.raw = ["\n margin: 0;\n display: inline-block;\n verticalAlign: middle;\n userSelect: all;\n border: 3px solid ", "\n border-radius: 5px;\n"], styled_components_1.default.div(_a, function (props) { return props.selected ? '#8cf' : 'transparent'; })); var MediaNode = (function (_super) { tslib_1.__extends(MediaNode, _super); function MediaNode(props) { var _this = _super.call(this, props) || this; _this.handleRemove = function (item, event) { var _a = _this.props, getPos = _a.getPos, node = _a.node; _this.pluginState.handleMediaNodeRemoval(node, getPos); if (event) { event.stopPropagation(); } }; _this.handleNewNode = function (props) { var getPos = props.getPos, node = props.node; _this.pluginState.handleMediaNodeMount(node, getPos); }; var view = _this.props.view; _this.pluginState = media_1.stateKey.getState(view.state); return _this; } MediaNode.prototype.componentDidMount = function () { this.handleNewNode(this.props); }; MediaNode.prototype.componentWillUnmount = function () { var node = this.props.node; this.pluginState.handleMediaNodeUnmount(node); }; MediaNode.prototype.shouldComponentUpdate = function (nextProps) { var getId = function (props) { return props.node.attrs.id; }; return getId(nextProps) !== getId(this.props) || nextProps.selected !== this.props.selected; }; MediaNode.prototype.render = function () { var _a = this.props, node = _a.node, providerFactory = _a.providerFactory, selected = _a.selected, view = _a.view, cardDimensions = _a.cardDimensions; var _b = node.attrs, id = _b.id, type = _b.type, collection = _b.collection; return (React.createElement(Wrapper, { selected: selected }, React.createElement(Media_1.default, { key: "medianode-" + id, editorView: view, id: id, type: type, collection: collection, providers: providerFactory, cardDimensions: cardDimensions, onDelete: this.handleRemove }))); }; return MediaNode; }(react_1.PureComponent)); exports.default = MediaNode; var _a; //# sourceMappingURL=media.js.map