@atlaskit/editor-plugin-loom
Version:
Loom plugin for @atlaskit/editor-core
47 lines • 2.68 kB
JavaScript
import React from 'react';
import { LOOM_MENU_SECTION, LOOM_MENU_ITEM, LOOM_MENU_SECTION_RANK, OVERFLOW_MENU_PRIMARY_TOOLBAR_RANK, OVERFLOW_MENU_PRIMARY_TOOLBAR, OVERFLOW_EXTENSIONS_MENU_SECTION, OVERFLOW_EXTENSIONS_MENU_SECTION_RANK } from '@atlaskit/editor-common/toolbar';
import { LoomMenuItem } from './LoomMenuItem';
import { MenuSection } from './MenuSection';
export var getToolbarComponents = function getToolbarComponents(config, api) {
return [{
type: LOOM_MENU_SECTION.type,
key: LOOM_MENU_SECTION.key,
parents: [{
type: OVERFLOW_MENU_PRIMARY_TOOLBAR.type,
key: OVERFLOW_MENU_PRIMARY_TOOLBAR.key,
rank: OVERFLOW_MENU_PRIMARY_TOOLBAR_RANK[LOOM_MENU_SECTION.key]
}],
component: function component(_ref) {
var children = _ref.children;
return /*#__PURE__*/React.createElement(MenuSection, {
api: api
}, children);
}
}, {
type: LOOM_MENU_ITEM.type,
key: LOOM_MENU_ITEM.key,
parents: [{
type: LOOM_MENU_SECTION.type,
key: LOOM_MENU_SECTION.key,
rank: LOOM_MENU_SECTION_RANK[LOOM_MENU_ITEM.key]
}, {
type: OVERFLOW_EXTENSIONS_MENU_SECTION.type,
key: OVERFLOW_EXTENSIONS_MENU_SECTION.key,
rank: OVERFLOW_EXTENSIONS_MENU_SECTION_RANK[LOOM_MENU_ITEM.key]
}],
component: function component() {
return /*#__PURE__*/React.createElement(LoomMenuItem, {
api: api,
renderButton: config.renderButton
});
},
isHidden: function isHidden() {
var _api$loom, _api$editorViewMode$s, _api$editorViewMode, _config$shouldRenderB, _config$shouldRenderB2;
var loomState = api === null || api === void 0 || (_api$loom = api.loom) === null || _api$loom === void 0 ? void 0 : _api$loom.sharedState.currentState();
var editorViewMode = (_api$editorViewMode$s = api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.currentState()) !== null && _api$editorViewMode$s !== void 0 ? _api$editorViewMode$s : 'edit';
// if shouldRenderButton is not provided, default to true
var shouldRenderButton = (_config$shouldRenderB = config === null || config === void 0 || (_config$shouldRenderB2 = config.shouldRenderButton) === null || _config$shouldRenderB2 === void 0 ? void 0 : _config$shouldRenderB2.call(config)) !== null && _config$shouldRenderB !== void 0 ? _config$shouldRenderB : true;
return 'renderButton' in config && shouldRenderButton === false || (loomState === null || loomState === void 0 ? void 0 : loomState.isEnabled) === undefined || editorViewMode !== 'edit';
}
}];
};