@portabletext/editor 6.1.0-canary.0 → 6.1.0-canary.1

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.
@@ -1,4 +1,4 @@
1
- import * as _portabletext_schema5 from "@portabletext/schema";
1
+ import * as _portabletext_schema6 from "@portabletext/schema";
2
2
  import { AnnotationDefinition, AnnotationSchemaType, AnnotationSchemaType as AnnotationSchemaType$1, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, BlockObjectSchemaType as BlockObjectSchemaType$1, DecoratorDefinition, DecoratorSchemaType, DecoratorSchemaType as DecoratorSchemaType$1, FieldDefinition, InlineObjectDefinition, InlineObjectSchemaType, InlineObjectSchemaType as InlineObjectSchemaType$1, ListDefinition, ListSchemaType, ListSchemaType as ListSchemaType$1, PortableTextBlock, PortableTextBlock as PortableTextBlock$1, PortableTextChild, PortableTextChild as PortableTextChild$1, PortableTextListBlock, PortableTextObject, PortableTextObject as PortableTextObject$1, PortableTextSpan, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, StyleSchemaType as StyleSchemaType$1, TypedObject, defineSchema } from "@portabletext/schema";
3
3
  import * as xstate73 from "xstate";
4
4
  import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
@@ -1996,7 +1996,7 @@ declare class PortableTextEditor {
1996
1996
  */
1997
1997
  static delete: (editor: PortableTextEditor, selection: EditorSelection, options?: EditableAPIDeleteOptions) => void;
1998
1998
  static findDOMNode: (editor: PortableTextEditor, element: PortableTextBlock | PortableTextChild) => Node | undefined;
1999
- static findByPath: (editor: PortableTextEditor, path: Path) => [_portabletext_schema5.PortableTextTextBlock<PortableTextObject | _portabletext_schema5.PortableTextSpan> | PortableTextObject | _portabletext_schema5.PortableTextSpan | undefined, Path | undefined];
1999
+ static findByPath: (editor: PortableTextEditor, path: Path) => [_portabletext_schema6.PortableTextTextBlock<PortableTextObject | _portabletext_schema6.PortableTextSpan> | PortableTextObject | _portabletext_schema6.PortableTextSpan | undefined, Path | undefined];
2000
2000
  /**
2001
2001
  * @deprecated
2002
2002
  * Use `editor.send(...)` instead
package/lib/index.js CHANGED
@@ -10971,13 +10971,12 @@ function createUndoSteps({
10971
10971
  return currentUndoStepId === previousUndoStepId || editor.isNormalizingNode ? mergeIntoLastStep(steps, lastStep, op) : createNewStep(steps, op, editor);
10972
10972
  if (op.type === "set_selection" && currentUndoStepId === void 0 && previousUndoStepId !== void 0 || op.type === "set_selection" && currentUndoStepId !== void 0 && previousUndoStepId !== void 0 && previousUndoStepId !== currentUndoStepId)
10973
10973
  return mergeIntoLastStep(steps, lastStep, op);
10974
- if (currentUndoStepId === void 0 && previousUndoStepId === void 0) {
10975
- if (op.type === "set_selection")
10974
+ if ((op.type === "insert_text" || op.type === "remove_text") && !(lastStep.operations.length > 0 && lastStep.operations.at(-1)?.type === "set_selection" && previousUndoStepId !== currentUndoStepId)) {
10975
+ const lastTextOp = findLastTextOp(lastStep.operations);
10976
+ if (lastTextOp && op.type === "insert_text" && lastTextOp.type === "insert_text" && op.offset === lastTextOp.offset + lastTextOp.text.length && Path.equals(op.path, lastTextOp.path) && op.text !== " " || lastTextOp && op.type === "remove_text" && lastTextOp.type === "remove_text" && op.offset + op.text.length === lastTextOp.offset && Path.equals(op.path, lastTextOp.path))
10976
10977
  return mergeIntoLastStep(steps, lastStep, op);
10977
- const lastOp = lastStep.operations.at(-1);
10978
- return lastOp && op.type === "insert_text" && lastOp.type === "insert_text" && op.offset === lastOp.offset + lastOp.text.length && Path.equals(op.path, lastOp.path) && op.text !== " " || lastOp && op.type === "remove_text" && lastOp.type === "remove_text" && op.offset + op.text.length === lastOp.offset && Path.equals(op.path, lastOp.path) ? mergeIntoLastStep(steps, lastStep, op) : createNewStep(steps, op, editor);
10979
10978
  }
10980
- return createNewStep(steps, op, editor);
10979
+ return currentUndoStepId === void 0 && previousUndoStepId === void 0 && op.type === "set_selection" ? mergeIntoLastStep(steps, lastStep, op) : createNewStep(steps, op, editor);
10981
10980
  }
10982
10981
  function createNewStep(steps, op, editor) {
10983
10982
  const operations = editor.selection === null ? [op] : [{
@@ -11000,6 +10999,13 @@ function mergeIntoLastStep(steps, lastStep, op) {
11000
10999
  operations: [...lastStep.operations, op]
11001
11000
  }];
11002
11001
  }
11002
+ function findLastTextOp(operations) {
11003
+ for (let i = operations.length - 1; i >= 0; i--) {
11004
+ const op = operations[i];
11005
+ if (op !== void 0 && (op.type === "insert_text" || op.type === "remove_text"))
11006
+ return op;
11007
+ }
11008
+ }
11003
11009
  const UNDO_STEP_LIMIT = 1e3;
11004
11010
  function createHistoryPlugin({
11005
11011
  editorActor,