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.
+261
View File
@@ -0,0 +1,261 @@
/**
* 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';
var lexical = require('lexical');
var utils = require('@lexical/utils');
/**
* 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 NO_IDS = [];
/** @noInheritDoc */
class MarkNode extends lexical.ElementNode {
/** @internal */
static getType() {
return 'mark';
}
static clone(node) {
return new MarkNode(node.__ids, node.__key);
}
static importDOM() {
return null;
}
static importJSON(serializedNode) {
return $createMarkNode().updateFromJSON(serializedNode);
}
updateFromJSON(serializedNode) {
return super.updateFromJSON(serializedNode).setIDs(serializedNode.ids);
}
exportJSON() {
return {
...super.exportJSON(),
ids: this.getIDs()
};
}
constructor(ids = NO_IDS, key) {
super(key);
this.__ids = ids;
}
createDOM(config) {
const element = document.createElement('mark');
utils.addClassNamesToElement(element, config.theme.mark);
if (this.__ids.length > 1) {
utils.addClassNamesToElement(element, config.theme.markOverlap);
}
return element;
}
updateDOM(prevNode, element, config) {
const prevIDs = prevNode.__ids;
const nextIDs = this.__ids;
const prevIDsCount = prevIDs.length;
const nextIDsCount = nextIDs.length;
const overlapTheme = config.theme.markOverlap;
if (prevIDsCount !== nextIDsCount) {
if (prevIDsCount === 1) {
if (nextIDsCount === 2) {
utils.addClassNamesToElement(element, overlapTheme);
}
} else if (nextIDsCount === 1) {
utils.removeClassNamesFromElement(element, overlapTheme);
}
}
return false;
}
hasID(id) {
return this.getIDs().includes(id);
}
getIDs() {
return Array.from(this.getLatest().__ids);
}
setIDs(ids) {
const self = this.getWritable();
self.__ids = ids;
return self;
}
addID(id) {
const self = this.getWritable();
return self.__ids.includes(id) ? self : self.setIDs([...self.__ids, id]);
}
deleteID(id) {
const self = this.getWritable();
const idx = self.__ids.indexOf(id);
if (idx === -1) {
return self;
}
const ids = Array.from(self.__ids);
ids.splice(idx, 1);
return self.setIDs(ids);
}
insertNewAfter(selection, restoreSelection = true) {
const markNode = $createMarkNode(this.__ids);
this.insertAfter(markNode, restoreSelection);
return markNode;
}
canInsertTextBefore() {
return false;
}
canInsertTextAfter() {
return false;
}
canBeEmpty() {
return false;
}
isInline() {
return true;
}
extractWithChild(child, selection, destination) {
if (!lexical.$isRangeSelection(selection) || destination === 'html') {
return false;
}
const anchor = selection.anchor;
const focus = selection.focus;
const anchorNode = anchor.getNode();
const focusNode = focus.getNode();
const isBackward = selection.isBackward();
const selectionLength = isBackward ? anchor.offset - focus.offset : focus.offset - anchor.offset;
return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && this.getTextContent().length === selectionLength;
}
excludeFromCopy(destination) {
return destination !== 'clone';
}
}
function $createMarkNode(ids = NO_IDS) {
return lexical.$applyNodeReplacement(new MarkNode(ids));
}
function $isMarkNode(node) {
return node instanceof MarkNode;
}
/**
* 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.
*
*/
function $unwrapMarkNode(node) {
const children = node.getChildren();
let target = null;
for (let i = 0; i < children.length; i++) {
const child = children[i];
if (target === null) {
node.insertBefore(child);
} else {
target.insertAfter(child);
}
target = child;
}
node.remove();
}
function $wrapSelectionInMarkNode(selection, isBackward, id, createNode) {
// Force a forwards selection since append is used, ignore the argument.
// A new selection is used to avoid side-effects of flipping the given
// selection
const forwardSelection = lexical.$createRangeSelection();
const [startPoint, endPoint] = selection.isBackward() ? [selection.focus, selection.anchor] : [selection.anchor, selection.focus];
forwardSelection.anchor.set(startPoint.key, startPoint.offset, startPoint.type);
forwardSelection.focus.set(endPoint.key, endPoint.offset, endPoint.type);
let currentNodeParent;
let lastCreatedMarkNode;
// Note that extract will split text nodes at the boundaries
const nodes = forwardSelection.extract();
// We only want wrap adjacent text nodes, line break nodes
// and inline element nodes. For decorator nodes and block
// element nodes, we step out of their boundary and start
// again after, if there are more nodes.
for (const node of nodes) {
if (lexical.$isElementNode(lastCreatedMarkNode) && lastCreatedMarkNode.isParentOf(node)) {
// If the current node is a child of the last created mark node, there is nothing to do here
continue;
}
let targetNode = null;
if (lexical.$isTextNode(node)) {
// Case 1: The node is a text node and we can include it
targetNode = node;
} else if ($isMarkNode(node)) {
// Case 2: the node is a mark node and we can ignore it as a target,
// moving on to its children. Note that when we make a mark inside
// another mark, it may ultimately be unnested by a call to
// `registerNestedElementResolver<MarkNode>` somewhere else in the
// codebase.
continue;
} else if ((lexical.$isElementNode(node) || lexical.$isDecoratorNode(node)) && node.isInline()) {
// Case 3: inline element/decorator nodes can be added in their entirety
// to the new mark
targetNode = node;
}
if (targetNode !== null) {
// Now that we have a target node for wrapping with a mark, we can run
// through special cases.
if (targetNode && targetNode.is(currentNodeParent)) {
// The current node is a child of the target node to be wrapped, there
// is nothing to do here.
continue;
}
const parentNode = targetNode.getParent();
if (parentNode == null || !parentNode.is(currentNodeParent)) {
// If the parent node is not the current node's parent node, we can
// clear the last created mark node.
lastCreatedMarkNode = undefined;
}
currentNodeParent = parentNode;
if (lastCreatedMarkNode === undefined) {
// If we don't have a created mark node, we can make one
const createMarkNode = createNode || $createMarkNode;
lastCreatedMarkNode = createMarkNode([id]);
targetNode.insertBefore(lastCreatedMarkNode);
}
// Add the target node to be wrapped in the latest created mark node
lastCreatedMarkNode.append(targetNode);
} else {
// If we don't have a target node to wrap we can clear our state and
// continue on with the next node
currentNodeParent = undefined;
lastCreatedMarkNode = undefined;
}
}
// Make selection collapsed at the end
if (lexical.$isElementNode(lastCreatedMarkNode)) {
// eslint-disable-next-line no-unused-expressions
isBackward ? lastCreatedMarkNode.selectStart() : lastCreatedMarkNode.selectEnd();
}
}
function $getMarkIDs(node, offset) {
let currentNode = node;
while (currentNode !== null) {
if ($isMarkNode(currentNode)) {
return currentNode.getIDs();
} else if (lexical.$isTextNode(currentNode) && offset === currentNode.getTextContentSize()) {
const nextSibling = currentNode.getNextSibling();
if ($isMarkNode(nextSibling)) {
return nextSibling.getIDs();
}
}
currentNode = currentNode.getParent();
}
return null;
}
exports.$createMarkNode = $createMarkNode;
exports.$getMarkIDs = $getMarkIDs;
exports.$isMarkNode = $isMarkNode;
exports.$unwrapMarkNode = $unwrapMarkNode;
exports.$wrapSelectionInMarkNode = $wrapSelectionInMarkNode;
exports.MarkNode = MarkNode;
+254
View File
@@ -0,0 +1,254 @@
/**
* 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 { ElementNode, $isRangeSelection, $applyNodeReplacement, $createRangeSelection, $isElementNode, $isTextNode, $isDecoratorNode } from 'lexical';
import { addClassNamesToElement, removeClassNamesFromElement } from '@lexical/utils';
/**
* 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 NO_IDS = [];
/** @noInheritDoc */
class MarkNode extends ElementNode {
/** @internal */
static getType() {
return 'mark';
}
static clone(node) {
return new MarkNode(node.__ids, node.__key);
}
static importDOM() {
return null;
}
static importJSON(serializedNode) {
return $createMarkNode().updateFromJSON(serializedNode);
}
updateFromJSON(serializedNode) {
return super.updateFromJSON(serializedNode).setIDs(serializedNode.ids);
}
exportJSON() {
return {
...super.exportJSON(),
ids: this.getIDs()
};
}
constructor(ids = NO_IDS, key) {
super(key);
this.__ids = ids;
}
createDOM(config) {
const element = document.createElement('mark');
addClassNamesToElement(element, config.theme.mark);
if (this.__ids.length > 1) {
addClassNamesToElement(element, config.theme.markOverlap);
}
return element;
}
updateDOM(prevNode, element, config) {
const prevIDs = prevNode.__ids;
const nextIDs = this.__ids;
const prevIDsCount = prevIDs.length;
const nextIDsCount = nextIDs.length;
const overlapTheme = config.theme.markOverlap;
if (prevIDsCount !== nextIDsCount) {
if (prevIDsCount === 1) {
if (nextIDsCount === 2) {
addClassNamesToElement(element, overlapTheme);
}
} else if (nextIDsCount === 1) {
removeClassNamesFromElement(element, overlapTheme);
}
}
return false;
}
hasID(id) {
return this.getIDs().includes(id);
}
getIDs() {
return Array.from(this.getLatest().__ids);
}
setIDs(ids) {
const self = this.getWritable();
self.__ids = ids;
return self;
}
addID(id) {
const self = this.getWritable();
return self.__ids.includes(id) ? self : self.setIDs([...self.__ids, id]);
}
deleteID(id) {
const self = this.getWritable();
const idx = self.__ids.indexOf(id);
if (idx === -1) {
return self;
}
const ids = Array.from(self.__ids);
ids.splice(idx, 1);
return self.setIDs(ids);
}
insertNewAfter(selection, restoreSelection = true) {
const markNode = $createMarkNode(this.__ids);
this.insertAfter(markNode, restoreSelection);
return markNode;
}
canInsertTextBefore() {
return false;
}
canInsertTextAfter() {
return false;
}
canBeEmpty() {
return false;
}
isInline() {
return true;
}
extractWithChild(child, selection, destination) {
if (!$isRangeSelection(selection) || destination === 'html') {
return false;
}
const anchor = selection.anchor;
const focus = selection.focus;
const anchorNode = anchor.getNode();
const focusNode = focus.getNode();
const isBackward = selection.isBackward();
const selectionLength = isBackward ? anchor.offset - focus.offset : focus.offset - anchor.offset;
return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && this.getTextContent().length === selectionLength;
}
excludeFromCopy(destination) {
return destination !== 'clone';
}
}
function $createMarkNode(ids = NO_IDS) {
return $applyNodeReplacement(new MarkNode(ids));
}
function $isMarkNode(node) {
return node instanceof MarkNode;
}
/**
* 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.
*
*/
function $unwrapMarkNode(node) {
const children = node.getChildren();
let target = null;
for (let i = 0; i < children.length; i++) {
const child = children[i];
if (target === null) {
node.insertBefore(child);
} else {
target.insertAfter(child);
}
target = child;
}
node.remove();
}
function $wrapSelectionInMarkNode(selection, isBackward, id, createNode) {
// Force a forwards selection since append is used, ignore the argument.
// A new selection is used to avoid side-effects of flipping the given
// selection
const forwardSelection = $createRangeSelection();
const [startPoint, endPoint] = selection.isBackward() ? [selection.focus, selection.anchor] : [selection.anchor, selection.focus];
forwardSelection.anchor.set(startPoint.key, startPoint.offset, startPoint.type);
forwardSelection.focus.set(endPoint.key, endPoint.offset, endPoint.type);
let currentNodeParent;
let lastCreatedMarkNode;
// Note that extract will split text nodes at the boundaries
const nodes = forwardSelection.extract();
// We only want wrap adjacent text nodes, line break nodes
// and inline element nodes. For decorator nodes and block
// element nodes, we step out of their boundary and start
// again after, if there are more nodes.
for (const node of nodes) {
if ($isElementNode(lastCreatedMarkNode) && lastCreatedMarkNode.isParentOf(node)) {
// If the current node is a child of the last created mark node, there is nothing to do here
continue;
}
let targetNode = null;
if ($isTextNode(node)) {
// Case 1: The node is a text node and we can include it
targetNode = node;
} else if ($isMarkNode(node)) {
// Case 2: the node is a mark node and we can ignore it as a target,
// moving on to its children. Note that when we make a mark inside
// another mark, it may ultimately be unnested by a call to
// `registerNestedElementResolver<MarkNode>` somewhere else in the
// codebase.
continue;
} else if (($isElementNode(node) || $isDecoratorNode(node)) && node.isInline()) {
// Case 3: inline element/decorator nodes can be added in their entirety
// to the new mark
targetNode = node;
}
if (targetNode !== null) {
// Now that we have a target node for wrapping with a mark, we can run
// through special cases.
if (targetNode && targetNode.is(currentNodeParent)) {
// The current node is a child of the target node to be wrapped, there
// is nothing to do here.
continue;
}
const parentNode = targetNode.getParent();
if (parentNode == null || !parentNode.is(currentNodeParent)) {
// If the parent node is not the current node's parent node, we can
// clear the last created mark node.
lastCreatedMarkNode = undefined;
}
currentNodeParent = parentNode;
if (lastCreatedMarkNode === undefined) {
// If we don't have a created mark node, we can make one
const createMarkNode = createNode || $createMarkNode;
lastCreatedMarkNode = createMarkNode([id]);
targetNode.insertBefore(lastCreatedMarkNode);
}
// Add the target node to be wrapped in the latest created mark node
lastCreatedMarkNode.append(targetNode);
} else {
// If we don't have a target node to wrap we can clear our state and
// continue on with the next node
currentNodeParent = undefined;
lastCreatedMarkNode = undefined;
}
}
// Make selection collapsed at the end
if ($isElementNode(lastCreatedMarkNode)) {
// eslint-disable-next-line no-unused-expressions
isBackward ? lastCreatedMarkNode.selectStart() : lastCreatedMarkNode.selectEnd();
}
}
function $getMarkIDs(node, offset) {
let currentNode = node;
while (currentNode !== null) {
if ($isMarkNode(currentNode)) {
return currentNode.getIDs();
} else if ($isTextNode(currentNode) && offset === currentNode.getTextContentSize()) {
const nextSibling = currentNode.getNextSibling();
if ($isMarkNode(nextSibling)) {
return nextSibling.getIDs();
}
}
currentNode = currentNode.getParent();
}
return null;
}
export { $createMarkNode, $getMarkIDs, $isMarkNode, $unwrapMarkNode, $wrapSelectionInMarkNode, MarkNode };
+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 LexicalMark = process.env.NODE_ENV !== 'production' ? require('./LexicalMark.dev.js') : require('./LexicalMark.prod.js');
module.exports = LexicalMark;
+55
View File
@@ -0,0 +1,55 @@
/**
* 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 {
NodeKey,
RangeSelection,
TextNode,
SerializedElementNode,
} from 'lexical';
import {ElementNode, LexicalNode} from 'lexical';
export type SerializedMarkNode = SerializedElementNode & {
ids: Array<string>,
};
declare export class MarkNode extends ElementNode {
__ids: Array<string>;
static clone(node: this): MarkNode;
constructor(ids: Array<string>, key?: NodeKey): void;
hasID(id: string): boolean;
getIDs(): Array<string>;
addID(id: string): void;
deleteID(id: string): void;
canInsertTextBefore(): false;
canInsertTextAfter(): false;
isInline(): true;
}
declare export function $isMarkNode(
node: ?LexicalNode,
): node is MarkNode;
declare export function $createMarkNode(ids: Array<string>): MarkNode;
declare export function $getMarkIDs(
node: TextNode,
offset: number,
): null | Array<string>;
declare export function $wrapSelectionInMarkNode(
selection: RangeSelection,
isBackward: boolean,
id: string,
createNode?: (ids: Array<string>) => MarkNode,
): void;
declare export function $unwrapMarkNode(node: MarkNode): void;
+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 * as modDev from './LexicalMark.dev.mjs';
import * as modProd from './LexicalMark.prod.mjs';
const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
export const $createMarkNode = mod.$createMarkNode;
export const $getMarkIDs = mod.$getMarkIDs;
export const $isMarkNode = mod.$isMarkNode;
export const $unwrapMarkNode = mod.$unwrapMarkNode;
export const $wrapSelectionInMarkNode = mod.$wrapSelectionInMarkNode;
export const MarkNode = mod.MarkNode;
+15
View File
@@ -0,0 +1,15 @@
/**
* 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('./LexicalMark.dev.mjs') : import('./LexicalMark.prod.mjs'));
export const $createMarkNode = mod.$createMarkNode;
export const $getMarkIDs = mod.$getMarkIDs;
export const $isMarkNode = mod.$isMarkNode;
export const $unwrapMarkNode = mod.$unwrapMarkNode;
export const $wrapSelectionInMarkNode = mod.$wrapSelectionInMarkNode;
export const MarkNode = mod.MarkNode;
+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.
*
*/
"use strict";var e=require("lexical"),t=require("@lexical/utils");const r=[];class s extends e.ElementNode{static getType(){return"mark"}static clone(e){return new s(e.__ids,e.__key)}static importDOM(){return null}static importJSON(e){return n().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setIDs(e.ids)}exportJSON(){return{...super.exportJSON(),ids:this.getIDs()}}constructor(e=r,t){super(t),this.__ids=e}createDOM(e){const r=document.createElement("mark");return t.addClassNamesToElement(r,e.theme.mark),this.__ids.length>1&&t.addClassNamesToElement(r,e.theme.markOverlap),r}updateDOM(e,r,s){const n=e.__ids,i=this.__ids,o=n.length,a=i.length,l=s.theme.markOverlap;return o!==a&&(1===o?2===a&&t.addClassNamesToElement(r,l):1===a&&t.removeClassNamesFromElement(r,l)),!1}hasID(e){return this.getIDs().includes(e)}getIDs(){return Array.from(this.getLatest().__ids)}setIDs(e){const t=this.getWritable();return t.__ids=e,t}addID(e){const t=this.getWritable();return t.__ids.includes(e)?t:t.setIDs([...t.__ids,e])}deleteID(e){const t=this.getWritable(),r=t.__ids.indexOf(e);if(-1===r)return t;const s=Array.from(t.__ids);return s.splice(r,1),t.setIDs(s)}insertNewAfter(e,t=!0){const r=n(this.__ids);return this.insertAfter(r,t),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(t,r,s){if(!e.$isRangeSelection(r)||"html"===s)return!1;const n=r.anchor,i=r.focus,o=n.getNode(),a=i.getNode(),l=r.isBackward()?n.offset-i.offset:i.offset-n.offset;return this.isParentOf(o)&&this.isParentOf(a)&&this.getTextContent().length===l}excludeFromCopy(e){return"clone"!==e}}function n(t=r){return e.$applyNodeReplacement(new s(t))}function i(e){return e instanceof s}exports.$createMarkNode=n,exports.$getMarkIDs=function(t,r){let s=t;for(;null!==s;){if(i(s))return s.getIDs();if(e.$isTextNode(s)&&r===s.getTextContentSize()){const e=s.getNextSibling();if(i(e))return e.getIDs()}s=s.getParent()}return null},exports.$isMarkNode=i,exports.$unwrapMarkNode=function(e){const t=e.getChildren();let r=null;for(let s=0;s<t.length;s++){const n=t[s];null===r?e.insertBefore(n):r.insertAfter(n),r=n}e.remove()},exports.$wrapSelectionInMarkNode=function(t,r,s,o){const a=e.$createRangeSelection(),[l,c]=t.isBackward()?[t.focus,t.anchor]:[t.anchor,t.focus];let u,d;a.anchor.set(l.key,l.offset,l.type),a.focus.set(c.key,c.offset,c.type);const f=a.extract();for(const t of f){if(e.$isElementNode(d)&&d.isParentOf(t))continue;let r=null;if(e.$isTextNode(t))r=t;else{if(i(t))continue;(e.$isElementNode(t)||e.$isDecoratorNode(t))&&t.isInline()&&(r=t)}if(null!==r){if(r&&r.is(u))continue;const e=r.getParent();if(null!=e&&e.is(u)||(d=void 0),u=e,void 0===d){d=(o||n)([s]),r.insertBefore(d)}d.append(r)}else u=void 0,d=void 0}e.$isElementNode(d)&&(r?d.selectStart():d.selectEnd())},exports.MarkNode=s;
+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{ElementNode as t,$isRangeSelection as e,$applyNodeReplacement as r,$createRangeSelection as n,$isElementNode as s,$isTextNode as i,$isDecoratorNode as o}from"lexical";import{addClassNamesToElement as c,removeClassNamesFromElement as u}from"@lexical/utils";const l=[];class f extends t{static getType(){return"mark"}static clone(t){return new f(t.__ids,t.__key)}static importDOM(){return null}static importJSON(t){return a().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setIDs(t.ids)}exportJSON(){return{...super.exportJSON(),ids:this.getIDs()}}constructor(t=l,e){super(e),this.__ids=t}createDOM(t){const e=document.createElement("mark");return c(e,t.theme.mark),this.__ids.length>1&&c(e,t.theme.markOverlap),e}updateDOM(t,e,r){const n=t.__ids,s=this.__ids,i=n.length,o=s.length,l=r.theme.markOverlap;return i!==o&&(1===i?2===o&&c(e,l):1===o&&u(e,l)),!1}hasID(t){return this.getIDs().includes(t)}getIDs(){return Array.from(this.getLatest().__ids)}setIDs(t){const e=this.getWritable();return e.__ids=t,e}addID(t){const e=this.getWritable();return e.__ids.includes(t)?e:e.setIDs([...e.__ids,t])}deleteID(t){const e=this.getWritable(),r=e.__ids.indexOf(t);if(-1===r)return e;const n=Array.from(e.__ids);return n.splice(r,1),e.setIDs(n)}insertNewAfter(t,e=!0){const r=a(this.__ids);return this.insertAfter(r,e),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(t,r,n){if(!e(r)||"html"===n)return!1;const s=r.anchor,i=r.focus,o=s.getNode(),c=i.getNode(),u=r.isBackward()?s.offset-i.offset:i.offset-s.offset;return this.isParentOf(o)&&this.isParentOf(c)&&this.getTextContent().length===u}excludeFromCopy(t){return"clone"!==t}}function a(t=l){return r(new f(t))}function d(t){return t instanceof f}function h(t){const e=t.getChildren();let r=null;for(let n=0;n<e.length;n++){const s=e[n];null===r?t.insertBefore(s):r.insertAfter(s),r=s}t.remove()}function _(t,e,r,c){const u=n(),[l,f]=t.isBackward()?[t.focus,t.anchor]:[t.anchor,t.focus];let h,_;u.anchor.set(l.key,l.offset,l.type),u.focus.set(f.key,f.offset,f.type);const m=u.extract();for(const t of m){if(s(_)&&_.isParentOf(t))continue;let e=null;if(i(t))e=t;else{if(d(t))continue;(s(t)||o(t))&&t.isInline()&&(e=t)}if(null!==e){if(e&&e.is(h))continue;const t=e.getParent();if(null!=t&&t.is(h)||(_=void 0),h=t,void 0===_){_=(c||a)([r]),e.insertBefore(_)}_.append(e)}else h=void 0,_=void 0}s(_)&&(e?_.selectStart():_.selectEnd())}function m(t,e){let r=t;for(;null!==r;){if(d(r))return r.getIDs();if(i(r)&&e===r.getTextContentSize()){const t=r.getNextSibling();if(d(t))return t.getIDs()}r=r.getParent()}return null}export{a as $createMarkNode,m as $getMarkIDs,d as $isMarkNode,h as $unwrapMarkNode,_ as $wrapSelectionInMarkNode,f as MarkNode};
+40
View File
@@ -0,0 +1,40 @@
/**
* 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 { BaseSelection, EditorConfig, LexicalNode, LexicalUpdateJSON, NodeKey, RangeSelection, SerializedElementNode, Spread } from 'lexical';
import { ElementNode } from 'lexical';
export type SerializedMarkNode = Spread<{
ids: Array<string>;
}, SerializedElementNode>;
/** @noInheritDoc */
export declare class MarkNode extends ElementNode {
/** @internal */
__ids: readonly string[];
static getType(): string;
static clone(node: MarkNode): MarkNode;
static importDOM(): null;
static importJSON(serializedNode: SerializedMarkNode): MarkNode;
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedMarkNode>): this;
exportJSON(): SerializedMarkNode;
constructor(ids?: readonly string[], key?: NodeKey);
createDOM(config: EditorConfig): HTMLElement;
updateDOM(prevNode: this, element: HTMLElement, config: EditorConfig): boolean;
hasID(id: string): boolean;
getIDs(): Array<string>;
setIDs(ids: readonly string[]): this;
addID(id: string): this;
deleteID(id: string): this;
insertNewAfter(selection: RangeSelection, restoreSelection?: boolean): null | ElementNode;
canInsertTextBefore(): false;
canInsertTextAfter(): false;
canBeEmpty(): false;
isInline(): true;
extractWithChild(child: LexicalNode, selection: BaseSelection, destination: 'clone' | 'html'): boolean;
excludeFromCopy(destination: 'clone' | 'html'): boolean;
}
export declare function $createMarkNode(ids?: readonly string[]): MarkNode;
export declare function $isMarkNode(node: LexicalNode | null): node is MarkNode;
+5
View File
@@ -0,0 +1,5 @@
# `@lexical/mark`
[![See API Documentation](https://lexical.dev/img/see-api-documentation.svg)](https://lexical.dev/docs/api/modules/lexical_mark)
This package contains helpers and nodes for wrapping content in marks for Lexical.
+14
View File
@@ -0,0 +1,14 @@
/**
* 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 { SerializedMarkNode } from './MarkNode';
import type { RangeSelection, TextNode } from 'lexical';
import { $createMarkNode, $isMarkNode, MarkNode } from './MarkNode';
export declare function $unwrapMarkNode(node: MarkNode): void;
export declare function $wrapSelectionInMarkNode(selection: RangeSelection, isBackward: boolean, id: string, createNode?: (ids: Array<string>) => MarkNode): void;
export declare function $getMarkIDs(node: TextNode, offset: number): null | Array<string>;
export { $createMarkNode, $isMarkNode, MarkNode, SerializedMarkNode };
+42
View File
@@ -0,0 +1,42 @@
{
"name": "@lexical/mark",
"description": "This package contains helpers and nodes for wrapping content in marks for Lexical.",
"keywords": [
"lexical",
"editor",
"rich-text",
"mark"
],
"license": "MIT",
"version": "0.35.0",
"main": "LexicalMark.js",
"types": "index.d.ts",
"dependencies": {
"@lexical/utils": "0.35.0",
"lexical": "0.35.0"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-mark"
},
"module": "LexicalMark.mjs",
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./index.d.ts",
"development": "./LexicalMark.dev.mjs",
"production": "./LexicalMark.prod.mjs",
"node": "./LexicalMark.node.mjs",
"default": "./LexicalMark.mjs"
},
"require": {
"types": "./index.d.ts",
"development": "./LexicalMark.dev.js",
"production": "./LexicalMark.prod.js",
"default": "./LexicalMark.js"
}
}
}
}