import { BlockOffset, BlockPath, EditorSelection, PortableTextBlock } from "@portabletext/editor";
import { BehaviorActionSet, BehaviorGuard } from "@portabletext/editor/behaviors";
/**
 * @public
 */
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<EditorSelection>;
  /**
   * Block offsets of the match in the text after the insertion
   */
  targetOffsets: {
    anchor: BlockOffset;
    focus: BlockOffset;
    backward: boolean;
  };
};
/**
 * Match found in the text after the insertion
 * @public
 */
type InputRuleMatch = InputRuleMatchLocation & {
  /**
   * Locations of the match's named capture groups, keyed by group name.
   * Only groups that participated in the match are present, and a capture
   * group must be named (`(?<name>...)`) for its location to be exposed;
   * unnamed groups remain usable for regex mechanics (alternation) but get
   * no location.
   */
  groups: Record<string, InputRuleMatchLocation | undefined>;
};
/**
 * @public
 */
type InputRuleEvent = {
  type: 'custom.input rule';
  /**
   * Matches found by the input rule
   */
  matches: Array<InputRuleMatch>;
  /**
   * The focus block's text from its start to the caret, as it was before
   * the insertion
   */
  textBefore: string;
  /**
   * The text carried by the triggering `insert.text` event
   */
  textInserted: string;
  /**
   * The block where the insertion takes place
   */
  focusBlock: {
    path: BlockPath;
    node: PortableTextBlock;
  };
};
/**
 * @public
 */
type InputRuleGuard<TGuardResponse = true> = BehaviorGuard<InputRuleEvent, TGuardResponse>;
/**
 * @public
 */
type InputRule<TGuardResponse = true> = {
  on: RegExp;
  /**
   * Named capture groups inside which an inline object may sit without
   * dropping the match.
   *
   * Inline objects contribute nothing to the text the RegExp matches
   * against, so a match can span one invisibly. By default any such match
   * is dropped: rules commonly delete the matched range, and deleting
   * across an inline object destroys it. Listing a group allows inline
   * objects within that group's matched span (inclusive of its edges,
   * so an object adjacent to the span does not drop the match); everything
   * else in the match, unlisted groups and the text between groups, stays
   * protected. To allow inline objects anywhere in the match, capture the
   * whole pattern in a named group and list it.
   */
  inlineObjects?: {
    allow: Array<string>;
  };
  guard?: InputRuleGuard<TGuardResponse>;
  actions: Array<BehaviorActionSet<InputRuleEvent, TGuardResponse>>;
};
/**
 * @public
 */
declare function defineInputRule<TGuardResponse = true>(config: InputRule<TGuardResponse>): InputRule<TGuardResponse>;
/**
 * @public
 */
declare function defineInputRuleBehavior(config: {
  rules: Array<InputRule<any>>;
  onApply?: ({ endOffsets, endSelection }: {
    endOffsets: {
      start: BlockOffset;
      end: BlockOffset;
    } | undefined;
    endSelection: EditorSelection;
  }) => void;
}): import("@portabletext/editor/behaviors").Behavior<"*" | "annotation.*" | "annotation.add" | "annotation.remove" | "annotation.set" | "annotation.toggle" | "block.*" | "block.set" | "block.unset" | "child.*" | "child.set" | "child.unset" | "clipboard.*" | "clipboard.copy" | "clipboard.cut" | "clipboard.paste" | "decorator.*" | "decorator.add" | "decorator.remove" | "decorator.toggle" | "delete" | "delete.*" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialization.*" | "deserialization.failure" | "deserialization.success" | "deserialize" | "deserialize.*" | "deserialize.data" | "drag.*" | "drag.drag" | "drag.dragend" | "drag.dragenter" | "drag.dragleave" | "drag.dragover" | "drag.dragstart" | "drag.drop" | "history.*" | "history.redo" | "history.undo" | "input.*" | "insert" | "insert.*" | "insert.block" | "insert.blocks" | "insert.break" | "insert.child" | "insert.inline object" | "insert.soft break" | "insert.span" | "insert.text" | "keyboard.*" | "keyboard.keydown" | "keyboard.keyup" | "list item.*" | "list item.add" | "list item.remove" | "list item.toggle" | "mouse.*" | "mouse.click" | "move.*" | "move.backward" | "move.block" | "move.block down" | "move.block up" | "move.forward" | "remove.*" | "remove.text" | "select" | "select.*" | "select.block" | "select.next block" | "select.previous block" | "serialization.*" | "serialization.failure" | "serialization.success" | "serialize" | "serialize.*" | "serialize.data" | "set" | "set.*" | "split" | "split.*" | "style.*" | "style.add" | "style.remove" | "style.toggle" | "unset" | "unset.*" | `custom.${string}`, true, import("@portabletext/editor/behaviors").BehaviorEvent>;
type InputRulePluginProps = {
  rules: Array<InputRule<any>>;
};
/**
 * 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
 * <InputRulePlugin rules={smartQuotesRules} />
 * ```
 *
 * @public
 */
declare function InputRulePlugin(props: InputRulePluginProps): null;
/**
 * @public
 */
type TextTransform<TGuardResponse = true> = ({ location }: {
  location: InputRuleMatchLocation;
}, guardResponse: TGuardResponse) => string;
/**
 * @public
 */
type TextTransformRule<TGuardResponse = true> = {
  on: RegExp;
  guard?: InputRuleGuard<TGuardResponse>;
  /**
   * What to replace, and with what.
   *
   * A function replaces the whole match, always, regardless of any capture
   * groups in the pattern. A record replaces only the spans of the named
   * capture groups given as keys, each with its own transform,
   * `/\d+\s?(?<operator>[*x])\s?\d+/` with
   * `transform: {operator: () => '×'}` turns `2x3` into `2×3` rather than
   * `×`. Use the record form when the pattern needs surrounding context to
   * decide *when* to fire but only part of the match should change; the
   * context must sit inside the match rather than in lookarounds, a rule
   * only fires when its match involves the just-inserted text.
   *
   * Every key must exist as a named capture group in `on`;
   * `defineTextTransformRule` throws otherwise. A match in which none of
   * the keys participated has nothing to replace and is skipped.
   */
  transform: TextTransform<TGuardResponse> | Record<string, TextTransform<TGuardResponse>>;
};
/**
 * Define an `InputRule` specifically designed to transform matched text into
 * some other text.
 *
 * @example
 * ```tsx
 * const transformRule = defineTextTransformRule({
 *   on: /--/,
 *   transform: () => '—',
 * })
 * ```
 *
 * @public
 */
declare function defineTextTransformRule<TGuardResponse = true>(config: TextTransformRule<TGuardResponse>): InputRule<TGuardResponse>;
export { InputRule, InputRuleEvent, InputRuleGuard, InputRuleMatch, type InputRuleMatchLocation, InputRulePlugin, TextTransform, TextTransformRule, defineInputRule, defineInputRuleBehavior, defineTextTransformRule };
//# sourceMappingURL=index.d.ts.map