@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
69 lines • 3.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var react_1 = require("react");
var hint_1 = require("@atlaskit/icon/glyph/editor/hint");
var info_1 = require("@atlaskit/icon/glyph/editor/info");
var note_1 = require("@atlaskit/icon/glyph/editor/note");
var remove_1 = require("@atlaskit/icon/glyph/editor/remove");
var warning_1 = require("@atlaskit/icon/glyph/editor/warning");
var ToolbarButton_1 = require("../ToolbarButton");
var panel_1 = require("../../plugins/panel");
var styles_1 = require("./styles");
var icons = {
info: info_1.default,
note: note_1.default,
tip: hint_1.default,
warning: warning_1.default,
};
var PanelEdit = (function (_super) {
tslib_1.__extends(PanelEdit, _super);
function PanelEdit(props) {
var _this = _super.call(this, props) || this;
_this.state = { toolbarVisible: false };
_this.handlePluginStateChange = function (pluginState) {
var target = pluginState.element, activePanelType = pluginState.activePanelType, toolbarVisible = pluginState.toolbarVisible;
_this.setState({
toolbarVisible: toolbarVisible,
target: target,
activePanelType: activePanelType,
});
};
_this.handleSelectPanelType = function (panelType, event) {
var editorView = _this.props.editorView;
_this.props.pluginState.changePanelType(editorView, panelType);
};
_this.handleRemovePanel = function () {
var editorView = _this.props.editorView;
_this.props.pluginState.removePanel(editorView);
};
return _this;
}
PanelEdit.prototype.componentDidMount = function () {
this.props.pluginState.subscribe(this.handlePluginStateChange);
};
PanelEdit.prototype.componentWillUnmount = function () {
this.props.pluginState.unsubscribe(this.handlePluginStateChange);
};
PanelEdit.prototype.render = function () {
var _this = this;
var _a = this.state, target = _a.target, activePanelType = _a.activePanelType, toolbarVisible = _a.toolbarVisible;
if (toolbarVisible) {
return (React.createElement(styles_1.FloatingToolbar, { target: target, offset: [0, 3] },
panel_1.availablePanelType.map(function (panelType, index) {
// tslint:disable-next-line:variable-name
var Icon = icons[panelType.panelType];
return (React.createElement(ToolbarButton_1.default, { key: index, selected: activePanelType === panelType.panelType, onClick: _this.handleSelectPanelType.bind(_this, panelType), iconBefore: React.createElement(Icon, { label: "Change panel type to " + panelType.panelType }) }));
}),
React.createElement(styles_1.Separator, null),
React.createElement(styles_1.TrashToolbarButton, { onClick: this.handleRemovePanel, iconBefore: React.createElement(remove_1.default, { label: "Remove panel type" }) })));
}
else {
return null;
}
};
return PanelEdit;
}(react_1.PureComponent));
exports.default = PanelEdit;
//# sourceMappingURL=index.js.map