UNPKG

@atlaskit/editor-plugin-insert-block

Version:

Insert block plugin for @atlaskit/editor-core

28 lines 2.02 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { useCallback } from 'react'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { usePopupManager } from './usePopupManager'; export var useTableSelectorPopup = function useTableSelectorPopup(_ref) { var api = _ref.api, buttonRef = _ref.buttonRef; var popupManager = usePopupManager({ focusTarget: buttonRef }); var handleSelectedTableSize = useCallback(function (rowsCount, colsCount) { // workaround to solve race condition where cursor is not placed correctly inside table queueMicrotask(function () { var _api$core, _api$table; api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.commands.insertTableWithSize(rowsCount, colsCount, INPUT_METHOD.PICKER)); }); popupManager.close(); }, [api, popupManager]); var onPopupUnmount = useCallback(function () { api === null || api === void 0 || api.core.actions.focus(); }, [api]); return _objectSpread(_objectSpread({}, popupManager), {}, { handleSelectedTableSize: handleSelectedTableSize, onPopupUnmount: onPopupUnmount }); };