Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@udecode/plate-select

Package Overview
Dependencies
Maintainers
2
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@udecode/plate-select - npm Package Compare versions

Comparing version 24.2.0 to 24.3.0

dist/index.d.mts

756

dist/index.d.ts

@@ -0,6 +1,754 @@

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, THistoryEditor, TRange, TElement as TElement$1, EElement, EElementOrText, TText as TText$1, EText, TRenderLeafProps, ENodeEntry, TNodeEntry, RenderLeafFn } from '@udecode/slate';
import { AnyObject, WithRequired, UnknownObject } from '@udecode/utils';
import { TReactEditor } from '@udecode/slate-react';
import { Path, Range } from 'slate';
import { RenderElementProps } from 'slate-react';
import { EditableProps } from 'slate-react/dist/components/editable';
import { QueryNodeOptions, Value as Value$2, PlateEditor as PlateEditor$1, WithPlatePlugin as WithPlatePlugin$1 } from '@udecode/plate-common';
type SetRecord<O> = {
[K in keyof O]: (scope?: Scope) => (value: O[K]) => void;
};
/**
* @file Automatically generated by barrelsby.
* A unique id used as a provider scope.
* Use it if you have multiple `Plate` in the same React tree.
* @default PLATE_SCOPE
*/
export * from './createSelectOnBackspacePlugin';
export * from './withSelectOnBackspace';
//# sourceMappingURL=index.d.ts.map
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) => 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<P, V, E>> | 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<V> & THistoryEditor<V> & TReactEditor<V> & PlateEditorMethods<V> & {
key: any;
plugins: WithPlatePlugin<{}, V>[];
pluginsByKey: Record<PluginKey, WithPlatePlugin<{}, V>>;
prevSelection: TRange | 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;
};
/**
* `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 Value = TElement[];
type SelectOnBackspacePlugin = {
query?: QueryNodeOptions;
removeNodeIfEmpty?: boolean;
};
declare const KEY_SELECT_ON_BACKSPACE = "selectOnBackspace";
/**
* @see {@link withSelectOnBackspace}
*/
declare const createSelectOnBackspacePlugin: <OP = SelectOnBackspacePlugin, 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>;
/**
* Set a list of element types to select on backspace
*/
declare const withSelectOnBackspace: <V extends Value$2 = Value$2, E extends PlateEditor$1<V> = PlateEditor$1<V>>(editor: E, { options: { query, removeNodeIfEmpty }, }: WithPlatePlugin$1<SelectOnBackspacePlugin, V, E>) => E;
export { KEY_SELECT_ON_BACKSPACE, SelectOnBackspacePlugin, createSelectOnBackspacePlugin, withSelectOnBackspace };

95

dist/index.js

@@ -1,40 +0,56 @@

'use strict';
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var plateCommon = require('@udecode/plate-common');
// src/index.ts
var src_exports = {};
__export(src_exports, {
KEY_SELECT_ON_BACKSPACE: () => KEY_SELECT_ON_BACKSPACE,
createSelectOnBackspacePlugin: () => createSelectOnBackspacePlugin,
withSelectOnBackspace: () => withSelectOnBackspace
});
module.exports = __toCommonJS(src_exports);
/**
* Set a list of element types to select on backspace
*/
const withSelectOnBackspace = (editor, {
options: {
query,
removeNodeIfEmpty
}
// src/createSelectOnBackspacePlugin.ts
var import_plate_common2 = require("@udecode/plate-common");
// src/withSelectOnBackspace.ts
var import_plate_common = require("@udecode/plate-common");
var withSelectOnBackspace = (editor, {
options: { query, removeNodeIfEmpty }
}) => {
const {
deleteBackward
} = editor;
editor.deleteBackward = unit => {
const {
selection
} = editor;
if (unit === 'character' && plateCommon.isCollapsed(selection)) {
const pointBefore = plateCommon.getPointBefore(editor, selection, {
const { deleteBackward } = editor;
editor.deleteBackward = (unit) => {
const { selection } = editor;
if (unit === "character" && (0, import_plate_common.isCollapsed)(selection)) {
const pointBefore = (0, import_plate_common.getPointBefore)(editor, selection, {
unit
});
if (pointBefore) {
const [prevCell] = plateCommon.getNodeEntries(editor, {
match: node => plateCommon.queryNode([node, pointBefore.path], query),
const [prevCell] = (0, import_plate_common.getNodeEntries)(editor, {
match: (node) => (0, import_plate_common.queryNode)([node, pointBefore.path], query),
at: pointBefore
});
if (!!prevCell && pointBefore) {
const point = plateCommon.getPoint(editor, selection);
const selectedNode = plateCommon.getNode(editor, point.path);
if (removeNodeIfEmpty && selectedNode && !plateCommon.getNodeString(selectedNode)) {
// remove node if empty
plateCommon.removeNodes(editor);
const point = (0, import_plate_common.getPoint)(editor, selection);
const selectedNode = (0, import_plate_common.getNode)(editor, point.path);
if (removeNodeIfEmpty && selectedNode && !(0, import_plate_common.getNodeString)(selectedNode)) {
(0, import_plate_common.removeNodes)(editor);
}
// don't delete image, set selection there
plateCommon.select(editor, pointBefore);
(0, import_plate_common.select)(editor, pointBefore);
} else {

@@ -53,8 +69,5 @@ deleteBackward(unit);

const KEY_SELECT_ON_BACKSPACE = 'selectOnBackspace';
/**
* @see {@link withSelectOnBackspace}
*/
const createSelectOnBackspacePlugin = plateCommon.createPluginFactory({
// src/createSelectOnBackspacePlugin.ts
var KEY_SELECT_ON_BACKSPACE = "selectOnBackspace";
var createSelectOnBackspacePlugin = (0, import_plate_common2.createPluginFactory)({
key: KEY_SELECT_ON_BACKSPACE,

@@ -66,6 +79,8 @@ withOverrides: withSelectOnBackspace,

});
exports.KEY_SELECT_ON_BACKSPACE = KEY_SELECT_ON_BACKSPACE;
exports.createSelectOnBackspacePlugin = createSelectOnBackspacePlugin;
exports.withSelectOnBackspace = withSelectOnBackspace;
//# sourceMappingURL=index.js.map
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
KEY_SELECT_ON_BACKSPACE,
createSelectOnBackspacePlugin,
withSelectOnBackspace
});
//# sourceMappingURL=index.js.map
{
"name": "@udecode/plate-select",
"version": "24.2.0",
"version": "24.3.0",
"description": "Select plugins for Plate",

@@ -15,8 +15,17 @@ "license": "MIT",

},
"sideEffects": false,
"main": "dist/index.js",
"module": "dist/index.es.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
"dist/**/*"
],
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"module": "./dist/index.mjs",
"require": "./dist/index.js"
}
},
"scripts": {

@@ -34,3 +43,3 @@ "build": "yarn p:build",

"dependencies": {
"@udecode/plate-common": "24.2.0"
"@udecode/plate-common": "24.3.0"
},

@@ -37,0 +46,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc