UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

49 lines 2.66 kB
import * as tslib_1 from "tslib"; import * as React from 'react'; import { PureComponent } from 'react'; import styled from 'styled-components'; import UIMedia from '../../ui/Media'; import { stateKey as mediaStateKey } from '../../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.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 = mediaStateKey.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(UIMedia, { key: "medianode-" + id, editorView: view, id: id, type: type, collection: collection, providers: providerFactory, cardDimensions: cardDimensions, onDelete: this.handleRemove }))); }; return MediaNode; }(PureComponent)); export default MediaNode; var _a; //# sourceMappingURL=media.js.map