lexical 0.27.3-nightly.20250313.0 → 0.27.3-nightly.20250317.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Lexical.dev.js CHANGED
@@ -1538,7 +1538,7 @@ function $reconcileNode(key, parentDOM) {
1538
1538
  return dom;
1539
1539
  }
1540
1540
  // If the node key doesn't point to the same instance in both maps,
1541
- // it means it were cloned. If they're also dirty, we mark them as mutated.
1541
+ // it was cloned. If it's also dirty, we mark it as mutated.
1542
1542
  if (prevNode !== nextNode && isDirty) {
1543
1543
  setMutatedNode(mutatedNodes, activeEditorNodes, activeMutationListeners, nextNode, 'updated');
1544
1544
  }
@@ -5336,6 +5336,22 @@ class NodeSelection {
5336
5336
  }
5337
5337
  return textContent;
5338
5338
  }
5339
+
5340
+ /**
5341
+ * Remove all nodes in the NodeSelection. If there were any nodes,
5342
+ * replace the selection with a new RangeSelection at the previous
5343
+ * location of the first node.
5344
+ */
5345
+ deleteNodes() {
5346
+ const nodes = this.getNodes();
5347
+ if (($getSelection() || $getPreviousSelection()) === this && nodes[0]) {
5348
+ const firstCaret = $getSiblingCaret(nodes[0], 'next');
5349
+ $setSelectionFromCaretRange($getCaretRange(firstCaret, firstCaret));
5350
+ }
5351
+ for (const node of nodes) {
5352
+ node.remove();
5353
+ }
5354
+ }
5339
5355
  }
5340
5356
  function $isRangeSelection(x) {
5341
5357
  return x instanceof RangeSelection;
@@ -7688,6 +7704,7 @@ function $applyAllTransforms(editorState, editor) {
7688
7704
  for (const currentUntransformedDirtyElement of untransformedDirtyElements) {
7689
7705
  const nodeKey = currentUntransformedDirtyElement[0];
7690
7706
  const intentionallyMarkedAsDirty = currentUntransformedDirtyElement[1];
7707
+ dirtyElements.set(nodeKey, intentionallyMarkedAsDirty);
7691
7708
  if (nodeKey !== 'root' && !intentionallyMarkedAsDirty) {
7692
7709
  continue;
7693
7710
  }
@@ -7695,7 +7712,6 @@ function $applyAllTransforms(editorState, editor) {
7695
7712
  if (node !== undefined && $isNodeValidForTransform(node, compositionKey)) {
7696
7713
  $applyTransforms(editor, node, transformsCache);
7697
7714
  }
7698
- dirtyElements.set(nodeKey, intentionallyMarkedAsDirty);
7699
7715
  }
7700
7716
  untransformedDirtyLeaves = editor._dirtyLeaves;
7701
7717
  untransformedDirtyLeavesLength = untransformedDirtyLeaves.size;
@@ -7961,6 +7977,7 @@ function $commitPendingUpdates(editor, recoveryEditorState) {
7961
7977
  dirtyElements,
7962
7978
  dirtyLeaves,
7963
7979
  editorState: pendingEditorState,
7980
+ mutatedNodes,
7964
7981
  normalizedNodes,
7965
7982
  prevEditorState: recoveryEditorState || currentEditorState,
7966
7983
  tags
@@ -7996,7 +8013,6 @@ function triggerListeners(type, editor, isCurrentlyEnqueuingUpdates, ...payload)
7996
8013
  try {
7997
8014
  const listeners = Array.from(editor._listeners[type]);
7998
8015
  for (let i = 0; i < listeners.length; i++) {
7999
- // @ts-ignore
8000
8016
  listeners[i].apply(null, payload);
8001
8017
  }
8002
8018
  } finally {
@@ -8258,6 +8274,9 @@ class ElementDOMSlot {
8258
8274
  * Return a new ElementDOMSlot with an updated root element
8259
8275
  */
8260
8276
  withElement(element) {
8277
+ if (this.element === element) {
8278
+ return this;
8279
+ }
8261
8280
  return new ElementDOMSlot(element, this.before, this.after);
8262
8281
  }
8263
8282
  /**
@@ -9126,17 +9145,13 @@ class RootNode extends ElementNode {
9126
9145
  }
9127
9146
 
9128
9147
  // Mutate
9129
-
9130
- append(...nodesToAppend) {
9131
- for (let i = 0; i < nodesToAppend.length; i++) {
9132
- const node = nodesToAppend[i];
9133
- if (!$isElementNode(node) && !$isDecoratorNode(node)) {
9134
- {
9135
- formatDevErrorMessage(`rootNode.append: Only element or decorator nodes can be appended to the root node`);
9136
- }
9148
+ splice(start, deleteCount, nodesToInsert) {
9149
+ for (const node of nodesToInsert) {
9150
+ if (!($isElementNode(node) || $isDecoratorNode(node))) {
9151
+ formatDevErrorMessage(`rootNode.splice: Only element or decorator nodes can be inserted to the root node`);
9137
9152
  }
9138
9153
  }
9139
- return super.append(...nodesToAppend);
9154
+ return super.splice(start, deleteCount, nodesToInsert);
9140
9155
  }
9141
9156
  static importJSON(serializedNode) {
9142
9157
  // We don't create a root, and instead use the existing root.
@@ -9368,6 +9383,15 @@ function $isParagraphNode(node) {
9368
9383
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9369
9384
 
9370
9385
  const DEFAULT_SKIP_INITIALIZATION = false;
9386
+
9387
+ /**
9388
+ * The payload passed to an UpdateListener
9389
+ */
9390
+
9391
+ /**
9392
+ * A listener that gets called after the editor is updated
9393
+ */
9394
+
9371
9395
  const COMMAND_PRIORITY_EDITOR = 0;
9372
9396
  const COMMAND_PRIORITY_LOW = 1;
9373
9397
  const COMMAND_PRIORITY_NORMAL = 2;
@@ -10223,7 +10247,7 @@ class LexicalEditor {
10223
10247
  };
10224
10248
  }
10225
10249
  }
10226
- LexicalEditor.version = "0.27.3-nightly.20250313.0+dev.cjs";
10250
+ LexicalEditor.version = "0.27.3-nightly.20250317.0+dev.cjs";
10227
10251
 
10228
10252
  let keyCounter = 1;
10229
10253
  function resetRandomKey() {
package/Lexical.dev.mjs CHANGED
@@ -1536,7 +1536,7 @@ function $reconcileNode(key, parentDOM) {
1536
1536
  return dom;
1537
1537
  }
1538
1538
  // If the node key doesn't point to the same instance in both maps,
1539
- // it means it were cloned. If they're also dirty, we mark them as mutated.
1539
+ // it was cloned. If it's also dirty, we mark it as mutated.
1540
1540
  if (prevNode !== nextNode && isDirty) {
1541
1541
  setMutatedNode(mutatedNodes, activeEditorNodes, activeMutationListeners, nextNode, 'updated');
1542
1542
  }
@@ -5334,6 +5334,22 @@ class NodeSelection {
5334
5334
  }
5335
5335
  return textContent;
5336
5336
  }
5337
+
5338
+ /**
5339
+ * Remove all nodes in the NodeSelection. If there were any nodes,
5340
+ * replace the selection with a new RangeSelection at the previous
5341
+ * location of the first node.
5342
+ */
5343
+ deleteNodes() {
5344
+ const nodes = this.getNodes();
5345
+ if (($getSelection() || $getPreviousSelection()) === this && nodes[0]) {
5346
+ const firstCaret = $getSiblingCaret(nodes[0], 'next');
5347
+ $setSelectionFromCaretRange($getCaretRange(firstCaret, firstCaret));
5348
+ }
5349
+ for (const node of nodes) {
5350
+ node.remove();
5351
+ }
5352
+ }
5337
5353
  }
5338
5354
  function $isRangeSelection(x) {
5339
5355
  return x instanceof RangeSelection;
@@ -7686,6 +7702,7 @@ function $applyAllTransforms(editorState, editor) {
7686
7702
  for (const currentUntransformedDirtyElement of untransformedDirtyElements) {
7687
7703
  const nodeKey = currentUntransformedDirtyElement[0];
7688
7704
  const intentionallyMarkedAsDirty = currentUntransformedDirtyElement[1];
7705
+ dirtyElements.set(nodeKey, intentionallyMarkedAsDirty);
7689
7706
  if (nodeKey !== 'root' && !intentionallyMarkedAsDirty) {
7690
7707
  continue;
7691
7708
  }
@@ -7693,7 +7710,6 @@ function $applyAllTransforms(editorState, editor) {
7693
7710
  if (node !== undefined && $isNodeValidForTransform(node, compositionKey)) {
7694
7711
  $applyTransforms(editor, node, transformsCache);
7695
7712
  }
7696
- dirtyElements.set(nodeKey, intentionallyMarkedAsDirty);
7697
7713
  }
7698
7714
  untransformedDirtyLeaves = editor._dirtyLeaves;
7699
7715
  untransformedDirtyLeavesLength = untransformedDirtyLeaves.size;
@@ -7959,6 +7975,7 @@ function $commitPendingUpdates(editor, recoveryEditorState) {
7959
7975
  dirtyElements,
7960
7976
  dirtyLeaves,
7961
7977
  editorState: pendingEditorState,
7978
+ mutatedNodes,
7962
7979
  normalizedNodes,
7963
7980
  prevEditorState: recoveryEditorState || currentEditorState,
7964
7981
  tags
@@ -7994,7 +8011,6 @@ function triggerListeners(type, editor, isCurrentlyEnqueuingUpdates, ...payload)
7994
8011
  try {
7995
8012
  const listeners = Array.from(editor._listeners[type]);
7996
8013
  for (let i = 0; i < listeners.length; i++) {
7997
- // @ts-ignore
7998
8014
  listeners[i].apply(null, payload);
7999
8015
  }
8000
8016
  } finally {
@@ -8256,6 +8272,9 @@ class ElementDOMSlot {
8256
8272
  * Return a new ElementDOMSlot with an updated root element
8257
8273
  */
8258
8274
  withElement(element) {
8275
+ if (this.element === element) {
8276
+ return this;
8277
+ }
8259
8278
  return new ElementDOMSlot(element, this.before, this.after);
8260
8279
  }
8261
8280
  /**
@@ -9124,17 +9143,13 @@ class RootNode extends ElementNode {
9124
9143
  }
9125
9144
 
9126
9145
  // Mutate
9127
-
9128
- append(...nodesToAppend) {
9129
- for (let i = 0; i < nodesToAppend.length; i++) {
9130
- const node = nodesToAppend[i];
9131
- if (!$isElementNode(node) && !$isDecoratorNode(node)) {
9132
- {
9133
- formatDevErrorMessage(`rootNode.append: Only element or decorator nodes can be appended to the root node`);
9134
- }
9146
+ splice(start, deleteCount, nodesToInsert) {
9147
+ for (const node of nodesToInsert) {
9148
+ if (!($isElementNode(node) || $isDecoratorNode(node))) {
9149
+ formatDevErrorMessage(`rootNode.splice: Only element or decorator nodes can be inserted to the root node`);
9135
9150
  }
9136
9151
  }
9137
- return super.append(...nodesToAppend);
9152
+ return super.splice(start, deleteCount, nodesToInsert);
9138
9153
  }
9139
9154
  static importJSON(serializedNode) {
9140
9155
  // We don't create a root, and instead use the existing root.
@@ -9366,6 +9381,15 @@ function $isParagraphNode(node) {
9366
9381
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9367
9382
 
9368
9383
  const DEFAULT_SKIP_INITIALIZATION = false;
9384
+
9385
+ /**
9386
+ * The payload passed to an UpdateListener
9387
+ */
9388
+
9389
+ /**
9390
+ * A listener that gets called after the editor is updated
9391
+ */
9392
+
9369
9393
  const COMMAND_PRIORITY_EDITOR = 0;
9370
9394
  const COMMAND_PRIORITY_LOW = 1;
9371
9395
  const COMMAND_PRIORITY_NORMAL = 2;
@@ -10221,7 +10245,7 @@ class LexicalEditor {
10221
10245
  };
10222
10246
  }
10223
10247
  }
10224
- LexicalEditor.version = "0.27.3-nightly.20250313.0+dev.esm";
10248
+ LexicalEditor.version = "0.27.3-nightly.20250317.0+dev.esm";
10225
10249
 
10226
10250
  let keyCounter = 1;
10227
10251
  function resetRandomKey() {
package/Lexical.js.flow CHANGED
@@ -809,7 +809,7 @@ declare export class ElementNode extends LexicalNode {
809
809
  nodesToInsert: Array<LexicalNode>,
810
810
  ): this;
811
811
  exportJSON(): SerializedElementNode;
812
- getDOMSlot(dom: HTMLElement): ElementDOMSlot;
812
+ getDOMSlot(dom: HTMLElement): ElementDOMSlot<HTMLElement>;
813
813
  }
814
814
  declare export function $isElementNode(
815
815
  node: ?LexicalNode,
@@ -818,14 +818,14 @@ declare export function $isElementNode(
818
818
  /**
819
819
  * ElementDOMSlot
820
820
  */
821
- declare export class ElementDOMSlot {
822
- element: HTMLElement;
823
- before: Node | null;
824
- after: Node | null;
821
+ declare export class ElementDOMSlot<+T: HTMLElement> {
822
+ +element: HTMLElement;
823
+ +before: Node | null;
824
+ +after: Node | null;
825
825
  constructor(element: HTMLElement, before?: Node | null | void, after?: Node | null | void): void;
826
- withBefore(before: Node | null | void): ElementDOMSlot;
827
- withAfter(after: Node | null | void): ElementDOMSlot;
828
- withElement(element: HTMLElement): ElementDOMSlot;
826
+ withBefore(before: Node | null | void): ElementDOMSlot<T>;
827
+ withAfter(after: Node | null | void): ElementDOMSlot<T>;
828
+ withElement<ElementType: HTMLElement>(element: ElementType): ElementDOMSlot<ElementType>;
829
829
  insertChild(dom: Node): this;
830
830
  removeChild(dom: Node): this;
831
831
  replaceChild(dom: Node, prevDom: Node): this;