UNPKG

@atlaskit/editor-plugin-expand

Version:

Expand plugin for @atlaskit/editor-core

109 lines (108 loc) 4.56 kB
import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import type { EditorAppearance, EditorCommand, LongPressSelectionPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types'; import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics'; import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls'; import type { BlockMenuPlugin } from '@atlaskit/editor-plugin-block-menu'; import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations'; import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled'; import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode'; import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags'; import type { LocalIdPlugin } from '@atlaskit/editor-plugin-local-id'; import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection'; import type { SelectionMarkerPlugin } from '@atlaskit/editor-plugin-selection-marker'; import type { Selection } from '@atlaskit/editor-prosemirror/state'; import type { insertExpand, insertExpandWithInputMethod } from './legacyExpand/commands'; export interface ExpandPluginState { expandRef?: HTMLDivElement | null; } export type ExpandPluginAction = { data: { ref?: HTMLDivElement | null; }; type: 'SET_EXPAND_REF'; }; export type ExpandPluginSharedState = { allowInsertion?: boolean; } | undefined; export type InsertMethod = INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.ELEMENT_BROWSER | INPUT_METHOD.TOOLBAR; export interface ExpandPluginOptions extends LongPressSelectionPluginOptions { /** * There is expected to be temporary divergence between Live Page editor expand behaviour and the standard expand behaviour. * * This is expected to be removed in Q4 as Editor and Live Page teams align on a singular behaviour. * * It is only supported for use by Confluence. * * @default false */ __livePage?: boolean; allowInsertion?: boolean; /** * Allows the expand button to toggle. Previously this was set via the editor prop featureFlag (`interactiveExpand`) * * Defaults to true */ allowInteractiveExpand?: boolean; appearance?: EditorAppearance; } export type ExpandPluginDependencies = [ DecorationsPlugin, SelectionPlugin, OptionalPlugin<AnalyticsPlugin>, OptionalPlugin<SelectionMarkerPlugin>, OptionalPlugin<EditorDisabledPlugin>, OptionalPlugin<FeatureFlagsPlugin>, OptionalPlugin<EditorViewModePlugin>, OptionalPlugin<BlockMenuPlugin>, OptionalPlugin<LocalIdPlugin>, OptionalPlugin<BlockControlsPlugin> ]; export type ExpandPlugin = NextEditorPlugin<'expand', { actions: { /** * Insert an expand node and dispatch event with `insertMenu` inputMethod */ insertExpand: ReturnType<typeof insertExpand>; /** * Insert an expand node and dispatch event with inputMethod specified */ insertExpandWithInputMethod: ReturnType<typeof insertExpandWithInputMethod>; }; commands: { /** * Expand or collapse a range of expand nodes. With no parameters * * * @param from Starting range (defaults to 0) * @param to Ending range (defaults to the document size) * @param open Boolean to open (defaults to opening expands) * @returns EditorCommand to be executed * * @example * ```ts * // Opens all the expands on the page * editorAPI.core.actions.execute( * editorAPI.expand.commands.toggleExpandRange() * ) * * // Closes all the expands between positions 0 and 34 on the page * editorAPI.core.actions.execute( * editorAPI.expand.commands.toggleExpandRange(0, 34, false) * ) * * // Closes all the expands on the page * editorAPI.core.actions.execute( * editorAPI.expand.commands.toggleExpandRange(undefined, undefined, false) * ) * ``` */ toggleExpandRange: (from?: number, to?: number, open?: boolean) => EditorCommand; /** * Toggle the expand or nested expand node open */ toggleExpandWithMatch: (selection: Selection) => EditorCommand; }; dependencies: ExpandPluginDependencies; pluginConfiguration: ExpandPluginOptions | undefined; sharedState: ExpandPluginSharedState; }>;