@udecode/plate-mention
Advanced tools
Comparing version 24.3.2 to 24.3.5
@@ -1,846 +0,8 @@ | ||
import { Scope } from 'jotai/core/atom'; | ||
import React__default, { FC, ReactNode, KeyboardEvent, ClipboardEvent, CompositionEvent, FocusEvent, FormEvent, SyntheticEvent, MouseEvent, DragEvent, TouchEvent, PointerEvent, UIEvent, WheelEvent, AnimationEvent, TransitionEvent, CSSProperties, ForwardedRef } from 'react'; | ||
import { Value as Value$1, TEditor as TEditor$1, THistoryEditor, TRange as TRange$1, TElement as TElement$1, EElement, EElementOrText, TText as TText$1, EText, ENodeEntry, TNodeEntry as TNodeEntry$1 } from '@udecode/slate'; | ||
import { TReactEditor, TRenderLeafProps, RenderLeafFn } from '@udecode/slate-react'; | ||
import { AnyObject, WithRequired, UnknownObject, Modify } from '@udecode/utils'; | ||
import { Path, Range, Editor } from 'slate'; | ||
import { RenderElementProps } from 'slate-react'; | ||
import { EditableProps } from 'slate-react/dist/components/editable'; | ||
import * as _udecode_plate_core from '@udecode/plate-core'; | ||
import * as _udecode_slate from '@udecode/slate'; | ||
import { Data, TComboboxItem, ComboboxOnSelectItem, NoData } from '@udecode/plate-combobox'; | ||
import { TNodeProps, PlatePluginKey as PlatePluginKey$1, TElement as TElement$2, PlateEditor as PlateEditor$1, Value as Value$2, WithPlatePlugin as WithPlatePlugin$1, HandlerReturnType as HandlerReturnType$1, FindNodeOptions, TNode as TNode$1 } from '@udecode/plate-common'; | ||
import { TNodeProps, PlatePluginKey, TElement, PlateEditor, Value, WithPlatePlugin, HandlerReturnType, FindNodeOptions, TNode } from '@udecode/plate-common'; | ||
import { KeyboardEvent } from 'react'; | ||
import { Path } from 'slate'; | ||
type SetRecord<O> = { | ||
[K in keyof O]: (scope?: Scope) => (value: O[K]) => void; | ||
}; | ||
/** | ||
* A unique id used as a provider scope. | ||
* Use it if you have multiple `Plate` in the same React tree. | ||
* @default PLATE_SCOPE | ||
*/ | ||
type PlateId = string; | ||
type NoInfer<T> = [T][T extends any ? 0 : never]; | ||
type Nullable<T> = { | ||
[P in keyof T]: T[P] | null; | ||
}; | ||
/** | ||
* If true, the next handlers will be skipped. | ||
*/ | ||
type HandlerReturnType = boolean | void; | ||
type DOMHandlerReturnType<EV = {}> = (event: EV) => HandlerReturnType; | ||
type DOMHandler<P = PluginOptions, V extends Value$1 = Value$1, E extends PlateEditor<V> = PlateEditor<V>, EV = {}> = (editor: E, plugin: WithPlatePlugin<P, V, E>) => DOMHandlerReturnType<EV>; | ||
interface DOMHandlers<P = PluginOptions, V extends Value$1 = Value$1, E extends PlateEditor<V> = PlateEditor<V>> { | ||
onCopy?: DOMHandler<P, V, E, ClipboardEvent>; | ||
onCopyCapture?: DOMHandler<P, V, E, ClipboardEvent>; | ||
onCut?: DOMHandler<P, V, E, ClipboardEvent>; | ||
onCutCapture?: DOMHandler<P, V, E, ClipboardEvent>; | ||
onPaste?: DOMHandler<P, V, E, ClipboardEvent>; | ||
onPasteCapture?: DOMHandler<P, V, E, ClipboardEvent>; | ||
onCompositionEnd?: DOMHandler<P, V, E, CompositionEvent>; | ||
onCompositionEndCapture?: DOMHandler<P, V, E, CompositionEvent>; | ||
onCompositionStart?: DOMHandler<P, V, E, CompositionEvent>; | ||
onCompositionStartCapture?: DOMHandler<P, V, E, CompositionEvent>; | ||
onCompositionUpdate?: DOMHandler<P, V, E, CompositionEvent>; | ||
onCompositionUpdateCapture?: DOMHandler<P, V, E, CompositionEvent>; | ||
onFocus?: DOMHandler<P, V, E, FocusEvent>; | ||
onFocusCapture?: DOMHandler<P, V, E, FocusEvent>; | ||
onBlur?: DOMHandler<P, V, E, FocusEvent>; | ||
onBlurCapture?: DOMHandler<P, V, E, FocusEvent>; | ||
onDOMBeforeInput?: DOMHandler<P, V, E, Event>; | ||
onBeforeInput?: DOMHandler<P, V, E, FormEvent>; | ||
onBeforeInputCapture?: DOMHandler<P, V, E, FormEvent>; | ||
onInput?: DOMHandler<P, V, E, FormEvent>; | ||
onInputCapture?: DOMHandler<P, V, E, FormEvent>; | ||
onReset?: DOMHandler<P, V, E, FormEvent>; | ||
onResetCapture?: DOMHandler<P, V, E, FormEvent>; | ||
onSubmit?: DOMHandler<P, V, E, FormEvent>; | ||
onSubmitCapture?: DOMHandler<P, V, E, FormEvent>; | ||
onInvalid?: DOMHandler<P, V, E, FormEvent>; | ||
onInvalidCapture?: DOMHandler<P, V, E, FormEvent>; | ||
onLoad?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onLoadCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onKeyDown?: DOMHandler<P, V, E, KeyboardEvent>; | ||
onKeyDownCapture?: DOMHandler<P, V, E, KeyboardEvent>; | ||
onKeyPress?: DOMHandler<P, V, E, KeyboardEvent>; | ||
onKeyPressCapture?: DOMHandler<P, V, E, KeyboardEvent>; | ||
onKeyUp?: DOMHandler<P, V, E, KeyboardEvent>; | ||
onKeyUpCapture?: DOMHandler<P, V, E, KeyboardEvent>; | ||
onAbort?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onAbortCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onCanPlay?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onCanPlayCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onCanPlayThrough?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onCanPlayThroughCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onDurationChange?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onDurationChangeCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onEmptied?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onEmptiedCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onEncrypted?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onEncryptedCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onEnded?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onEndedCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onLoadedData?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onLoadedDataCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onLoadedMetadata?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onLoadedMetadataCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onLoadStart?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onLoadStartCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onPause?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onPauseCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onPlay?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onPlayCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onPlaying?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onPlayingCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onProgress?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onProgressCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onRateChange?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onRateChangeCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onSeeked?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onSeekedCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onSeeking?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onSeekingCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onStalled?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onStalledCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onSuspend?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onSuspendCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onTimeUpdate?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onTimeUpdateCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onVolumeChange?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onVolumeChangeCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onWaiting?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onWaitingCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onAuxClick?: DOMHandler<P, V, E, MouseEvent>; | ||
onAuxClickCapture?: DOMHandler<P, V, E, MouseEvent>; | ||
onClick?: DOMHandler<P, V, E, MouseEvent>; | ||
onClickCapture?: DOMHandler<P, V, E, MouseEvent>; | ||
onContextMenu?: DOMHandler<P, V, E, MouseEvent>; | ||
onContextMenuCapture?: DOMHandler<P, V, E, MouseEvent>; | ||
onDoubleClick?: DOMHandler<P, V, E, MouseEvent>; | ||
onDoubleClickCapture?: DOMHandler<P, V, E, MouseEvent>; | ||
onDrag?: DOMHandler<P, V, E, DragEvent>; | ||
onDragCapture?: DOMHandler<P, V, E, DragEvent>; | ||
onDragEnd?: DOMHandler<P, V, E, DragEvent>; | ||
onDragEndCapture?: DOMHandler<P, V, E, DragEvent>; | ||
onDragEnter?: DOMHandler<P, V, E, DragEvent>; | ||
onDragEnterCapture?: DOMHandler<P, V, E, DragEvent>; | ||
onDragExit?: DOMHandler<P, V, E, DragEvent>; | ||
onDragExitCapture?: DOMHandler<P, V, E, DragEvent>; | ||
onDragLeave?: DOMHandler<P, V, E, DragEvent>; | ||
onDragLeaveCapture?: DOMHandler<P, V, E, DragEvent>; | ||
onDragOver?: DOMHandler<P, V, E, DragEvent>; | ||
onDragOverCapture?: DOMHandler<P, V, E, DragEvent>; | ||
onDragStart?: DOMHandler<P, V, E, DragEvent>; | ||
onDragStartCapture?: DOMHandler<P, V, E, DragEvent>; | ||
onDrop?: DOMHandler<P, V, E, DragEvent>; | ||
onDropCapture?: DOMHandler<P, V, E, DragEvent>; | ||
onMouseDown?: DOMHandler<P, V, E, MouseEvent>; | ||
onMouseDownCapture?: DOMHandler<P, V, E, MouseEvent>; | ||
onMouseEnter?: DOMHandler<P, V, E, MouseEvent>; | ||
onMouseLeave?: DOMHandler<P, V, E, MouseEvent>; | ||
onMouseMove?: DOMHandler<P, V, E, MouseEvent>; | ||
onMouseMoveCapture?: DOMHandler<P, V, E, MouseEvent>; | ||
onMouseOut?: DOMHandler<P, V, E, MouseEvent>; | ||
onMouseOutCapture?: DOMHandler<P, V, E, MouseEvent>; | ||
onMouseOver?: DOMHandler<P, V, E, MouseEvent>; | ||
onMouseOverCapture?: DOMHandler<P, V, E, MouseEvent>; | ||
onMouseUp?: DOMHandler<P, V, E, MouseEvent>; | ||
onMouseUpCapture?: DOMHandler<P, V, E, MouseEvent>; | ||
onSelect?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onSelectCapture?: DOMHandler<P, V, E, SyntheticEvent>; | ||
onTouchCancel?: DOMHandler<P, V, E, TouchEvent>; | ||
onTouchCancelCapture?: DOMHandler<P, V, E, TouchEvent>; | ||
onTouchEnd?: DOMHandler<P, V, E, TouchEvent>; | ||
onTouchEndCapture?: DOMHandler<P, V, E, TouchEvent>; | ||
onTouchMove?: DOMHandler<P, V, E, TouchEvent>; | ||
onTouchMoveCapture?: DOMHandler<P, V, E, TouchEvent>; | ||
onTouchStart?: DOMHandler<P, V, E, TouchEvent>; | ||
onTouchStartCapture?: DOMHandler<P, V, E, TouchEvent>; | ||
onPointerDown?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerDownCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerMove?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerMoveCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerUp?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerUpCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerCancel?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerCancelCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerEnter?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerEnterCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerLeave?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerLeaveCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerOver?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerOverCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerOut?: DOMHandler<P, V, E, PointerEvent>; | ||
onPointerOutCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onGotPointerCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onGotPointerCaptureCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onLostPointerCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onLostPointerCaptureCapture?: DOMHandler<P, V, E, PointerEvent>; | ||
onScroll?: DOMHandler<P, V, E, UIEvent>; | ||
onScrollCapture?: DOMHandler<P, V, E, UIEvent>; | ||
onWheel?: DOMHandler<P, V, E, WheelEvent>; | ||
onWheelCapture?: DOMHandler<P, V, E, WheelEvent>; | ||
onAnimationStart?: DOMHandler<P, V, E, AnimationEvent>; | ||
onAnimationStartCapture?: DOMHandler<P, V, E, AnimationEvent>; | ||
onAnimationEnd?: DOMHandler<P, V, E, AnimationEvent>; | ||
onAnimationEndCapture?: DOMHandler<P, V, E, AnimationEvent>; | ||
onAnimationIteration?: DOMHandler<P, V, E, AnimationEvent>; | ||
onAnimationIterationCapture?: DOMHandler<P, V, E, AnimationEvent>; | ||
onTransitionEnd?: DOMHandler<P, V, E, TransitionEvent>; | ||
onTransitionEndCapture?: DOMHandler<P, V, E, TransitionEvent>; | ||
} | ||
type DecorateEntry<V extends Value$1 = Value$1> = (entry: ENodeEntry<V>) => Range[] | undefined; | ||
/** | ||
* Property used by Plate to decorate editor ranges. | ||
* If the function returns undefined then no ranges are modified. | ||
* If the function returns an array the returned ranges are merged with the ranges called by other plugins. | ||
*/ | ||
type Decorate<P = PluginOptions, V extends Value$1 = Value$1, E extends PlateEditor<V> = PlateEditor<V>> = (editor: PlateEditor<V>, plugin: WithPlatePlugin<P, V, E>) => DecorateEntry<V>; | ||
type DeserializeHtml = { | ||
/** | ||
* List of HTML attribute names to store their values in `node.attributes`. | ||
*/ | ||
attributeNames?: string[]; | ||
/** | ||
* Deserialize an element. | ||
* Use this instead of plugin.isElement if you don't want the plugin to renderElement. | ||
* @default plugin.isElement | ||
*/ | ||
isElement?: boolean; | ||
/** | ||
* Deserialize a leaf. | ||
* Use this instead of plugin.isLeaf if you don't want the plugin to renderLeaf. | ||
* @default plugin.isLeaf | ||
*/ | ||
isLeaf?: boolean; | ||
/** | ||
* Deserialize html element to slate node. | ||
*/ | ||
getNode?: (element: HTMLElement, node: AnyObject) => AnyObject | undefined | void; | ||
query?: (element: HTMLElement) => boolean; | ||
rules?: { | ||
/** | ||
* Deserialize an element: | ||
* - if this option (string) is in the element attribute names. | ||
* - if this option (object) values match the element attributes. | ||
*/ | ||
validAttribute?: string | { | ||
[key: string]: string | string[]; | ||
}; | ||
/** | ||
* Valid element `className`. | ||
*/ | ||
validClassName?: string; | ||
/** | ||
* Valid element `nodeName`. | ||
* Set '*' to allow any node name. | ||
*/ | ||
validNodeName?: string | string[]; | ||
/** | ||
* Valid element style values. | ||
* Can be a list of string (only one match is needed). | ||
*/ | ||
validStyle?: Partial<Record<keyof CSSStyleDeclaration, string | string[] | undefined>>; | ||
}[]; | ||
/** | ||
* Whether or not to include deserialized children on this node | ||
*/ | ||
withoutChildren?: boolean; | ||
}; | ||
type TRenderElementProps<V extends Value$1 = Value$1, N extends TElement$1 = EElement<V>> = Omit<RenderElementProps, 'element'> & { | ||
element: N; | ||
}; | ||
type RenderElementFn = (props: TRenderElementProps) => React.ReactElement; | ||
/** | ||
* Element props passed by Plate | ||
*/ | ||
type PlateRenderElementProps<V extends Value$1 = Value$1, N extends TElement$1 = EElement<V>> = PlateRenderNodeProps<V> & TRenderElementProps<V, N>; | ||
interface InjectComponentProps<V extends Value$1 = Value$1> extends PlateRenderElementProps<V> { | ||
key: string; | ||
} | ||
type InjectComponentReturnType<V extends Value$1 = Value$1> = React__default.FC<PlateRenderElementProps<V>> | undefined; | ||
type InjectComponent<V extends Value$1 = Value$1> = (props: InjectComponentProps<V>) => InjectComponentReturnType; | ||
interface GetInjectPropsOptions<V extends Value$1 = Value$1> { | ||
/** | ||
* Existing className. | ||
*/ | ||
className?: string; | ||
/** | ||
* Style value or className key. | ||
*/ | ||
element?: EElement<V>; | ||
/** | ||
* Style value or className key. | ||
*/ | ||
text?: EText<V>; | ||
/** | ||
* Existing style. | ||
*/ | ||
style?: CSSProperties; | ||
} | ||
interface GetInjectPropsReturnType extends AnyObject { | ||
className?: string; | ||
style?: CSSProperties; | ||
} | ||
interface TransformOptions<V extends Value$1 = Value$1> extends GetInjectPropsOptions<V> { | ||
nodeValue?: any; | ||
value?: any; | ||
} | ||
interface InjectProps<V extends Value$1> { | ||
inject?: { | ||
/** | ||
* Properties used by Plate to inject props into any node `component`. | ||
*/ | ||
props?: { | ||
/** | ||
* Object whose keys are node values and values are classNames which will be extended. | ||
*/ | ||
classNames?: AnyObject; | ||
/** | ||
* Default node value. | ||
* The node key would be unset if the node value = defaultNodeValue. | ||
*/ | ||
defaultNodeValue?: any; | ||
/** | ||
* Node key to map to the styles. | ||
*/ | ||
nodeKey?: string; | ||
/** | ||
* Whether to inject the props. If true, overrides all other checks. | ||
*/ | ||
query?: (options: NonNullable<NonNullable<InjectProps<V>['inject']>['props']>, nodeProps: GetInjectPropsOptions<V>) => boolean; | ||
/** | ||
* Style key to override. | ||
* @default nodeKey | ||
*/ | ||
styleKey?: keyof CSSProperties; | ||
/** | ||
* Transform the className. | ||
* @default clsx(className, classNames[value]) | ||
*/ | ||
transformClassName?: (options: TransformOptions<V>) => any; | ||
/** | ||
* Transform the node value for the style or className. | ||
* @default nodeValue | ||
*/ | ||
transformNodeValue?: (options: TransformOptions<V>) => any; | ||
/** | ||
* Transform the injected props. | ||
*/ | ||
transformProps?: (options: TransformOptions<V>, props: GetInjectPropsReturnType) => AnyObject | undefined; | ||
/** | ||
* Transform the style. | ||
* @default { ...style, [styleKey]: value } | ||
*/ | ||
transformStyle?: (options: TransformOptions<V>) => CSSProperties; | ||
/** | ||
* List of supported node values. | ||
*/ | ||
validNodeValues?: any[]; | ||
/** | ||
* Node types required to inject the props. | ||
* @default [ELEMENT_DEFAULT] | ||
*/ | ||
validTypes?: string[]; | ||
}; | ||
}; | ||
} | ||
/** | ||
* Function called whenever a change occurs in the editor. | ||
* Return `false` to prevent calling the next plugin handler. | ||
* @see {@link SlatePropsOnChange} | ||
*/ | ||
type OnChange<P = PluginOptions, V extends Value$1 = Value$1, E extends PlateEditor<V> = PlateEditor<V>> = (editor: E, plugin: WithPlatePlugin<P, V, E>) => (value: V) => HandlerReturnType; | ||
/** | ||
* The plate plugin component. | ||
*/ | ||
type PlatePluginComponent<T = any> = React__default.FC<T>; | ||
type PlatePluginInsertDataOptions = { | ||
data: string; | ||
dataTransfer: DataTransfer; | ||
}; | ||
type PlatePluginInsertData<V extends Value$1 = Value$1> = { | ||
/** | ||
* Format to get data. Example data types are text/plain and text/uri-list. | ||
*/ | ||
format?: string; | ||
/** | ||
* Query to skip this plugin. | ||
*/ | ||
query?: (options: PlatePluginInsertDataOptions) => boolean; | ||
/** | ||
* Deserialize data to fragment | ||
*/ | ||
getFragment?: (options: PlatePluginInsertDataOptions) => EElementOrText<V>[] | undefined; | ||
/** | ||
* Function called on `editor.insertData` just before `editor.insertFragment`. | ||
* Default: if the block above the selection is empty and the first fragment node type is not inline, | ||
* set the selected node type to the first fragment node type. | ||
* @return if true, the next handlers will be skipped. | ||
*/ | ||
preInsert?: (fragment: EElementOrText<V>[], options: PlatePluginInsertDataOptions) => HandlerReturnType; | ||
/** | ||
* Transform the inserted data. | ||
*/ | ||
transformData?: (data: string, options: { | ||
dataTransfer: DataTransfer; | ||
}) => string; | ||
/** | ||
* Transform the fragment to insert. | ||
*/ | ||
transformFragment?: (fragment: EElementOrText<V>[], options: PlatePluginInsertDataOptions) => EElementOrText<V>[]; | ||
}; | ||
/** | ||
* Unique key to store the plugins by key. | ||
*/ | ||
type PluginKey = string; | ||
interface PlatePluginKey { | ||
/** | ||
* Property used by Plate to store the plugins by key in `editor.pluginsByKey`. | ||
*/ | ||
key?: PluginKey; | ||
} | ||
/** | ||
* Props object or function returning props object. | ||
*/ | ||
type PlatePluginProps<V extends Value$1 = Value$1> = AnyObject | ((props: PlateRenderElementProps<V> & PlateRenderLeafProps<V>) => AnyObject | undefined); | ||
/** | ||
* `EditableProps` are passed to the <Editable> component. | ||
*/ | ||
type TEditableProps = Omit<EditableProps, 'decorate' | 'renderElement' | 'renderLeaf'> & { | ||
decorate?: (entry: TNodeEntry$1) => Range[]; | ||
renderElement?: RenderElementFn; | ||
renderLeaf?: RenderLeafFn; | ||
}; | ||
type RenderAfterEditable = (editableProps: TEditableProps) => React.ReactElement | null; | ||
type SerializeHtml<V extends Value$1 = Value$1> = React__default.FC<PlateRenderElementProps<V> & PlateRenderLeafProps<V>>; | ||
/** | ||
* Plate plugin overriding the `editor` methods. | ||
* Naming convention is `with*`. | ||
*/ | ||
type WithOverride<P = PluginOptions, V extends Value$1 = Value$1, E extends PlateEditor<V> = PlateEditor<V>, EE extends E = E> = (editor: E, plugin: WithPlatePlugin<P, V, E>) => EE; | ||
/** | ||
* The `PlatePlugin` interface is a base interface for all plugins. | ||
*/ | ||
type PlatePlugin<P = PluginOptions, V extends Value$1 = Value$1, E extends PlateEditor<V> = PlateEditor<V>> = Required<PlatePluginKey> & { | ||
editor?: Nullable<{ | ||
/** | ||
* Properties used by the `insertData` core plugin to deserialize inserted data to a slate fragment. | ||
* The fragment will be inserted to the editor if not empty. | ||
*/ | ||
insertData?: PlatePluginInsertData<V>; | ||
}>; | ||
/** | ||
* Handlers called whenever the corresponding event occurs in the editor. | ||
* Event handlers can return a boolean flag to specify whether the event can be treated as being handled. | ||
* If it returns `true`, the next handlers will not be called. | ||
*/ | ||
handlers?: Nullable<DOMHandlers<P, V, E> & { | ||
/** | ||
* @see {@link OnChange} | ||
*/ | ||
onChange?: OnChange<P, V, E>; | ||
}>; | ||
/** | ||
* Inject into Plate. | ||
*/ | ||
inject?: Nullable<{ | ||
/** | ||
* Property used by Plate to inject a component above other plugins `component`. | ||
*/ | ||
aboveComponent?: InjectComponent<V>; | ||
/** | ||
* Property used by Plate to inject a component below other plugins `component`, i.e. above its `children`. | ||
*/ | ||
belowComponent?: InjectComponent<V>; | ||
/** | ||
* Property that can be used by a plugin to allow other plugins to inject code. | ||
* For example, if multiple plugins have defined | ||
* `inject.editor.insertData.transformData` for `key=KEY_DESERIALIZE_HTML`, | ||
* `insertData` plugin will call all of these `transformData` for `KEY_DESERIALIZE_HTML` plugin. | ||
* Differs from `overrideByKey` as this is not overriding any plugin. | ||
*/ | ||
pluginsByKey?: Record<PluginKey, Partial<PlatePlugin<PluginOptions, V, E>>>; | ||
}>; | ||
/** | ||
* Property used by Plate to render nodes of this `type` as elements, i.e. `renderElement`. | ||
*/ | ||
isElement?: boolean; | ||
/** | ||
* Property used by `inlineVoid` core plugin to set elements of this `type` as inline. | ||
*/ | ||
isInline?: boolean; | ||
/** | ||
* Property used by `isMarkableVoid` core plugin to set void elements of this `type` as markable. | ||
*/ | ||
isMarkableVoid?: boolean; | ||
/** | ||
* Property used by Plate to render nodes of this `type` as leaves, i.e. `renderLeaf`. | ||
*/ | ||
isLeaf?: boolean; | ||
/** | ||
* Property used by `inlineVoid` core plugin to set elements of this `type` as void. | ||
*/ | ||
isVoid?: boolean; | ||
/** | ||
* Property used by Plate to enable/disable the plugin. | ||
*/ | ||
enabled?: boolean; | ||
/** | ||
* Extended properties used by any plugin as options. | ||
*/ | ||
options?: P; | ||
/** | ||
* Property used by Plate to render a node by type. | ||
* It requires slate node properties to have a `type` property. | ||
* @default key | ||
*/ | ||
type?: string; | ||
} & InjectProps<V> & Nullable<{ | ||
/** | ||
* React component rendering a slate element or leaf. | ||
* @default DefaultElement | DefaultLeaf | ||
*/ | ||
component?: PlatePluginComponent; | ||
/** | ||
* @see {@link Decorate} | ||
*/ | ||
decorate?: Decorate<P, V, E>; | ||
/** | ||
* Properties used by the HTML deserializer core plugin for each HTML element. | ||
*/ | ||
deserializeHtml?: Nullable<DeserializeHtml>; | ||
/** | ||
* Normalize initial value before passing it into the editor. | ||
* @return normalized value | ||
*/ | ||
normalizeInitialValue?: (initialValue: V) => V; | ||
/** | ||
* Property used by Plate to deeply override plugins by key. | ||
*/ | ||
overrideByKey?: Record<PluginKey, Partial<PlatePlugin<PluginOptions, V, E>>>; | ||
/** | ||
* Recursive plugin support to allow having multiple plugins in a single plugin. | ||
* Plate eventually flattens all the plugins into the editor. | ||
*/ | ||
plugins?: PlatePlugin<PluginOptions, V, E>[]; | ||
/** | ||
* Property used by Plate to override node `component` props. | ||
* If function, its returning value will be shallow merged to the old props, with the old props as parameter. | ||
* If object, its value will be shallow merged to the old props. | ||
*/ | ||
props?: PlatePluginProps<V>; | ||
/** | ||
* Render a component above `Editable`. | ||
*/ | ||
renderAboveEditable?: FC<{ | ||
children: ReactNode; | ||
}>; | ||
/** | ||
* Render a component above `Slate`. | ||
*/ | ||
renderAboveSlate?: FC<{ | ||
children: ReactNode; | ||
}>; | ||
/** | ||
* Render a component after `Editable`. | ||
*/ | ||
renderAfterEditable?: RenderAfterEditable; | ||
/** | ||
* Render a component before `Editable`. | ||
*/ | ||
renderBeforeEditable?: RenderAfterEditable; | ||
/** | ||
* Property used by `serializeHtml` util to replace `renderElement` and `renderLeaf` when serializing a node of this `type`. | ||
*/ | ||
serializeHtml?: SerializeHtml<V>; | ||
/** | ||
* Recursive plugin merging. | ||
* Can be used to derive plugin fields from `editor` and `plugin`. | ||
* The returned value will be deeply merged to the plugin. | ||
*/ | ||
then?: (editor: E, plugin: WithPlatePlugin<P, V, E>) => Partial<PlatePlugin<PluginOptions, V, E>> | undefined | void; | ||
/** | ||
* For internal use. Tracks if then has been replaced for recursive calls. | ||
*/ | ||
_thenReplaced?: number; | ||
/** | ||
* Hook called when the editor is initialized. | ||
*/ | ||
useHooks?: (editor: E, plugin: WithPlatePlugin<P, V, E>) => void; | ||
/** | ||
* Editor method overriders. | ||
*/ | ||
withOverrides?: WithOverride<P, V, E>; | ||
}>; | ||
type PluginOptions = AnyObject; | ||
type WithPlatePlugin<P = PluginOptions, V extends Value$1 = Value$1, E extends PlateEditor<V> = PlateEditor<V>> = WithRequired<PlatePlugin<P, V, E>, 'type' | 'options' | 'inject' | 'editor'>; | ||
type OverrideByKey<V extends Value$1 = Value$1, E extends PlateEditor<V> = PlateEditor<V>> = Record<PluginKey, Partial<PlatePlugin<{}, V, E>>>; | ||
type PlateStoreState<V extends Value$1 = Value$1, E extends PlateEditor<V> = PlateEditor<V>> = { | ||
/** | ||
* A unique id used as a provider scope. | ||
* Use it if you have multiple `Plate` in the same React tree. | ||
* @default PLATE_SCOPE | ||
*/ | ||
id: PlateId; | ||
/** | ||
* Slate editor reference. | ||
* @default pipe(createTEditor(), withPlate({ id, plugins, options, components })) | ||
*/ | ||
editor: E; | ||
/** | ||
* Plugins prop passed to `Plate`. | ||
*/ | ||
rawPlugins: PlatePlugin<PluginOptions, V, E>[]; | ||
readOnly: boolean; | ||
/** | ||
* Flattened plugins. | ||
*/ | ||
plugins: WithPlatePlugin<PluginOptions, V, E>[]; | ||
/** | ||
* Value of the editor. | ||
* @default [{ type: 'p', children: [{ text: '' }]}] | ||
*/ | ||
value: V; | ||
} & Nullable<{ | ||
/** | ||
* Whether `Editable` is rendered so slate DOM is resolvable. | ||
*/ | ||
isMounted: boolean; | ||
/** | ||
* Version incremented on each editor change. | ||
*/ | ||
versionEditor: number; | ||
/** | ||
* Version incremented on each editor.selection change. | ||
*/ | ||
versionSelection: number; | ||
/** | ||
* Version incremented when calling `redecorate`. | ||
* This is a dependency of the `decorate` function. | ||
*/ | ||
versionDecorate: number; | ||
/** | ||
* Controlled callback called when the editor state changes. | ||
*/ | ||
onChange: { | ||
fn: (value: V) => void; | ||
}; | ||
/** | ||
* Access the editor object using a React ref. | ||
*/ | ||
editorRef: { | ||
ref: ForwardedRef<E>; | ||
}; | ||
decorate: { | ||
fn: NonNullable<TEditableProps['decorate']>; | ||
}; | ||
renderElement: { | ||
fn: NonNullable<TEditableProps['renderElement']>; | ||
}; | ||
renderLeaf: { | ||
fn: NonNullable<TEditableProps['renderLeaf']>; | ||
}; | ||
}>; | ||
declare const EXPOSED_STORE_KEYS: (keyof PlateStoreState)[]; | ||
type PlateEditorMethods<V extends Value$1 = Value$1> = { | ||
reset: () => void; | ||
redecorate: () => void; | ||
plate: { | ||
set: { | ||
[K in (typeof EXPOSED_STORE_KEYS)[number]]: ReturnType<SetRecord<PlateStoreState<V>>[K]>; | ||
}; | ||
}; | ||
}; | ||
type PlateEditor<V extends Value$1 = Value$1> = TEditor$1<V> & THistoryEditor<V> & TReactEditor<V> & PlateEditorMethods<V> & { | ||
key: any; | ||
plugins: WithPlatePlugin<{}, V>[]; | ||
pluginsByKey: Record<PluginKey, WithPlatePlugin<{}, V>>; | ||
prevSelection: TRange$1 | null; | ||
/** | ||
* Default block factory. | ||
* @default [{ type: getPluginType(editor, ELEMENT_DEFAULT), children: [{ text: '' }] }] | ||
*/ | ||
blockFactory: (node?: Partial<TElement$1>, path?: Path) => EElement<V>; | ||
/** | ||
* Editor children factory. | ||
* @default [editor.blockFactory()] | ||
*/ | ||
childrenFactory: () => V; | ||
currentKeyboardEvent: KeyboardEvent | null; | ||
}; | ||
/** | ||
* Node props passed by Plate | ||
*/ | ||
interface PlateRenderNodeProps<V extends Value$1, E extends PlateEditor<V> = PlateEditor<V>> { | ||
className?: string; | ||
editor: E; | ||
/** | ||
* @see {@link NodeProps} | ||
*/ | ||
nodeProps?: AnyObject; | ||
} | ||
/** | ||
* Leaf props passed by Plate | ||
*/ | ||
type PlateRenderLeafProps<V extends Value$1 = Value$1, N extends TText$1 = EText<V>> = PlateRenderNodeProps<V> & TRenderLeafProps<V, N>; | ||
/** | ||
* `Text` objects represent the nodes that contain the actual text content of a | ||
* Slate document along with any formatting properties. They are always leaf | ||
* nodes in the document tree as they cannot contain any children. | ||
*/ | ||
type TText = UnknownObject & { | ||
text: string; | ||
}; | ||
type TNode = TEditor | TElement | TText; | ||
/** | ||
* `Element` objects are a type of node in a Slate document that contain other | ||
* element nodes or text nodes. They can be either "blocks" or "inlines" | ||
* depending on the Slate editor's configuration. | ||
*/ | ||
type TElement = UnknownObject & { | ||
children: TDescendant[]; | ||
type: string; | ||
}; | ||
/** | ||
* The `Descendant` union type represents nodes that are descendants in the | ||
* tree. It is returned as a convenience in certain cases to narrow a value | ||
* further than the more generic `Node` union. | ||
*/ | ||
type TDescendant = TElement | TText; | ||
type TPath = Path; | ||
type TRange = Range; | ||
type TInsertNodeOperation<N extends TDescendant = TDescendant> = { | ||
type: 'insert_node'; | ||
path: TPath; | ||
node: N; | ||
[key: string]: unknown; | ||
}; | ||
type TInsertTextOperation = { | ||
type: 'insert_text'; | ||
path: TPath; | ||
offset: number; | ||
text: string; | ||
[key: string]: unknown; | ||
}; | ||
type TMergeNodeOperation = { | ||
type: 'merge_node'; | ||
path: TPath; | ||
position: number; | ||
properties: object; | ||
[key: string]: unknown; | ||
}; | ||
type TMoveNodeOperation = { | ||
type: 'move_node'; | ||
path: TPath; | ||
newPath: TPath; | ||
[key: string]: unknown; | ||
}; | ||
type TRemoveNodeOperation<N extends TDescendant = TDescendant> = { | ||
type: 'remove_node'; | ||
path: TPath; | ||
node: N; | ||
[key: string]: unknown; | ||
}; | ||
type TRemoveTextOperation = { | ||
type: 'remove_text'; | ||
path: TPath; | ||
offset: number; | ||
text: string; | ||
[key: string]: unknown; | ||
}; | ||
type TSetNodeOperation = { | ||
type: 'set_node'; | ||
path: TPath; | ||
properties: object; | ||
newProperties: object; | ||
[key: string]: unknown; | ||
}; | ||
type TSetSelectionOperation = { | ||
type: 'set_selection'; | ||
properties: null; | ||
newProperties: TRange; | ||
[key: string]: unknown; | ||
} | { | ||
type: 'set_selection'; | ||
properties: Partial<TRange>; | ||
newProperties: Partial<TRange>; | ||
[key: string]: unknown; | ||
} | { | ||
type: 'set_selection'; | ||
properties: TRange; | ||
newProperties: null; | ||
[key: string]: unknown; | ||
}; | ||
type TSplitNodeOperation = { | ||
type: 'split_node'; | ||
path: TPath; | ||
position: number; | ||
properties: object; | ||
[key: string]: unknown; | ||
}; | ||
type TNodeOperation<N extends TDescendant = TDescendant> = TInsertNodeOperation<N> | TMergeNodeOperation | TMoveNodeOperation | TRemoveNodeOperation<N> | TSetNodeOperation | TSplitNodeOperation; | ||
type TSelectionOperation = TSetSelectionOperation; | ||
type TTextOperation = TInsertTextOperation | TRemoveTextOperation; | ||
/** | ||
* `Operation` objects define the low-level instructions that Slate editors use | ||
* to apply changes to their internal state. Representing all changes as | ||
* operations is what allows Slate editors to easily implement history, | ||
* collaboration, and other features. | ||
*/ | ||
type TOperation<N extends TDescendant = TDescendant> = TNodeOperation<N> | TSelectionOperation | TTextOperation; | ||
/** | ||
* `TNodeEntry` objects are returned when iterating over the nodes in a Slate | ||
* document tree. They consist of the node and its `Path` relative to the root | ||
* node in the document. | ||
*/ | ||
type TNodeEntry<N extends TNode = TNode> = [N, Path]; | ||
type Value = TElement[]; | ||
type TEditor<V extends Value = Value> = Modify<Editor, { | ||
id: any; | ||
children: V; | ||
operations: TOperation[]; | ||
marks: Record<string, any> | null; | ||
isInline: <N extends TElement>(element: N) => boolean; | ||
isVoid: <N extends TElement>(element: N) => boolean; | ||
markableVoid: <N extends TElement>(element: N) => boolean; | ||
normalizeNode: <N extends TNode>(entry: TNodeEntry<N>) => void; | ||
apply: <N extends TDescendant>(operation: TOperation<N>) => void; | ||
getFragment: <N extends TDescendant>() => N[]; | ||
insertFragment: <N extends TDescendant>(fragment: N[]) => void; | ||
insertNode: <N extends TDescendant>(node: N) => void; | ||
getDirtyPaths: <N extends TDescendant>(operation: TOperation<N>) => Path[]; | ||
}> & UnknownObject; | ||
interface CreateMentionNode<TData extends Data> { | ||
@@ -852,8 +14,8 @@ (item: TComboboxItem<TData>, meta: CreateMentionNodeMeta): TNodeProps<TMentionElement>; | ||
} | ||
declare const getMentionOnSelectItem: <TData extends unknown = undefined>({ key, }?: PlatePluginKey$1) => ComboboxOnSelectItem<TData>; | ||
declare const getMentionOnSelectItem: <TData extends unknown = undefined>({ key, }?: PlatePluginKey) => ComboboxOnSelectItem<TData>; | ||
interface TMentionElement extends TElement$2 { | ||
interface TMentionElement extends TElement { | ||
value: string; | ||
} | ||
interface TMentionInputElement extends TElement$2 { | ||
interface TMentionInputElement extends TElement { | ||
trigger: string; | ||
@@ -871,3 +33,3 @@ } | ||
}; | ||
query?: (editor: PlateEditor$1) => boolean; | ||
query?: (editor: PlateEditor) => boolean; | ||
} | ||
@@ -880,23 +42,23 @@ | ||
*/ | ||
declare const createMentionPlugin: <OP = MentionPlugin<undefined>, OV extends Value = Value, OE extends PlateEditor<OV> = PlateEditor<OV>>(override?: Partial<PlatePlugin<NoInfer<OP>, OV, OE>> | undefined, overrideByKey?: OverrideByKey<OV, OE> | undefined) => PlatePlugin<NoInfer<OP>, OV, OE>; | ||
declare const createMentionPlugin: <OP = MentionPlugin<undefined>, OV extends _udecode_slate.Value = _udecode_slate.Value, OE extends _udecode_plate_core.PlateEditor<OV> = _udecode_plate_core.PlateEditor<OV>>(override?: Partial<_udecode_plate_core.PlatePlugin<_udecode_plate_core.NoInfer<OP>, OV, OE>> | undefined, overrideByKey?: _udecode_plate_core.OverrideByKey<OV, OE> | undefined) => _udecode_plate_core.PlatePlugin<_udecode_plate_core.NoInfer<OP>, OV, OE>; | ||
declare const withMention: <V extends Value$2 = Value$2, E extends PlateEditor$1<V> = PlateEditor$1<V>>(editor: E, { options: { id, trigger, triggerPreviousCharPattern, query, inputCreation }, }: WithPlatePlugin$1<MentionPlugin<undefined>, V, E>) => E; | ||
declare const withMention: <V extends Value = Value, E extends PlateEditor<V> = PlateEditor<V>>(editor: E, { options: { id, trigger, triggerPreviousCharPattern, query, inputCreation }, }: WithPlatePlugin<MentionPlugin<undefined>, V, E>) => E; | ||
type KeyboardEventHandler = (event: KeyboardEvent) => HandlerReturnType$1; | ||
type KeyboardEventHandler = (event: KeyboardEvent) => HandlerReturnType; | ||
interface MoveSelectionByOffsetOptions<V extends Value$2 = Value$2> { | ||
query?: (editor: PlateEditor$1<V>) => boolean; | ||
interface MoveSelectionByOffsetOptions<V extends Value = Value> { | ||
query?: (editor: PlateEditor<V>) => boolean; | ||
} | ||
declare const moveSelectionByOffset: <V extends Value$2>(editor: PlateEditor$1<V>, options?: MoveSelectionByOffsetOptions<V>) => KeyboardEventHandler; | ||
declare const moveSelectionByOffset: <V extends Value>(editor: PlateEditor<V>, options?: MoveSelectionByOffsetOptions<V>) => KeyboardEventHandler; | ||
declare const mentionOnKeyDownHandler: <V extends Value$2>(options?: MoveSelectionByOffsetOptions<V>) => (editor: PlateEditor$1<V>) => KeyboardEventHandler; | ||
declare const mentionOnKeyDownHandler: <V extends Value>(options?: MoveSelectionByOffsetOptions<V>) => (editor: PlateEditor<V>) => KeyboardEventHandler; | ||
declare const findMentionInput: <V extends Value$2>(editor: PlateEditor$1<V>, options?: Omit<FindNodeOptions<V>, "match"> | undefined) => TNodeEntry<TMentionInputElement> | undefined; | ||
declare const findMentionInput: <V extends Value>(editor: PlateEditor<V>, options?: Omit<FindNodeOptions<V>, "match"> | undefined) => _udecode_slate.TNodeEntry<TMentionInputElement> | undefined; | ||
declare const isNodeMentionInput: <V extends Value$2>(editor: PlateEditor$1<V>, node: TNode$1) => node is TMentionInputElement; | ||
declare const isNodeMentionInput: <V extends Value>(editor: PlateEditor<V>, node: TNode) => node is TMentionInputElement; | ||
declare const isSelectionInMentionInput: <V extends Value$2>(editor: PlateEditor$1<V>) => boolean; | ||
declare const isSelectionInMentionInput: <V extends Value>(editor: PlateEditor<V>) => boolean; | ||
declare const removeMentionInput: <V extends Value$2>(editor: PlateEditor$1<V>, path: Path) => boolean; | ||
declare const removeMentionInput: <V extends Value>(editor: PlateEditor<V>, path: Path) => boolean; | ||
export { CreateMentionNode, CreateMentionNodeMeta, ELEMENT_MENTION, ELEMENT_MENTION_INPUT, KeyboardEventHandler, MentionPlugin, MoveSelectionByOffsetOptions, TMentionElement, TMentionInputElement, createMentionPlugin, findMentionInput, getMentionOnSelectItem, isNodeMentionInput, isSelectionInMentionInput, mentionOnKeyDownHandler, moveSelectionByOffset, removeMentionInput, withMention }; |
{ | ||
"name": "@udecode/plate-mention", | ||
"version": "24.3.2", | ||
"version": "24.3.5", | ||
"description": "Mention plugin for Plate", | ||
@@ -42,4 +42,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"@udecode/plate-combobox": "24.3.2", | ||
"@udecode/plate-common": "24.3.2" | ||
"@udecode/plate-combobox": "24.3.5", | ||
"@udecode/plate-common": "24.3.5" | ||
}, | ||
@@ -46,0 +46,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
71045
702
+ Added@udecode/plate-combobox@24.3.5(transitive)
+ Added@udecode/plate-common@24.3.5(transitive)
+ Added@udecode/plate-core@24.3.5(transitive)
+ Added@udecode/plate-utils@24.3.5(transitive)
+ Added@udecode/slate@24.3.5(transitive)
+ Added@udecode/slate-react@24.3.5(transitive)
+ Added@udecode/slate-utils@24.3.5(transitive)
+ Addedlodash-es@4.17.21(transitive)
- Removed@udecode/plate-combobox@24.3.2(transitive)
- Removed@udecode/plate-common@24.3.2(transitive)
- Removed@udecode/plate-core@24.3.2(transitive)
- Removed@udecode/plate-utils@24.3.2(transitive)
- Removed@udecode/slate@24.3.2(transitive)
- Removed@udecode/slate-react@24.3.2(transitive)
- Removed@udecode/slate-utils@24.3.2(transitive)
Updated@udecode/plate-common@24.3.5