import { AnnotationDefinition, AnnotationPath, AnnotationSchemaType, BlockObjectSchemaType, BlockPath, ChildPath, DecoratorDefinition, DecoratorSchemaType, InlineObjectSchemaType, ListSchemaType, PortableTextObject, StyleSchemaType } from "@portabletext/editor"; import { ApplicableSchema } from "@portabletext/editor/selectors"; import { InsertPlacement } from "@portabletext/editor/behaviors"; import { RefObject } from "react"; import { KeyboardShortcut } from "@portabletext/keyboard-shortcuts"; /** * @beta * * React hook that subscribes to {@link getApplicableSchema} for the active * editor and returns a stable reference across editor ticks while the * applicable set is unchanged. * * Pair with {@link useToolbarSchema} to render a static toolbar whose * buttons stay stable across selection moves and gate their enabled state * on whether the corresponding name is in the relevant set. */ declare function useApplicableSchema(): ApplicableSchema; /** * @beta */ type ExtendDecoratorSchemaType = (decorator: DecoratorSchemaType) => ToolbarDecoratorSchemaType; /** * @beta */ type ExtendAnnotationSchemaType = (annotation: AnnotationSchemaType) => ToolbarAnnotationSchemaType; /** * @beta */ type ExtendListSchemaType = (list: ListSchemaType) => ToolbarListSchemaType; /** * @beta */ type ExtendBlockObjectSchemaType = (blockObject: BlockObjectSchemaType) => ToolbarBlockObjectSchemaType; /** * @beta */ type ExtendInlineObjectSchemaType = (inlineObject: InlineObjectSchemaType) => ToolbarInlineObjectSchemaType; /** * @beta */ type ExtendStyleSchemaType = (style: StyleSchemaType) => ToolbarStyleSchemaType; /** * @beta * * Resolve the editor's full toolbar schema. Returns the union of every * decorator, annotation, list, style, block object and inline object declared * anywhere in the editor's schema graph that is reachable from a position * where text is edited - the root schema merged with the sub-schema of every * registered container whose field accepts text blocks. Useful for rendering * a static toolbar whose buttons stay stable across selection moves. * * Re-renders only when the schema graph or the extension callbacks change. * Pair with {@link useApplicableSchema} to determine which entries are * applicable at the current selection (which buttons should be enabled vs. * disabled). */ declare function useToolbarSchema(props: { extendDecorator?: ExtendDecoratorSchemaType; extendAnnotation?: ExtendAnnotationSchemaType; extendList?: ExtendListSchemaType; extendBlockObject?: ExtendBlockObjectSchemaType; extendInlineObject?: ExtendInlineObjectSchemaType; extendStyle?: ExtendStyleSchemaType; }): ToolbarSchema; /** * @beta */ type ToolbarSchema = { decorators: ReadonlyArray; annotations: ReadonlyArray; lists: ReadonlyArray; blockObjects: ReadonlyArray; inlineObjects: ReadonlyArray; styles: ReadonlyArray; }; /** * @beta */ type ToolbarDecoratorSchemaType = DecoratorSchemaType & { icon?: React.ComponentType<{ className?: string; }>; shortcut?: KeyboardShortcut; mutuallyExclusive?: ReadonlyArray; }; /** * @beta */ type ToolbarAnnotationSchemaType = AnnotationSchemaType & { icon?: React.ComponentType<{ className?: string; }>; defaultValues?: Record; shortcut?: KeyboardShortcut; /** * The annotations this annotation cannot coexist with. The list * replaces the default rule that an annotation is mutually exclusive * with itself: * * - Absent: the default applies (adding the annotation removes * existing annotations of the same type in the selection). * - `[]`: exclusive with nothing, not even itself, so same-type * annotations may overlap. * - `['other']`: exclusive with exactly the listed annotations. * Include the annotation's own name to keep self-exclusivity. */ mutuallyExclusive?: ReadonlyArray; }; /** * @beta */ type ToolbarListSchemaType = ListSchemaType & { icon?: React.ComponentType<{ className?: string; }>; }; /** * @beta */ type ToolbarBlockObjectSchemaType = BlockObjectSchemaType & { icon?: React.ComponentType<{ className?: string; }>; defaultValues?: Record; shortcut?: KeyboardShortcut; }; /** * @beta */ type ToolbarInlineObjectSchemaType = InlineObjectSchemaType & { icon?: React.ComponentType<{ className?: string; }>; defaultValues?: Record; shortcut?: KeyboardShortcut; }; /** * @beta */ type ToolbarStyleSchemaType = StyleSchemaType & { icon?: React.ComponentType<{ className?: string; }>; shortcut?: KeyboardShortcut; }; /** * @beta */ type AnnotationButtonEvent = { type: 'close dialog'; } | { type: 'open dialog'; } | { type: 'add'; annotation: { value: Record; }; } | { type: 'remove'; }; /** * @beta */ type AnnotationButton = { snapshot: { matches: (state: 'disabled' | 'enabled' | { disabled: 'inactive'; } | { disabled: 'active'; } | { enabled: 'inactive'; } | { enabled: { inactive: 'idle'; }; } | { enabled: { inactive: 'showing dialog'; }; } | { enabled: 'active'; }) => boolean; }; send: (event: AnnotationButtonEvent) => void; }; /** * @beta * Manages the state, keyboard shortcut and available events for an annotation * button. * * Note: This hook assumes that the button triggers a dialog for inputting * the annotation value. */ declare function useAnnotationButton(props: { schemaType: ToolbarAnnotationSchemaType; }): AnnotationButton; type ActiveContext$2 = { annotations: Array<{ value: PortableTextObject; schemaType: ToolbarAnnotationSchemaType; at: AnnotationPath; }>; elementRef: RefObject; }; /** * @beta */ type AnnotationPopoverEvent = { type: 'remove'; schemaType: AnnotationSchemaType; } | { type: 'edit'; at: AnnotationPath; props: { [key: string]: unknown; }; } | { type: 'close'; }; /** * @beta */ type AnnotationPopover = { snapshot: { context: ActiveContext$2; matches: (state: 'disabled' | 'enabled' | { enabled: 'inactive' | 'active'; }) => boolean; }; send: (event: AnnotationPopoverEvent) => void; }; /** * @beta * Manages the state and available events for an annotation popover. */ declare function useAnnotationPopover(props: { schemaTypes: ReadonlyArray; }): AnnotationPopover; /** * @beta */ type BlockObjectButtonEvent = { type: 'close dialog'; } | { type: 'open dialog'; } | { type: 'insert'; value: { [key: string]: unknown; }; placement: InsertPlacement | undefined; }; /** * @beta */ type BlockObjectButton = { snapshot: { matches: (state: 'disabled' | 'enabled' | { enabled: 'idle'; } | { enabled: 'showing dialog'; }) => boolean; }; send: (event: BlockObjectButtonEvent) => void; }; /** * @beta * Manages the state, keyboard shortcut and available events for a block * object button. * * Note: This hook assumes that the button triggers a dialog for inputting * the block object value. */ declare function useBlockObjectButton(props: { schemaType: ToolbarBlockObjectSchemaType; }): BlockObjectButton; type ActiveContext$1 = { blockObjects: Array<{ value: PortableTextObject; schemaType: ToolbarBlockObjectSchemaType; at: BlockPath; }>; elementRef: RefObject; }; /** * @beta */ type BlockObjectPopoverEvent = { type: 'remove'; at: BlockPath; } | { type: 'edit'; at: BlockPath; props: { [key: string]: unknown; }; } | { type: 'close'; }; /** * @beta */ type BlockObjectPopover = { snapshot: { context: ActiveContext$1; matches: (state: 'disabled' | 'enabled' | { enabled: 'inactive' | 'active'; }) => boolean; }; send: (event: BlockObjectPopoverEvent) => void; }; /** * @beta * Manages the state and available events for a block object popover. */ declare function useBlockObjectPopover(props: { schemaTypes: ReadonlyArray; }): BlockObjectPopover; /** * @beta */ type DecoratorButtonEvent = { type: 'toggle'; }; /** * @beta */ type DecoratorButton = { snapshot: { matches: (state: 'disabled' | 'enabled' | { disabled: 'inactive'; } | { disabled: 'active'; } | { enabled: 'inactive'; } | { enabled: 'active'; }) => boolean; }; send: (event: DecoratorButtonEvent) => void; }; /** * @beta * Manages the state, keyboard shortcuts and available events for a decorator * button and sets up mutually exclusive decorator behaviors. */ declare function useDecoratorButton(props: { schemaType: ToolbarDecoratorSchemaType; }): DecoratorButton; /** * @beta */ type HistoryButtonsEvent = { type: 'history.undo'; } | { type: 'history.redo'; }; /** * @beta */ type HistoryButtons = { snapshot: { matches: (state: 'disabled' | 'enabled') => boolean; }; send: (event: HistoryButtonsEvent) => void; }; /** * @beta */ declare function useHistoryButtons(): HistoryButtons; /** * @beta */ type InlineObjectButtonEvent = { type: 'close dialog'; } | { type: 'open dialog'; } | { type: 'insert'; value: { [key: string]: unknown; }; }; /** * @beta */ type InlineObjectButton = { snapshot: { matches: (state: 'disabled' | 'enabled' | { enabled: 'idle'; } | { enabled: 'showing dialog'; }) => boolean; }; send: (event: InlineObjectButtonEvent) => void; }; /** * @beta * Manages the state, keyboard shortcut and available events for an inline * object button. * * Note: This hook assumes that the button triggers a dialog for inputting * the inline object value. */ declare function useInlineObjectButton(props: { schemaType: ToolbarInlineObjectSchemaType; }): InlineObjectButton; type ActiveContext = { inlineObjects: Array<{ value: PortableTextObject; schemaType: ToolbarInlineObjectSchemaType; at: ChildPath; }>; elementRef: RefObject; }; /** * @beta */ type InlineObjectPopoverEvent = { type: 'remove'; at: ChildPath; } | { type: 'edit'; at: ChildPath; props: { [key: string]: unknown; }; } | { type: 'close'; }; /** * @beta */ type InlineObjectPopover = { snapshot: { context: ActiveContext; matches: (state: 'disabled' | 'enabled' | { enabled: 'inactive' | 'active'; }) => boolean; }; send: (event: InlineObjectPopoverEvent) => void; }; /** * @beta * Manages the state and available events for an inline object popover. */ declare function useInlineObjectPopover(props: { schemaTypes: ReadonlyArray; }): InlineObjectPopover; /** * @beta */ type ListButtonEvent = { type: 'toggle'; }; /** * @beta */ type ListButton = { snapshot: { matches: (state: 'disabled' | 'enabled' | { disabled: 'inactive'; } | { disabled: 'active'; } | { enabled: 'inactive'; } | { enabled: 'active'; }) => boolean; }; send: (event: ListButtonEvent) => void; }; /** * @beta * Manages the state, keyboard shortcuts and available events for a list button. */ declare function useListButton(props: { schemaType: ToolbarListSchemaType; }): ListButton; /** * @beta */ type StyleSelectorEvent = { type: 'toggle'; style: StyleSchemaType['name']; }; /** * @beta */ type StyleSelector = { snapshot: { matches: (state: 'disabled' | 'enabled') => boolean; context: { activeStyle: StyleSchemaType['name'] | undefined; }; }; send: (event: StyleSelectorEvent) => void; }; /** * @beta * Manages the state, keyboard shortcuts and available events for a style * selector. */ declare function useStyleSelector(props: { schemaTypes: ReadonlyArray; }): StyleSelector; export { AnnotationButton, AnnotationButtonEvent, AnnotationPopover, AnnotationPopoverEvent, type ApplicableSchema, BlockObjectButton, BlockObjectButtonEvent, BlockObjectPopover, BlockObjectPopoverEvent, DecoratorButton, DecoratorButtonEvent, ExtendAnnotationSchemaType, ExtendBlockObjectSchemaType, ExtendDecoratorSchemaType, ExtendInlineObjectSchemaType, ExtendListSchemaType, ExtendStyleSchemaType, HistoryButtons, HistoryButtonsEvent, InlineObjectButton, InlineObjectButtonEvent, InlineObjectPopover, InlineObjectPopoverEvent, ListButton, ListButtonEvent, StyleSelector, StyleSelectorEvent, ToolbarAnnotationSchemaType, ToolbarBlockObjectSchemaType, ToolbarDecoratorSchemaType, ToolbarInlineObjectSchemaType, ToolbarListSchemaType, ToolbarSchema, ToolbarStyleSchemaType, useAnnotationButton, useAnnotationPopover, useApplicableSchema, useBlockObjectButton, useBlockObjectPopover, useDecoratorButton, useHistoryButtons, useInlineObjectButton, useInlineObjectPopover, useListButton, useStyleSelector, useToolbarSchema }; //# sourceMappingURL=index.d.ts.map