UNPKG

@atlaskit/editor-plugin-synced-block

Version:

SyncedBlock plugin for @atlaskit/editor-core

74 lines (73 loc) 4 kB
import React from 'react'; import type { IntlShape } from 'react-intl'; import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher'; import type { PortalProviderAPI } from '@atlaskit/editor-common/portal'; import ReactNodeView from '@atlaskit/editor-common/react-node-view'; import type { getPosHandler } from '@atlaskit/editor-common/react-node-view'; import type { ReactComponentProps } from '@atlaskit/editor-common/react-node-view'; import type { ExtractInjectionAPI, getPosHandlerNode, PMPluginFactoryParams } from '@atlaskit/editor-common/types'; import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model'; import type { EditorView, Decoration, DecorationSource } from '@atlaskit/editor-prosemirror/view'; import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider'; import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType'; export interface SyncBlockNodeViewProps extends ReactComponentProps { api?: ExtractInjectionAPI<SyncedBlockPlugin>; eventDispatcher: EventDispatcher; getPos: getPosHandlerNode; intl?: IntlShape; isNodeNested?: boolean; node: PMNode; options: SyncedBlockPluginOptions | undefined; portalProviderAPI: PortalProviderAPI; syncBlockStore?: SyncBlockStoreManager; view: EditorView; } export declare class SyncBlock extends ReactNodeView<SyncBlockNodeViewProps> { private options; private api?; private syncBlockStore?; private intl?; constructor(props: SyncBlockNodeViewProps); private removeSyncBlockStable; private fetchSyncBlockSourceInfoStable; unsubscribe: (() => void) | undefined; private dragStartHandler; createDomRef(): HTMLElement; /** * Allow mouse and selection events inside the renderer content to pass * through to the browser so that users can select and copy text within a * reference sync block. * * Events that originate inside the sync block content area (but not the label) * are stopped so ProseMirror does not intercept them for node-level selection. * This includes the full click-drag cycle (mousedown, mousemove, mouseup), * click, dblclick, selectstart and cut. The `cut` event is stopped because * mousedown explicitly sets a NodeSelection on the sync block — without * stopping `cut`, a subsequent Ctrl+X would cause ProseMirror to delete the * entire sync block node instead of cutting the user's text selection. * * Copy events are conditionally stopped: when the user has an active native * text selection inside the renderer, `copy` is stopped so the browser handles * it natively (copying the selected text). When there is no text selection * (just a PM NodeSelection), `copy` is NOT stopped so ProseMirror's copy * handler runs and sets the "sync-block-copied" flag for the reference paste flow. * * Events on the SyncBlockLabel are left for ProseMirror to handle, preserving * label click interactions and the floating toolbar. * * The renderer wrapper sets contentEditable="true" to create a re-editable * island inside ProseMirror's contentEditable="false" nodeview, enabling * native text selection and preventing browser drag behaviour. */ stopEvent(event: Event): boolean; validUpdate(currentNode: PMNode, newNode: PMNode): boolean; update(node: PMNode, decorations: ReadonlyArray<Decoration>, innerDecorations?: DecorationSource): boolean; render({ getPos }: SyncBlockNodeViewProps): React.JSX.Element | null; destroy(): void; } export interface SyncBlockNodeViewProperties { api?: ExtractInjectionAPI<SyncedBlockPlugin>; options: SyncedBlockPluginOptions | undefined; pmPluginFactoryParams: PMPluginFactoryParams; } export declare const syncBlockNodeView: (props: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: getPosHandler) => ReactNodeView<SyncBlockNodeViewProps>;