import {BlockOffset, EditorSelection} from '@portabletext/editor' import type {BlockPath, PortableTextBlock} from '@portabletext/editor' import {Behavior, BehaviorEvent} from '@portabletext/editor/behaviors' import type { BehaviorActionSet, BehaviorGuard, } from '@portabletext/editor/behaviors' /** * @alpha */ export declare function defineInputRule( config: InputRule, ): InputRule /** * @alpha */ export declare function defineInputRuleBehavior(config: { rules: Array> onApply?: ({ endOffsets, endSelection, }: { endOffsets: | { start: BlockOffset end: BlockOffset } | undefined endSelection: EditorSelection }) => void }): Behavior< | '*' | 'insert.text' | 'annotation.add' | 'annotation.remove' | 'block.set' | 'block.unset' | 'child.set' | 'child.unset' | 'decorator.add' | 'decorator.remove' | 'delete' | 'history.redo' | 'history.undo' | 'insert' | 'insert.block' | 'insert.child' | 'move.backward' | 'move.block' | 'move.forward' | 'remove.text' | 'select' | 'set' | 'unset' | 'annotation.set' | 'annotation.toggle' | 'decorator.toggle' | 'delete.backward' | 'delete.block' | 'delete.child' | 'delete.forward' | 'delete.text' | 'deserialize' | 'deserialize.data' | 'deserialization.success' | 'deserialization.failure' | 'insert.blocks' | 'insert.break' | 'insert.inline object' | 'insert.soft break' | 'insert.span' | 'list item.add' | 'list item.remove' | 'list item.toggle' | 'move.block down' | 'move.block up' | 'select.block' | 'select.previous block' | 'select.next block' | 'serialize' | 'serialize.data' | 'serialization.success' | 'serialization.failure' | 'split' | 'style.add' | 'style.remove' | 'style.toggle' | 'clipboard.copy' | 'clipboard.cut' | 'clipboard.paste' | 'drag.dragstart' | 'drag.drag' | 'drag.dragend' | 'drag.dragenter' | 'drag.dragover' | 'drag.dragleave' | 'drag.drop' | 'input.*' | 'keyboard.keydown' | 'keyboard.keyup' | 'mouse.click' | 'delete.*' | 'insert.*' | 'select.*' | 'set.*' | 'unset.*' | 'deserialize.*' | 'serialize.*' | 'split.*' | 'annotation.*' | 'remove.*' | 'block.*' | 'child.*' | 'decorator.*' | 'history.*' | 'move.*' | 'deserialization.*' | 'list item.*' | 'serialization.*' | 'style.*' | 'clipboard.*' | 'drag.*' | 'keyboard.*' | 'mouse.*' | `custom.${string}`, true, BehaviorEvent > /** * Define an `InputRule` specifically designed to transform matched text into * some other text. * * @example * ```tsx * const transformRule = defineTextTransformRule({ * on: /--/, * transform: () => '—', * }) * ``` * * @alpha */ export declare function defineTextTransformRule( config: TextTransformRule, ): InputRule /** * @alpha */ export declare type InputRule = { on: RegExp guard?: InputRuleGuard actions: Array> } /** * @alpha */ export declare type InputRuleEvent = { type: 'custom.input rule' /** * Matches found by the input rule */ matches: Array /** * The text before the insertion */ textBefore: string /** * The text is destined to be inserted */ textInserted: string /** * The block where the insertion takes place */ focusBlock: { path: BlockPath node: PortableTextBlock } } /** * @alpha */ export declare type InputRuleGuard = BehaviorGuard< InputRuleEvent, TGuardResponse > /** * Match found in the text after the insertion * @alpha */ export declare type InputRuleMatch = InputRuleMatchLocation & { groupMatches: Array } declare type InputRuleMatchLocation = { /** * The matched text */ text: string /** * Estimated selection of where in the original text the match is located. * The selection is estimated since the match is found in the text after * insertion. */ selection: NonNullable /** * Block offsets of the match in the text after the insertion */ targetOffsets: { anchor: BlockOffset focus: BlockOffset backward: boolean } } /** * Turn an array of `InputRule`s into a Behavior that can be used to apply the * rules to the editor. * * The plugin handles undo/redo out of the box including smart undo with * Backspace. * * @example * ```tsx * * ``` * * @alpha */ export declare function InputRulePlugin(props: InputRulePluginProps): null declare type InputRulePluginProps = { rules: Array> } /** * @alpha */ export declare type TextTransformRule = { on: RegExp guard?: InputRuleGuard transform: ( { location, }: { location: InputRuleMatchLocation }, guardResponse: TGuardResponse, ) => string } export {}