@atlaskit/editor-plugin-insert-block
Version:
Insert block plugin for @atlaskit/editor-core
27 lines • 1.14 kB
JavaScript
import { useCallback } from 'react';
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
import { usePopupManager } from './usePopupManager';
export const useTableSelectorPopup = ({
api,
buttonRef
}) => {
const popupManager = usePopupManager({
focusTarget: buttonRef
});
const handleSelectedTableSize = useCallback((rowsCount, colsCount) => {
// workaround to solve race condition where cursor is not placed correctly inside table
queueMicrotask(() => {
var _api$core, _api$table;
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? 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]);
const onPopupUnmount = useCallback(() => {
api === null || api === void 0 ? void 0 : api.core.actions.focus();
}, [api]);
return {
...popupManager,
handleSelectedTableSize,
onPopupUnmount
};
};