UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

125 lines (120 loc) 5.62 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = require("@emotion/react"); var _ui = require("@atlaskit/editor-common/ui"); var _utils = require("@atlaskit/editor-prosemirror/utils"); var _editorSharedStyles = require("@atlaskit/editor-shared-styles"); var _utils2 = require("@atlaskit/editor-tables/utils"); var _platformFeatureFlags = require("@atlaskit/platform-feature-flags"); var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals"); var _pluginFactory = require("../../pm-plugins/plugin-factory"); var _consts = require("../consts"); var _ContextualMenu = _interopRequireDefault(require("./ContextualMenu")); var _styles = require("./styles"); /** * @jsxRuntime classic * @jsx jsx */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766 // Ignored via go/ees005 // eslint-disable-next-line import/no-named-as-default var FloatingContextualMenu = function FloatingContextualMenu(_ref) { var mountPoint = _ref.mountPoint, boundariesElement = _ref.boundariesElement, scrollableElement = _ref.scrollableElement, editorView = _ref.editorView, isOpen = _ref.isOpen, pluginConfig = _ref.pluginConfig, editorAnalyticsAPI = _ref.editorAnalyticsAPI, getEditorContainerWidth = _ref.getEditorContainerWidth, getEditorFeatureFlags = _ref.getEditorFeatureFlags, isCellMenuOpenByKeyboard = _ref.isCellMenuOpenByKeyboard, isCommentEditor = _ref.isCommentEditor, api = _ref.api; if ((0, _expValEquals.expValEquals)('platform_editor_hydratable_ui', 'isEnabled', true) && !editorView) { return null; } // TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129 // Remove ! during platform_editor_hydratable_ui cleanup // eslint-disable-next-line @typescript-eslint/no-non-null-assertion var _getPluginState = (0, _pluginFactory.getPluginState)(editorView.state), targetCellPosition = _getPluginState.targetCellPosition, isDragAndDropEnabled = _getPluginState.isDragAndDropEnabled; // Remove ! during platform_editor_hydratable_ui cleanup // eslint-disable-next-line @typescript-eslint/no-non-null-assertion if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) { return null; } // Remove ! during platform_editor_hydratable_ui cleanup // eslint-disable-next-line @typescript-eslint/no-non-null-assertion var selection = editorView.state.selection; var selectionRect = (0, _utils2.isSelectionType)(selection, 'cell') ? // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _utils2.getSelectionRect)(selection) : (0, _utils2.findCellRectClosestToPos)(selection.$from); if (!selectionRect) { return null; } // Remove ! during platform_editor_hydratable_ui cleanup // eslint-disable-next-line @typescript-eslint/no-non-null-assertion var domAtPos = editorView.domAtPos.bind(editorView); var targetCellRef = (0, _utils.findDomRefAtPos)(targetCellPosition, domAtPos); if (!targetCellRef) { return null; } var parentSticky = targetCellRef.parentElement && targetCellRef.parentElement.className.indexOf('sticky') > -1; return (0, _react.jsx)(_ui.Popup, { alignX: "right", alignY: "top" // Ignored via go/ees005 // eslint-disable-next-line @atlaskit/editor/no-as-casting , target: targetCellRef, mountTo: mountPoint, boundariesElement: boundariesElement, scrollableElement: scrollableElement, fitHeight: _consts.tablePopupMenuFitHeight, fitWidth: isDragAndDropEnabled ? _consts.contextualMenuDropdownWidthDnD : _consts.contextualMenuDropdownWidth // z-index value below is to ensure that this menu is above other floating menu // in table, but below floating dialogs like typeaheads, pickers, etc. , zIndex: parentSticky ? _editorSharedStyles.akEditorFloatingDialogZIndex : _editorSharedStyles.akEditorFloatingOverlapPanelZIndex, forcePlacement: true, offset: [-7, 0], stick: true }, (0, _react.jsx)("div", { css: (0, _styles.tablePopupStyles)(isDragAndDropEnabled) }, (0, _react.jsx)(_ContextualMenu.default // Remove ! during platform_editor_hydratable_ui cleanup // eslint-disable-next-line @typescript-eslint/no-non-null-assertion , { editorView: editorView, offset: [_consts.contextualMenuTriggerSize / 2, -_consts.contextualMenuTriggerSize], isOpen: isOpen, targetCellPosition: targetCellPosition, allowColumnSorting: pluginConfig && pluginConfig.allowColumnSorting // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion , allowMergeCells: pluginConfig.allowMergeCells // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion , allowBackgroundColor: pluginConfig.allowBackgroundColor, selectionRect: selectionRect, mountPoint: (0, _platformFeatureFlags.fg)('platform_editor_fix_table_menus_jira') ? mountPoint : undefined, boundariesElement: boundariesElement, editorAnalyticsAPI: editorAnalyticsAPI, getEditorContainerWidth: getEditorContainerWidth, getEditorFeatureFlags: getEditorFeatureFlags, isCellMenuOpenByKeyboard: isCellMenuOpenByKeyboard, isCommentEditor: isCommentEditor, api: api }))); }; FloatingContextualMenu.displayName = 'FloatingContextualMenu'; var _default = exports.default = FloatingContextualMenu;