UNPKG

@atlaskit/editor-plugin-media

Version:

Media plugin for @atlaskit/editor-core

66 lines 2.39 kB
import React from 'react'; import { pixelEntryMessages as messages } from '@atlaskit/editor-common/media'; import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils'; import ImageFullscreenIcon from '@atlaskit/icon/core/image-fullscreen'; import { openPixelEditor } from '../../pm-plugins/pixel-resizing/commands'; import { PixelEntry } from '../../pm-plugins/pixel-resizing/ui'; import { PIXEL_RESIZING_TOOLBAR_WIDTH } from '../../pm-plugins/pixel-resizing/ui/constants'; import { getSelectedMediaSingle } from './utils'; export const getPixelResizingToolbar = (toolbarBaseConfig, { pluginInjectionApi, intl, pluginState, hoverDecoration, isEditorFullWidthEnabled, triggerButtonSelector }) => ({ ...toolbarBaseConfig, width: PIXEL_RESIZING_TOOLBAR_WIDTH, scrollable: true, items: [{ type: 'custom', fallback: [], render: editorView => { if (!editorView) { return null; } const selectedMediaSingleNode = getSelectedMediaSingle(editorView.state); if (!editorView || !selectedMediaSingleNode) { return null; } return /*#__PURE__*/React.createElement(PixelEntry, { editorView: editorView, intl: intl, selectedMediaSingleNode: selectedMediaSingleNode, pluginInjectionApi: pluginInjectionApi, pluginState: pluginState, hoverDecoration: hoverDecoration, isEditorFullWidthEnabled: isEditorFullWidthEnabled, triggerButtonSelector: triggerButtonSelector }); } }] }); export const getResizeDropdownOption = (mediaOptions, state, formatMessage, selectedNodeType) => { if ((selectedNodeType === null || selectedNodeType === void 0 ? void 0 : selectedNodeType.name) !== 'mediaSingle') { return []; } const { allowResizing, allowResizingInTables, allowAdvancedToolBarOptions, allowPixelResizing } = mediaOptions; const isWithinTable = hasParentNodeOfType(state.schema.nodes.table)(state.selection); if (allowAdvancedToolBarOptions && allowResizing && (!isWithinTable || allowResizingInTables === true) && allowPixelResizing) { return [{ title: formatMessage(messages.resizeOption), onClick: openPixelEditor(), icon: /*#__PURE__*/React.createElement(ImageFullscreenIcon, { label: "" }), testId: 'media-pixel-resizing-dropdown-option' }]; } return []; };