UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

67 lines (64 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SizeSelector = void 0; var _react = require("react"); var _react2 = require("@emotion/react"); var _ui = require("@atlaskit/editor-common/ui"); var _tableSizeSelector = require("../../pm-plugins/table-size-selector"); /** * @jsxRuntime classic * @jsx jsx */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled var DEFAULT_TABLE_SELECTOR_COLS = 3; var DEFAULT_TABLE_SELECTOR_ROWS = 3; var SizeSelector = exports.SizeSelector = function SizeSelector(_ref) { var api = _ref.api, target = _ref.target, popupsMountPoint = _ref.popupsMountPoint, popupsBoundariesElement = _ref.popupsBoundariesElement, popupsScrollableElement = _ref.popupsScrollableElement; var closeSelectorPopup = (0, _react.useCallback)(function () { api === null || api === void 0 || api.core.actions.execute(function (_ref2) { var tr = _ref2.tr; tr.setMeta(_tableSizeSelector.pluginKey, { isSelectorOpen: false }); return tr; }); }, [api]); var onSelection = (0, _react.useCallback)(function (rowsCount, colsCount) { api === null || api === void 0 || api.core.actions.execute(function (_ref3) { var tr = _ref3.tr; api === null || api === void 0 || api.table.commands.insertTableWithSize(rowsCount, colsCount)({ tr: tr }); tr.setMeta(_tableSizeSelector.pluginKey, { isSelectorOpen: false }); return tr; }); }, [api]); var onUnmount = function onUnmount() { api === null || api === void 0 || api.core.actions.focus(); }; return (0, _react2.jsx)(_ui.TableSelectorPopup // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) , { defaultSize: { row: DEFAULT_TABLE_SELECTOR_ROWS, col: DEFAULT_TABLE_SELECTOR_COLS }, target: target, onUnmount: onUnmount, onSelection: onSelection, popupsMountPoint: popupsMountPoint, popupsScrollableElement: popupsScrollableElement, popupsBoundariesElement: popupsBoundariesElement, isOpenedByKeyboard: true, handleClickOutside: closeSelectorPopup, handleEscapeKeydown: closeSelectorPopup }); };