UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

49 lines 1.47 kB
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; export const pluginKey = new PluginKey('editorContentAreaHeightPlugin'); export const INITIAL_STATIC_VIEWPORT_HEIGHT = 1200; export const EDITOR_CONTENT_AREA_REGION_CLASSNAME = '.ak-editor-content-area-region'; const createPlugin = () => new SafePlugin({ key: pluginKey, state: { init() { return { height: INITIAL_STATIC_VIEWPORT_HEIGHT }; }, apply(tr, pluginState) { const meta = tr.getMeta(pluginKey); if (meta) { return { ...pluginState, ...meta }; } return pluginState; } }, view: view => { const editorContentAreaEl = view.dom.closest(EDITOR_CONTENT_AREA_REGION_CLASSNAME); let resizeObserver; if (editorContentAreaEl) { resizeObserver = new ResizeObserver(entries => { for (const entry of entries) { const height = entry.contentRect.height; const tr = view.state.tr.setMeta(pluginKey, { height, isObserved: true }); view.dispatch(tr); } }); resizeObserver.observe(editorContentAreaEl); } return { destroy() { var _resizeObserver; (_resizeObserver = resizeObserver) === null || _resizeObserver === void 0 ? void 0 : _resizeObserver.disconnect(); } }; } }); export { createPlugin };