deploy: v0.12 fix 存档key名

This commit is contained in:
2026-06-24 03:09:02 +00:00
parent 7a08d49fe3
commit e0a5281119
58743 changed files with 7297269 additions and 39505 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) Meta Platforms, Inc. and affiliates.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+1150
View File
File diff suppressed because it is too large Load Diff
+1099
View File
File diff suppressed because it is too large Load Diff
+11
View File
@@ -0,0 +1,11 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
'use strict'
const LexicalUtils = process.env.NODE_ENV !== 'production' ? require('./LexicalUtils.dev.js') : require('./LexicalUtils.prod.js');
module.exports = LexicalUtils;
+224
View File
@@ -0,0 +1,224 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
*/
import type {
EditorState,
LexicalEditor,
LexicalNode,
ElementNode,
NodeCaret,
CaretDirection,
SiblingCaret,
RootMode,
SplitAtPointCaretNextOptions,
PointCaret,
StateConfig,
ValueOrUpdater
} from 'lexical';
declare export function addClassNamesToElement(
element: HTMLElement,
...classNames: Array<typeof undefined | boolean | null | string>
): void;
declare export function removeClassNamesFromElement(
element: HTMLElement,
...classNames: Array<typeof undefined | boolean | null | string>
): void;
declare export function isMimeType(
file: File,
acceptableMimeTypes: Array<string>,
): boolean;
declare export function mediaFileReader(
files: Array<File>,
acceptableMimeTypes: Array<string>,
): Promise<Array<$ReadOnly<{file: File, result: string}>>>;
export type DFSNode = $ReadOnly<{
depth: number,
node: LexicalNode,
}>;
declare export function $dfs(
startNode?: LexicalNode,
endNode?: LexicalNode,
): Array<DFSNode>;
type DFSIterator = {
next: () => IteratorResult<DFSNode, void>;
@@iterator: () => DFSIterator;
};
declare export function $dfsIterator(
startNode?: LexicalNode,
endNode?: LexicalNode,
): DFSIterator;
declare export function $getNextSiblingOrParentSibling(
node: LexicalNode,
): null | [LexicalNode, number];
declare export function $getDepth(node: null | LexicalNode): number;
declare export function $getNextRightPreorderNode(
startingNode: LexicalNode,
): LexicalNode | null;
declare export function $getNearestNodeOfType<T: LexicalNode>(
node: LexicalNode,
klass: Class<T>,
): T | null;
export type DOMNodeToLexicalConversion = (element: Node) => LexicalNode;
export type DOMNodeToLexicalConversionMap = {
[string]: DOMNodeToLexicalConversion,
};
declare export function $findMatchingParent(
startingNode: LexicalNode,
findFn: (LexicalNode) => boolean,
): LexicalNode | null;
type Func = () => void;
declare export function mergeRegister(...func: Array<Func>): () => void;
declare export function markSelection(
editor: LexicalEditor,
onReposition?: (node: Array<HTMLElement>) => void,
): () => void;
declare export function positionNodeOnRange(
editor: LexicalEditor,
range: Range,
onReposition: (node: Array<HTMLElement>) => void,
): () => void;
declare export function selectionAlwaysOnDisplay(
editor: LexicalEditor,
): () => void;
declare export function $getNearestBlockElementAncestorOrThrow(
startNode: LexicalNode,
): ElementNode;
declare export function registerNestedElementResolver<N: ElementNode>(
editor: LexicalEditor,
targetNode: Class<N>,
cloneNode: (from: N) => N,
handleOverlap: (from: N, to: N) => void,
): () => void;
declare export function unstable_convertLegacyJSONEditorState(
editor: LexicalEditor,
maybeStringifiedEditorState: string,
): EditorState;
declare export function $restoreEditorState(
editor: LexicalEditor,
editorState: EditorState,
): void;
declare export function $insertNodeToNearestRoot<T: LexicalNode>(node: T): T;
declare export function $insertNodeToNearestRootAtCaret<T: LexicalNode>(node: T, caret: PointCaret<CaretDirection>, options?: SplitAtPointCaretNextOptions): T;
declare export function $wrapNodeInElement(
node: LexicalNode,
createElementNode: () => ElementNode,
): ElementNode;
declare export function objectKlassEquals<T>(
object: mixed,
objectClass: Class<T>,
): boolean;
declare export function $filter<T>(
nodes: Array<LexicalNode>,
filterFn: (node: LexicalNode) => null | T,
): Array<T>;
declare export function $insertFirst(parent: ElementNode, node: LexicalNode): void;
declare export function $splitNode(
node: ElementNode,
offset: number,
): [ElementNode | null, ElementNode];
declare export function calculateZoomLevel(element: Element | null): number;
declare export function $isEditorIsNestedEditor(editor: LexicalEditor): boolean;
declare export function $unwrapAndFilterDescendants(
root: ElementNode,
$predicate: (node: LexicalNode) => boolean,
): boolean;
declare export function $firstToLastIterator(node: ElementNode): Iterable<LexicalNode>;
declare export function $lastToFirstIterator(node: ElementNode): Iterable<LexicalNode>;
declare export function $unwrapNode(node: ElementNode): void;
declare export function $getAdjacentCaret<D: CaretDirection>(
caret: null | NodeCaret<D>,
): null | SiblingCaret<LexicalNode, D>;
declare export function $reverseDfs(
startNode?: LexicalNode,
endNode?: LexicalNode,
): Array<DFSNode>;
declare export function $reverseDfsIterator(
startNode?: LexicalNode,
endNode?: LexicalNode,
): Iterable<DFSNode>;
declare export function $descendantsMatching<T: LexicalNode>(
children: LexicalNode[],
$predicate: (node: LexicalNode) => node is T,
): T[];
declare export function $descendantsMatching(
children: LexicalNode[],
$predicate: (node: LexicalNode) => boolean,
): LexicalNode[];
declare export function $getAdjacentSiblingOrParentSiblingCaret<
D: CaretDirection,
>(
startCaret: NodeCaret<D>,
rootMode?: RootMode,
): null | [NodeCaret<D>, number];
export type StateConfigWrapper<K: string, V> = {
+stateConfig: StateConfig<K, V>;
+$get: <T: LexicalNode>(node: T) => V;
+$set: <T: LexicalNode>(
node: T,
valueOrUpdater: ValueOrUpdater<V>,
) => T;
/** `[$get, $set]` */
+accessors: $ReadOnly<[$get: StateConfigWrapper<K, V>['$get'], $set: StateConfigWrapper<K, V>['$set']]>;
/**
* `() => function () { return $get(this) }`
*
* Should be called with an explicit `this` type parameter.
*
* @example
* ```ts
* class MyNode {
* // …
* myGetter = myWrapper.makeGetterMethod<this>();
* }
* ```
*/
makeGetterMethod<T: LexicalNode>(): (this: T) => V;
/**
* `() => function (valueOrUpdater) { return $set(this, valueOrUpdater) }`
*
* Must be called with an explicit `this` type parameter.
*
* @example
* ```ts
* class MyNode {
* // …
* mySetter = myWrapper.makeSetterMethod<this>();
* }
* ```
*/
makeSetterMethod<T: LexicalNode>(): (
this: T,
valueOrUpdater: ValueOrUpdater<V>,
) => T;
};
declare export function makeStateWrapper<K: string, V>(
stateConfig: StateConfig<K, V>,
): StateConfigWrapper<K, V>;
+62
View File
@@ -0,0 +1,62 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import * as modDev from './LexicalUtils.dev.mjs';
import * as modProd from './LexicalUtils.prod.mjs';
const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
export const $descendantsMatching = mod.$descendantsMatching;
export const $dfs = mod.$dfs;
export const $dfsIterator = mod.$dfsIterator;
export const $filter = mod.$filter;
export const $findMatchingParent = mod.$findMatchingParent;
export const $firstToLastIterator = mod.$firstToLastIterator;
export const $getAdjacentCaret = mod.$getAdjacentCaret;
export const $getAdjacentSiblingOrParentSiblingCaret = mod.$getAdjacentSiblingOrParentSiblingCaret;
export const $getDepth = mod.$getDepth;
export const $getNearestBlockElementAncestorOrThrow = mod.$getNearestBlockElementAncestorOrThrow;
export const $getNearestNodeOfType = mod.$getNearestNodeOfType;
export const $getNextRightPreorderNode = mod.$getNextRightPreorderNode;
export const $getNextSiblingOrParentSibling = mod.$getNextSiblingOrParentSibling;
export const $insertFirst = mod.$insertFirst;
export const $insertNodeToNearestRoot = mod.$insertNodeToNearestRoot;
export const $insertNodeToNearestRootAtCaret = mod.$insertNodeToNearestRootAtCaret;
export const $isEditorIsNestedEditor = mod.$isEditorIsNestedEditor;
export const $lastToFirstIterator = mod.$lastToFirstIterator;
export const $restoreEditorState = mod.$restoreEditorState;
export const $reverseDfs = mod.$reverseDfs;
export const $reverseDfsIterator = mod.$reverseDfsIterator;
export const $splitNode = mod.$splitNode;
export const $unwrapAndFilterDescendants = mod.$unwrapAndFilterDescendants;
export const $unwrapNode = mod.$unwrapNode;
export const $wrapNodeInElement = mod.$wrapNodeInElement;
export const CAN_USE_BEFORE_INPUT = mod.CAN_USE_BEFORE_INPUT;
export const CAN_USE_DOM = mod.CAN_USE_DOM;
export const IS_ANDROID = mod.IS_ANDROID;
export const IS_ANDROID_CHROME = mod.IS_ANDROID_CHROME;
export const IS_APPLE = mod.IS_APPLE;
export const IS_APPLE_WEBKIT = mod.IS_APPLE_WEBKIT;
export const IS_CHROME = mod.IS_CHROME;
export const IS_FIREFOX = mod.IS_FIREFOX;
export const IS_IOS = mod.IS_IOS;
export const IS_SAFARI = mod.IS_SAFARI;
export const addClassNamesToElement = mod.addClassNamesToElement;
export const calculateZoomLevel = mod.calculateZoomLevel;
export const isBlockDomNode = mod.isBlockDomNode;
export const isHTMLAnchorElement = mod.isHTMLAnchorElement;
export const isHTMLElement = mod.isHTMLElement;
export const isInlineDomNode = mod.isInlineDomNode;
export const isMimeType = mod.isMimeType;
export const makeStateWrapper = mod.makeStateWrapper;
export const markSelection = mod.markSelection;
export const mediaFileReader = mod.mediaFileReader;
export const mergeRegister = mod.mergeRegister;
export const objectKlassEquals = mod.objectKlassEquals;
export const positionNodeOnRange = mod.positionNodeOnRange;
export const registerNestedElementResolver = mod.registerNestedElementResolver;
export const removeClassNamesFromElement = mod.removeClassNamesFromElement;
export const selectionAlwaysOnDisplay = mod.selectionAlwaysOnDisplay;
+60
View File
@@ -0,0 +1,60 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalUtils.dev.mjs') : import('./LexicalUtils.prod.mjs'));
export const $descendantsMatching = mod.$descendantsMatching;
export const $dfs = mod.$dfs;
export const $dfsIterator = mod.$dfsIterator;
export const $filter = mod.$filter;
export const $findMatchingParent = mod.$findMatchingParent;
export const $firstToLastIterator = mod.$firstToLastIterator;
export const $getAdjacentCaret = mod.$getAdjacentCaret;
export const $getAdjacentSiblingOrParentSiblingCaret = mod.$getAdjacentSiblingOrParentSiblingCaret;
export const $getDepth = mod.$getDepth;
export const $getNearestBlockElementAncestorOrThrow = mod.$getNearestBlockElementAncestorOrThrow;
export const $getNearestNodeOfType = mod.$getNearestNodeOfType;
export const $getNextRightPreorderNode = mod.$getNextRightPreorderNode;
export const $getNextSiblingOrParentSibling = mod.$getNextSiblingOrParentSibling;
export const $insertFirst = mod.$insertFirst;
export const $insertNodeToNearestRoot = mod.$insertNodeToNearestRoot;
export const $insertNodeToNearestRootAtCaret = mod.$insertNodeToNearestRootAtCaret;
export const $isEditorIsNestedEditor = mod.$isEditorIsNestedEditor;
export const $lastToFirstIterator = mod.$lastToFirstIterator;
export const $restoreEditorState = mod.$restoreEditorState;
export const $reverseDfs = mod.$reverseDfs;
export const $reverseDfsIterator = mod.$reverseDfsIterator;
export const $splitNode = mod.$splitNode;
export const $unwrapAndFilterDescendants = mod.$unwrapAndFilterDescendants;
export const $unwrapNode = mod.$unwrapNode;
export const $wrapNodeInElement = mod.$wrapNodeInElement;
export const CAN_USE_BEFORE_INPUT = mod.CAN_USE_BEFORE_INPUT;
export const CAN_USE_DOM = mod.CAN_USE_DOM;
export const IS_ANDROID = mod.IS_ANDROID;
export const IS_ANDROID_CHROME = mod.IS_ANDROID_CHROME;
export const IS_APPLE = mod.IS_APPLE;
export const IS_APPLE_WEBKIT = mod.IS_APPLE_WEBKIT;
export const IS_CHROME = mod.IS_CHROME;
export const IS_FIREFOX = mod.IS_FIREFOX;
export const IS_IOS = mod.IS_IOS;
export const IS_SAFARI = mod.IS_SAFARI;
export const addClassNamesToElement = mod.addClassNamesToElement;
export const calculateZoomLevel = mod.calculateZoomLevel;
export const isBlockDomNode = mod.isBlockDomNode;
export const isHTMLAnchorElement = mod.isHTMLAnchorElement;
export const isHTMLElement = mod.isHTMLElement;
export const isInlineDomNode = mod.isInlineDomNode;
export const isMimeType = mod.isMimeType;
export const makeStateWrapper = mod.makeStateWrapper;
export const markSelection = mod.markSelection;
export const mediaFileReader = mod.mediaFileReader;
export const mergeRegister = mod.mergeRegister;
export const objectKlassEquals = mod.objectKlassEquals;
export const positionNodeOnRange = mod.positionNodeOnRange;
export const registerNestedElementResolver = mod.registerNestedElementResolver;
export const removeClassNamesFromElement = mod.removeClassNamesFromElement;
export const selectionAlwaysOnDisplay = mod.selectionAlwaysOnDisplay;
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+5
View File
@@ -0,0 +1,5 @@
# `@lexical/utils`
[![See API Documentation](https://lexical.dev/img/see-api-documentation.svg)](https://lexical.dev/docs/api/modules/lexical_utils)
This package contains misc utilities for Lexical.
+345
View File
@@ -0,0 +1,345 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { type CaretDirection, type EditorState, ElementNode, type Klass, type LexicalEditor, type LexicalNode, type NodeCaret, PointCaret, RootMode, type SiblingCaret, SplitAtPointCaretNextOptions, StateConfig, ValueOrUpdater } from 'lexical';
export { default as markSelection } from './markSelection';
export { default as mergeRegister } from './mergeRegister';
export { default as positionNodeOnRange } from './positionNodeOnRange';
export { default as selectionAlwaysOnDisplay } from './selectionAlwaysOnDisplay';
export { $splitNode, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode, } from 'lexical';
export declare const CAN_USE_BEFORE_INPUT: boolean;
export declare const CAN_USE_DOM: boolean;
export declare const IS_ANDROID: boolean;
export declare const IS_ANDROID_CHROME: boolean;
export declare const IS_APPLE: boolean;
export declare const IS_APPLE_WEBKIT: boolean;
export declare const IS_CHROME: boolean;
export declare const IS_FIREFOX: boolean;
export declare const IS_IOS: boolean;
export declare const IS_SAFARI: boolean;
/**
* Takes an HTML element and adds the classNames passed within an array,
* ignoring any non-string types. A space can be used to add multiple classes
* eg. addClassNamesToElement(element, ['element-inner active', true, null])
* will add both 'element-inner' and 'active' as classes to that element.
* @param element - The element in which the classes are added
* @param classNames - An array defining the class names to add to the element
*/
export declare function addClassNamesToElement(element: HTMLElement, ...classNames: Array<typeof undefined | boolean | null | string>): void;
/**
* Takes an HTML element and removes the classNames passed within an array,
* ignoring any non-string types. A space can be used to remove multiple classes
* eg. removeClassNamesFromElement(element, ['active small', true, null])
* will remove both the 'active' and 'small' classes from that element.
* @param element - The element in which the classes are removed
* @param classNames - An array defining the class names to remove from the element
*/
export declare function removeClassNamesFromElement(element: HTMLElement, ...classNames: Array<typeof undefined | boolean | null | string>): void;
/**
* Returns true if the file type matches the types passed within the acceptableMimeTypes array, false otherwise.
* The types passed must be strings and are CASE-SENSITIVE.
* eg. if file is of type 'text' and acceptableMimeTypes = ['TEXT', 'IMAGE'] the function will return false.
* @param file - The file you want to type check.
* @param acceptableMimeTypes - An array of strings of types which the file is checked against.
* @returns true if the file is an acceptable mime type, false otherwise.
*/
export declare function isMimeType(file: File, acceptableMimeTypes: Array<string>): boolean;
/**
* Lexical File Reader with:
* 1. MIME type support
* 2. batched results (HistoryPlugin compatibility)
* 3. Order aware (respects the order when multiple Files are passed)
*
* const filesResult = await mediaFileReader(files, ['image/']);
* filesResult.forEach(file => editor.dispatchCommand('INSERT_IMAGE', \\{
* src: file.result,
* \\}));
*/
export declare function mediaFileReader(files: Array<File>, acceptableMimeTypes: Array<string>): Promise<Array<{
file: File;
result: string;
}>>;
export interface DFSNode {
readonly depth: number;
readonly node: LexicalNode;
}
/**
* "Depth-First Search" starts at the root/top node of a tree and goes as far as it can down a branch end
* before backtracking and finding a new path. Consider solving a maze by hugging either wall, moving down a
* branch until you hit a dead-end (leaf) and backtracking to find the nearest branching path and repeat.
* It will then return all the nodes found in the search in an array of objects.
* @param startNode - The node to start the search, if omitted, it will start at the root node.
* @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
* @returns An array of objects of all the nodes found by the search, including their depth into the tree.
* \\{depth: number, node: LexicalNode\\} It will always return at least 1 node (the start node).
*/
export declare function $dfs(startNode?: LexicalNode, endNode?: LexicalNode): Array<DFSNode>;
/**
* Get the adjacent caret in the same direction
*
* @param caret A caret or null
* @returns `caret.getAdjacentCaret()` or `null`
*/
export declare function $getAdjacentCaret<D extends CaretDirection>(caret: null | NodeCaret<D>): null | SiblingCaret<LexicalNode, D>;
/**
* $dfs iterator (right to left). Tree traversal is done on the fly as new values are requested with O(1) memory.
* @param startNode - The node to start the search, if omitted, it will start at the root node.
* @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
* @returns An iterator, each yielded value is a DFSNode. It will always return at least 1 node (the start node).
*/
export declare function $reverseDfs(startNode?: LexicalNode, endNode?: LexicalNode): Array<DFSNode>;
/**
* $dfs iterator (left to right). Tree traversal is done on the fly as new values are requested with O(1) memory.
* @param startNode - The node to start the search, if omitted, it will start at the root node.
* @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
* @returns An iterator, each yielded value is a DFSNode. It will always return at least 1 node (the start node).
*/
export declare function $dfsIterator(startNode?: LexicalNode, endNode?: LexicalNode): IterableIterator<DFSNode>;
/**
* Returns the Node sibling when this exists, otherwise the closest parent sibling. For example
* R -> P -> T1, T2
* -> P2
* returns T2 for node T1, P2 for node T2, and null for node P2.
* @param node LexicalNode.
* @returns An array (tuple) containing the found Lexical node and the depth difference, or null, if this node doesn't exist.
*/
export declare function $getNextSiblingOrParentSibling(node: LexicalNode): null | [LexicalNode, number];
export declare function $getDepth(node: null | LexicalNode): number;
/**
* Performs a right-to-left preorder tree traversal.
* From the starting node it goes to the rightmost child, than backtracks to parent and finds new rightmost path.
* It will return the next node in traversal sequence after the startingNode.
* The traversal is similar to $dfs functions above, but the nodes are visited right-to-left, not left-to-right.
* @param startingNode - The node to start the search.
* @returns The next node in pre-order right to left traversal sequence or `null`, if the node does not exist
*/
export declare function $getNextRightPreorderNode(startingNode: LexicalNode): LexicalNode | null;
/**
* $dfs iterator (right to left). Tree traversal is done on the fly as new values are requested with O(1) memory.
* @param startNode - The node to start the search, if omitted, it will start at the root node.
* @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
* @returns An iterator, each yielded value is a DFSNode. It will always return at least 1 node (the start node).
*/
export declare function $reverseDfsIterator(startNode?: LexicalNode, endNode?: LexicalNode): IterableIterator<DFSNode>;
/**
* Takes a node and traverses up its ancestors (toward the root node)
* in order to find a specific type of node.
* @param node - the node to begin searching.
* @param klass - an instance of the type of node to look for.
* @returns the node of type klass that was passed, or null if none exist.
*/
export declare function $getNearestNodeOfType<T extends ElementNode>(node: LexicalNode, klass: Klass<T>): T | null;
/**
* Returns the element node of the nearest ancestor, otherwise throws an error.
* @param startNode - The starting node of the search
* @returns The ancestor node found
*/
export declare function $getNearestBlockElementAncestorOrThrow(startNode: LexicalNode): ElementNode;
export type DOMNodeToLexicalConversion = (element: Node) => LexicalNode;
export type DOMNodeToLexicalConversionMap = Record<string, DOMNodeToLexicalConversion>;
/**
* Starts with a node and moves up the tree (toward the root node) to find a matching node based on
* the search parameters of the findFn. (Consider JavaScripts' .find() function where a testing function must be
* passed as an argument. eg. if( (node) => node.__type === 'div') ) return true; otherwise return false
* @param startingNode - The node where the search starts.
* @param findFn - A testing function that returns true if the current node satisfies the testing parameters.
* @returns A parent node that matches the findFn parameters, or null if one wasn't found.
*/
export declare const $findMatchingParent: {
<T extends LexicalNode>(startingNode: LexicalNode, findFn: (node: LexicalNode) => node is T): T | null;
(startingNode: LexicalNode, findFn: (node: LexicalNode) => boolean): LexicalNode | null;
};
/**
* Attempts to resolve nested element nodes of the same type into a single node of that type.
* It is generally used for marks/commenting
* @param editor - The lexical editor
* @param targetNode - The target for the nested element to be extracted from.
* @param cloneNode - See {@link $createMarkNode}
* @param handleOverlap - Handles any overlap between the node to extract and the targetNode
* @returns The lexical editor
*/
export declare function registerNestedElementResolver<N extends ElementNode>(editor: LexicalEditor, targetNode: Klass<N>, cloneNode: (from: N) => N, handleOverlap: (from: N, to: N) => void): () => void;
/**
* Clones the editor and marks it as dirty to be reconciled. If there was a selection,
* it would be set back to its previous state, or null otherwise.
* @param editor - The lexical editor
* @param editorState - The editor's state
*/
export declare function $restoreEditorState(editor: LexicalEditor, editorState: EditorState): void;
/**
* If the selected insertion area is the root/shadow root node (see {@link lexical!$isRootOrShadowRoot}),
* the node will be appended there, otherwise, it will be inserted before the insertion area.
* If there is no selection where the node is to be inserted, it will be appended after any current nodes
* within the tree, as a child of the root node. A paragraph will then be added after the inserted node and selected.
* @param node - The node to be inserted
* @returns The node after its insertion
*/
export declare function $insertNodeToNearestRoot<T extends LexicalNode>(node: T): T;
/**
* If the insertion caret is the root/shadow root node (see {@link lexical!$isRootOrShadowRoot}),
* the node will be inserted there, otherwise the parent nodes will be split according to the
* given options.
* @param node - The node to be inserted
* @param caret - The location to insert or split from
* @returns The node after its insertion
*/
export declare function $insertNodeToNearestRootAtCaret<T extends LexicalNode, D extends CaretDirection>(node: T, caret: PointCaret<D>, options?: SplitAtPointCaretNextOptions): NodeCaret<D>;
/**
* Wraps the node into another node created from a createElementNode function, eg. $createParagraphNode
* @param node - Node to be wrapped.
* @param createElementNode - Creates a new lexical element to wrap the to-be-wrapped node and returns it.
* @returns A new lexical element with the previous node appended within (as a child, including its children).
*/
export declare function $wrapNodeInElement(node: LexicalNode, createElementNode: () => ElementNode): ElementNode;
export type ObjectKlass<T> = new (...args: any[]) => T;
/**
* @param object = The instance of the type
* @param objectClass = The class of the type
* @returns Whether the object is has the same Klass of the objectClass, ignoring the difference across window (e.g. different iframes)
*/
export declare function objectKlassEquals<T>(object: unknown, objectClass: ObjectKlass<T>): object is T;
/**
* Filter the nodes
* @param nodes Array of nodes that needs to be filtered
* @param filterFn A filter function that returns node if the current node satisfies the condition otherwise null
* @returns Array of filtered nodes
*/
export declare function $filter<T>(nodes: Array<LexicalNode>, filterFn: (node: LexicalNode) => null | T): Array<T>;
/**
* Appends the node before the first child of the parent node
* @param parent A parent node
* @param node Node that needs to be appended
*/
export declare function $insertFirst(parent: ElementNode, node: LexicalNode): void;
/**
* Calculates the zoom level of an element as a result of using
* css zoom property. For browsers that implement standardized CSS
* zoom (Firefox, Chrome >= 128), this will always return 1.
* @param element
*/
export declare function calculateZoomLevel(element: Element | null): number;
/**
* Checks if the editor is a nested editor created by LexicalNestedComposer
*/
export declare function $isEditorIsNestedEditor(editor: LexicalEditor): boolean;
/**
* A depth first last-to-first traversal of root that stops at each node that matches
* $predicate and ensures that its parent is root. This is typically used to discard
* invalid or unsupported wrapping nodes. For example, a TableNode must only have
* TableRowNode as children, but an importer might add invalid nodes based on
* caption, tbody, thead, etc. and this will unwrap and discard those.
*
* @param root The root to start the traversal
* @param $predicate Should return true for nodes that are permitted to be children of root
* @returns true if this unwrapped or removed any nodes
*/
export declare function $unwrapAndFilterDescendants(root: ElementNode, $predicate: (node: LexicalNode) => boolean): boolean;
/**
* A depth first traversal of the children array that stops at and collects
* each node that `$predicate` matches. This is typically used to discard
* invalid or unsupported wrapping nodes on a children array in the `after`
* of an {@link lexical!DOMConversionOutput}. For example, a TableNode must only have
* TableRowNode as children, but an importer might add invalid nodes based on
* caption, tbody, thead, etc. and this will unwrap and discard those.
*
* This function is read-only and performs no mutation operations, which makes
* it suitable for import and export purposes but likely not for any in-place
* mutation. You should use {@link $unwrapAndFilterDescendants} for in-place
* mutations such as node transforms.
*
* @param children The children to traverse
* @param $predicate Should return true for nodes that are permitted to be children of root
* @returns The children or their descendants that match $predicate
*/
export declare function $descendantsMatching<T extends LexicalNode>(children: LexicalNode[], $predicate: (node: LexicalNode) => node is T): T[];
/**
* Return an iterator that yields each child of node from first to last, taking
* care to preserve the next sibling before yielding the value in case the caller
* removes the yielded node.
*
* @param node The node whose children to iterate
* @returns An iterator of the node's children
*/
export declare function $firstToLastIterator(node: ElementNode): Iterable<LexicalNode>;
/**
* Return an iterator that yields each child of node from last to first, taking
* care to preserve the previous sibling before yielding the value in case the caller
* removes the yielded node.
*
* @param node The node whose children to iterate
* @returns An iterator of the node's children
*/
export declare function $lastToFirstIterator(node: ElementNode): Iterable<LexicalNode>;
/**
* Replace this node with its children
*
* @param node The ElementNode to unwrap and remove
*/
export declare function $unwrapNode(node: ElementNode): void;
/**
* Returns the Node sibling when this exists, otherwise the closest parent sibling. For example
* R -> P -> T1, T2
* -> P2
* returns T2 for node T1, P2 for node T2, and null for node P2.
* @param node LexicalNode.
* @returns An array (tuple) containing the found Lexical node and the depth difference, or null, if this node doesn't exist.
*/
export declare function $getAdjacentSiblingOrParentSiblingCaret<D extends CaretDirection>(startCaret: NodeCaret<D>, rootMode?: RootMode): null | [NodeCaret<D>, number];
/**
* A wrapper that creates bound functions and methods for the
* StateConfig to save some boilerplate when defining methods
* or exporting only the accessors from your modules rather
* than exposing the StateConfig directly.
*/
export interface StateConfigWrapper<K extends string, V> {
/** A reference to the stateConfig */
readonly stateConfig: StateConfig<K, V>;
/** `(node) => $getState(node, stateConfig)` */
readonly $get: <T extends LexicalNode>(node: T) => V;
/** `(node, valueOrUpdater) => $setState(node, stateConfig, valueOrUpdater)` */
readonly $set: <T extends LexicalNode>(node: T, valueOrUpdater: ValueOrUpdater<V>) => T;
/** `[$get, $set]` */
readonly accessors: readonly [$get: this['$get'], $set: this['$set']];
/**
* `() => function () { return $get(this) }`
*
* Should be called with an explicit `this` type parameter.
*
* @example
* ```ts
* class MyNode {
* // …
* myGetter = myWrapper.makeGetterMethod<this>();
* }
* ```
*/
makeGetterMethod<T extends LexicalNode>(): (this: T) => V;
/**
* `() => function (valueOrUpdater) { return $set(this, valueOrUpdater) }`
*
* Must be called with an explicit `this` type parameter.
*
* @example
* ```ts
* class MyNode {
* // …
* mySetter = myWrapper.makeSetterMethod<this>();
* }
* ```
*/
makeSetterMethod<T extends LexicalNode>(): (this: T, valueOrUpdater: ValueOrUpdater<V>) => T;
}
/**
* EXPERIMENTAL
*
* A convenience interface for working with {@link $getState} and
* {@link $setState}.
*
* @param stateConfig The stateConfig to wrap with convenience functionality
* @returns a StateWrapper
*/
export declare function makeStateWrapper<K extends string, V>(stateConfig: StateConfig<K, V>): StateConfigWrapper<K, V>;
+17
View File
@@ -0,0 +1,17 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { type LexicalEditor } from 'lexical';
/**
* Place one or multiple newly created Nodes at the current selection. Multiple
* nodes will only be created when the selection spans multiple lines (aka
* client rects).
*
* This function can come useful when you want to show the selection but the
* editor has been focused away.
*/
export default function markSelection(editor: LexicalEditor, onReposition?: (node: Array<HTMLElement>) => void): () => void;
+35
View File
@@ -0,0 +1,35 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
type Func = () => void;
/**
* Returns a function that will execute all functions passed when called. It is generally used
* to register multiple lexical listeners and then tear them down with a single function call, such
* as React's useEffect hook.
* @example
* ```ts
* useEffect(() => {
* return mergeRegister(
* editor.registerCommand(...registerCommand1 logic),
* editor.registerCommand(...registerCommand2 logic),
* editor.registerCommand(...registerCommand3 logic)
* )
* }, [editor])
* ```
* In this case, useEffect is returning the function returned by mergeRegister as a cleanup
* function to be executed after either the useEffect runs again (due to one of its dependencies
* updating) or the component it resides in unmounts.
* Note the functions don't necessarily need to be in an array as all arguments
* are considered to be the func argument and spread from there.
* The order of cleanup is the reverse of the argument order. Generally it is
* expected that the first "acquire" will be "released" last (LIFO order),
* because a later step may have some dependency on an earlier one.
* @param func - An array of cleanup functions meant to be executed by the returned function.
* @returns the function which executes all the passed cleanup functions.
*/
export default function mergeRegister(...func: Array<Func>): () => void;
export {};
+44
View File
@@ -0,0 +1,44 @@
{
"name": "@lexical/utils",
"description": "This package contains misc utilities for Lexical.",
"keywords": [
"lexical",
"editor",
"rich-text",
"utils"
],
"license": "MIT",
"version": "0.35.0",
"main": "LexicalUtils.js",
"types": "index.d.ts",
"dependencies": {
"@lexical/list": "0.35.0",
"@lexical/selection": "0.35.0",
"@lexical/table": "0.35.0",
"lexical": "0.35.0"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-utils"
},
"module": "LexicalUtils.mjs",
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./index.d.ts",
"development": "./LexicalUtils.dev.mjs",
"production": "./LexicalUtils.prod.mjs",
"node": "./LexicalUtils.node.mjs",
"default": "./LexicalUtils.mjs"
},
"require": {
"types": "./index.d.ts",
"development": "./LexicalUtils.dev.js",
"production": "./LexicalUtils.prod.js",
"default": "./LexicalUtils.js"
}
}
}
}
+21
View File
@@ -0,0 +1,21 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { type LexicalEditor } from 'lexical';
/**
* Place one or multiple newly created Nodes at the passed Range's position.
* Multiple nodes will only be created when the Range spans multiple lines (aka
* client rects).
*
* This function can come particularly useful to highlight particular parts of
* the text without interfering with the EditorState, that will often replicate
* the state across collab and clipboard.
*
* This function accounts for DOM updates which can modify the passed Range.
* Hence, the function return to remove the listener.
*/
export default function mlcPositionNodeOnRange(editor: LexicalEditor, range: Range, onReposition: (node: Array<HTMLElement>) => void): () => void;
+8
View File
@@ -0,0 +1,8 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
export default function px(value: number): string;
+9
View File
@@ -0,0 +1,9 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { LexicalEditor } from 'lexical';
export default function selectionAlwaysOnDisplay(editor: LexicalEditor): () => void;