@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
121 lines (120 loc) • 7.22 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _hooks = require("@atlaskit/editor-common/hooks");
var _ui = require("@atlaskit/editor-common/ui");
var _userIntent = require("@atlaskit/editor-common/user-intent");
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
var _types = require("../../types");
var _consts = require("../consts");
var _keys = require("../TableMenu/column/keys");
var _keys2 = require("../TableMenu/row/keys");
var _consts2 = require("../TableMenu/shared/consts");
var _TableMenu = require("../TableMenu/shared/TableMenu");
var _DragMenu = _interopRequireDefault(require("./DragMenu"));
var TABLE_MENU_OFFSET = _consts.dragTableInsertColumnButtonSize + 4;
var FloatingDragMenu = function FloatingDragMenu(_ref) {
var _getEditorFeatureFlag;
var mountPoint = _ref.mountPoint,
boundariesElement = _ref.boundariesElement,
scrollableElement = _ref.scrollableElement,
editorView = _ref.editorView,
isOpen = _ref.isOpen,
tableNode = _ref.tableNode,
direction = _ref.direction,
index = _ref.index,
targetCellPosition = _ref.targetCellPosition,
getEditorContainerWidth = _ref.getEditorContainerWidth,
editorAnalyticsAPI = _ref.editorAnalyticsAPI,
stickyHeaders = _ref.stickyHeaders,
pluginConfig = _ref.pluginConfig,
isTableScalingEnabled = _ref.isTableScalingEnabled,
getEditorFeatureFlags = _ref.getEditorFeatureFlags,
ariaNotifyPlugin = _ref.ariaNotifyPlugin,
api = _ref.api,
isCommentEditor = _ref.isCommentEditor,
tableWrapper = _ref.tableWrapper;
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['table'], function (states) {
var _states$tableState;
return {
activeTableMenu: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.activeTableMenu
};
}),
activeTableMenu = _useSharedPluginState.activeTableMenu;
var isActiveTableMenuDragMenu = (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'row' || (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'column';
var hasActiveTableMenuState = activeTableMenu !== undefined;
var isDragMenuOpen = (0, _expValEquals.expValEquals)('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu : isOpen;
var dragMenuDirection = (0, _expValEquals.expValEquals)('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu ? activeTableMenu.type : undefined : direction;
var dragMenuIndex = (0, _expValEquals.expValEquals)('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu ? activeTableMenu.index : undefined : index;
if (!isDragMenuOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
return null;
}
var inStickyMode = (stickyHeaders === null || stickyHeaders === void 0 ? void 0 : stickyHeaders.sticky) || (tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.classList.contains(_types.TableCssClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW)) && (0, _platformFeatureFlags.fg)('platform_editor_table_sticky_header_patch_7');
var targetHandleRef = dragMenuDirection === 'row' ? document.querySelector('#drag-handle-button-row') : document.querySelector('#drag-handle-button-column');
if (!targetHandleRef || !(editorView.state.selection instanceof _cellSelection.CellSelection)) {
return null;
}
var _ref2 = (_getEditorFeatureFlag = getEditorFeatureFlags === null || getEditorFeatureFlags === void 0 ? void 0 : getEditorFeatureFlags()) !== null && _getEditorFeatureFlag !== void 0 ? _getEditorFeatureFlag : {},
_ref2$tableWithFixedC = _ref2.tableWithFixedColumnWidthsOption,
tableWithFixedColumnWidthsOption = _ref2$tableWithFixedC === void 0 ? false : _ref2$tableWithFixedC;
var shouldUseIncreasedScalingPercent = isTableScalingEnabled && (tableWithFixedColumnWidthsOption || isCommentEditor);
return /*#__PURE__*/_react.default.createElement(_ui.Popup, {
alignX: dragMenuDirection === 'row' ? 'right' : undefined,
alignY: dragMenuDirection === 'row' ? 'start' : undefined
// Ignored via go/ees005
// eslint-disable-next-line @atlaskit/editor/no-as-casting
,
target: targetHandleRef,
mountTo: mountPoint,
boundariesElement: boundariesElement,
scrollableElement: scrollableElement,
fitWidth: (0, _expValEquals.expValEquals)('platform_editor_table_menu_updates', 'isEnabled', true) ? _consts2.TABLE_MENU_WIDTH : _consts.dragMenuDropdownWidth,
fitHeight: _consts.tablePopupMenuFitHeight
// 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.
// In sticky mode, we want to show the menu above the sticky header
,
zIndex: inStickyMode ? _editorSharedStyles.akEditorFloatingDialogZIndex : _editorSharedStyles.akEditorFloatingOverlapPanelZIndex,
forcePlacement: true,
offset: (0, _expValEquals.expValEquals)('platform_editor_table_menu_updates', 'isEnabled', true) ? [TABLE_MENU_OFFSET, 0] : direction === 'row' ? [-9, 0] : [0, -7],
stick: true
}, (0, _expValEquals.expValEquals)('platform_editor_table_menu_updates', 'isEnabled', true) ? /*#__PURE__*/_react.default.createElement(_userIntent.UserIntentPopupWrapper, {
api: api,
userIntent: "tableDragMenuPopupOpen"
}, /*#__PURE__*/_react.default.createElement(_TableMenu.TableMenu, {
api: api,
editorView: editorView,
surface: dragMenuDirection === 'row' ? _keys2.ROW_MENU : _keys.COLUMN_MENU
})) : /*#__PURE__*/_react.default.createElement(_DragMenu.default, {
editorView: editorView,
isOpen: isDragMenuOpen,
tableNode: tableNode,
direction: dragMenuDirection,
index: dragMenuIndex,
target: targetHandleRef || undefined,
targetCellPosition: targetCellPosition,
getEditorContainerWidth: getEditorContainerWidth,
editorAnalyticsAPI: editorAnalyticsAPI,
pluginConfig: pluginConfig,
fitWidth: _consts.dragMenuDropdownWidth,
fitHeight: _consts.tablePopupMenuFitHeight,
mountPoint: mountPoint,
boundariesElement: boundariesElement,
scrollableElement: scrollableElement,
isTableScalingEnabled: isTableScalingEnabled,
shouldUseIncreasedScalingPercent: shouldUseIncreasedScalingPercent,
isTableFixedColumnWidthsOptionEnabled: tableWithFixedColumnWidthsOption,
ariaNotifyPlugin: ariaNotifyPlugin,
api: api,
isCommentEditor: isCommentEditor || false
}));
};
FloatingDragMenu.displayName = 'FloatingDragMenu';
var _default = exports.default = FloatingDragMenu;