@portabletext/editor 2.19.3 → 2.21.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.
@@ -1732,10 +1732,7 @@ declare const editorMachine: xstate229.StateMachine<{
1732
1732
  } | {
1733
1733
  type: StrictExtract<"split" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle", "decorator.add">;
1734
1734
  decorator: string;
1735
- at?: {
1736
- anchor: BlockOffset;
1737
- focus: BlockOffset;
1738
- };
1735
+ at?: NonNullable<EditorSelection>;
1739
1736
  } | {
1740
1737
  type: StrictExtract<"split" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle", "decorator.remove">;
1741
1738
  decorator: string;
@@ -1753,6 +1750,7 @@ declare const editorMachine: xstate229.StateMachine<{
1753
1750
  block: BlockWithOptionalKey;
1754
1751
  placement: InsertPlacement;
1755
1752
  select?: "start" | "end" | "none";
1753
+ at?: NonNullable<EditorSelection>;
1756
1754
  } | {
1757
1755
  type: StrictExtract<"split" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle", "insert.child">;
1758
1756
  child: ChildWithOptionalKey;
@@ -1787,10 +1785,7 @@ declare const editorMachine: xstate229.StateMachine<{
1787
1785
  } | {
1788
1786
  type: StrictExtract<"split" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle", "decorator.toggle">;
1789
1787
  decorator: string;
1790
- at?: {
1791
- anchor: BlockOffset;
1792
- focus: BlockOffset;
1793
- };
1788
+ at?: NonNullable<EditorSelection>;
1794
1789
  } | {
1795
1790
  type: StrictExtract<"split" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle", "delete.backward">;
1796
1791
  unit: "character" | "word" | "line" | "block";
@@ -1805,10 +1800,7 @@ declare const editorMachine: xstate229.StateMachine<{
1805
1800
  unit: "character" | "word" | "line" | "block";
1806
1801
  } | {
1807
1802
  type: StrictExtract<"split" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle", "delete.text">;
1808
- at: {
1809
- anchor: BlockOffset;
1810
- focus: BlockOffset;
1811
- };
1803
+ at: NonNullable<EditorSelection>;
1812
1804
  } | {
1813
1805
  type: StrictExtract<"split" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle", "deserialize">;
1814
1806
  originEvent: PickFromUnion<NativeBehaviorEvent, "type", "drag.drop" | "clipboard.paste"> | InputBehaviorEvent;
@@ -3254,10 +3246,7 @@ type SyntheticBehaviorEvent = {
3254
3246
  } | {
3255
3247
  type: StrictExtract<SyntheticBehaviorEventType, 'decorator.add'>;
3256
3248
  decorator: string;
3257
- at?: {
3258
- anchor: BlockOffset;
3259
- focus: BlockOffset;
3260
- };
3249
+ at?: NonNullable<EditorSelection>;
3261
3250
  } | {
3262
3251
  type: StrictExtract<SyntheticBehaviorEventType, 'decorator.remove'>;
3263
3252
  decorator: string;
@@ -3281,6 +3270,7 @@ type SyntheticBehaviorEvent = {
3281
3270
  block: BlockWithOptionalKey;
3282
3271
  placement: InsertPlacement;
3283
3272
  select?: 'start' | 'end' | 'none';
3273
+ at?: NonNullable<EditorSelection>;
3284
3274
  } | {
3285
3275
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.child'>;
3286
3276
  child: ChildWithOptionalKey;
@@ -3324,10 +3314,7 @@ type AbstractBehaviorEvent = {
3324
3314
  } | {
3325
3315
  type: StrictExtract<SyntheticBehaviorEventType, 'decorator.toggle'>;
3326
3316
  decorator: string;
3327
- at?: {
3328
- anchor: BlockOffset;
3329
- focus: BlockOffset;
3330
- };
3317
+ at?: NonNullable<EditorSelection>;
3331
3318
  } | {
3332
3319
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>;
3333
3320
  unit: 'character' | 'word' | 'line' | 'block';
@@ -3342,10 +3329,7 @@ type AbstractBehaviorEvent = {
3342
3329
  unit: 'character' | 'word' | 'line' | 'block';
3343
3330
  } | {
3344
3331
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>;
3345
- at: {
3346
- anchor: BlockOffset;
3347
- focus: BlockOffset;
3348
- };
3332
+ at: NonNullable<EditorSelection>;
3349
3333
  } | {
3350
3334
  type: StrictExtract<SyntheticBehaviorEventType, 'deserialize'>;
3351
3335
  originEvent: PickFromUnion<NativeBehaviorEvent, 'type', 'drag.drop' | 'clipboard.paste'> | InputBehaviorEvent;
@@ -1,6 +1,6 @@
1
1
  import { isPortableTextSpan, isKeySegment } from "@sanity/types";
2
2
  import { getFocusChild, getFocusBlock, getSelectionStartPoint as getSelectionStartPoint$1, getFocusTextBlock, getFocusSpan, isSelectionCollapsed as isSelectionCollapsed$1, getPreviousInlineObject, getSelectionText, isSelectionExpanded as isSelectionExpanded$1, getSelectedValue } from "./selector.get-selection-text.js";
3
- import { isEqualSelectionPoints, getBlockEndPoint, isSelectionCollapsed, isEmptyTextBlock } from "./util.is-empty-text-block.js";
3
+ import { isEqualSelectionPoints, getBlockEndPoint, isSelectionCollapsed } from "./util.is-empty-text-block.js";
4
4
  import { isTextBlock, isSpan } from "@portabletext/schema";
5
5
  import { getBlockKeyFromSelectionPoint, getSelectionStartPoint, getSelectionEndPoint as getSelectionEndPoint$1, getChildKeyFromSelectionPoint, getBlockStartPoint, blockOffsetToSpanSelectionPoint, spanSelectionPointToBlockOffset, isListBlock } from "./util.get-text-block-text.js";
6
6
  const getFocusInlineObject = (snapshot) => {
@@ -496,95 +496,7 @@ function getActiveDecorators(snapshot) {
496
496
  decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
497
497
  return activeDecorators;
498
498
  }
499
- const getTrimmedSelection = (snapshot) => {
500
- if (!snapshot.context.selection)
501
- return snapshot.context.selection;
502
- const startPoint = getSelectionStartPoint(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), startChildKey = getChildKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint), endChildKey = getChildKeyFromSelectionPoint(endPoint);
503
- if (!startBlockKey || !endBlockKey)
504
- return snapshot.context.selection;
505
- const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
506
- if (startBlockIndex === void 0 || endBlockIndex === void 0)
507
- return snapshot.context.selection;
508
- const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
509
- let startBlockFound = !1, adjustedStartPoint, trimStartPoint = !1, adjustedEndPoint, trimEndPoint = !1, previousPotentialEndpoint;
510
- for (const block of slicedValue)
511
- if (!(block._key === startBlockKey && (startBlockFound = !0, isTextBlock(snapshot.context, block) && isEmptyTextBlock(snapshot.context, block))) && startBlockFound && isTextBlock(snapshot.context, block)) {
512
- if (block._key === endBlockKey && isEmptyTextBlock(snapshot.context, block))
513
- break;
514
- for (const child of block.children) {
515
- if (child._key === endChildKey && (!isSpan(snapshot.context, child) || endPoint.offset === 0)) {
516
- adjustedEndPoint = previousPotentialEndpoint ? {
517
- path: [{
518
- _key: previousPotentialEndpoint.blockKey
519
- }, "children", {
520
- _key: previousPotentialEndpoint.span._key
521
- }],
522
- offset: previousPotentialEndpoint.span.text.length
523
- } : void 0, trimEndPoint = !0;
524
- break;
525
- }
526
- if (trimStartPoint) {
527
- const lonelySpan = isSpan(snapshot.context, child) && block.children.length === 1;
528
- (isSpan(snapshot.context, child) && child.text.length > 0 || lonelySpan) && (adjustedStartPoint = {
529
- path: [{
530
- _key: block._key
531
- }, "children", {
532
- _key: child._key
533
- }],
534
- offset: 0
535
- }, previousPotentialEndpoint = {
536
- blockKey: block._key,
537
- span: child
538
- }, trimStartPoint = !1);
539
- continue;
540
- }
541
- if (child._key === startChildKey) {
542
- if (!isSpan(snapshot.context, child)) {
543
- trimStartPoint = !0;
544
- continue;
545
- }
546
- if (startPoint.offset === child.text.length) {
547
- trimStartPoint = !0, previousPotentialEndpoint = child.text.length > 0 ? {
548
- blockKey: block._key,
549
- span: child
550
- } : previousPotentialEndpoint;
551
- continue;
552
- }
553
- }
554
- previousPotentialEndpoint = isSpan(snapshot.context, child) && child.text.length > 0 ? {
555
- blockKey: block._key,
556
- span: child
557
- } : previousPotentialEndpoint;
558
- }
559
- if (block._key === endBlockKey)
560
- break;
561
- }
562
- const trimmedSelection = snapshot.context.selection.backward ? {
563
- anchor: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,
564
- focus: adjustedStartPoint ?? startPoint,
565
- backward: !0
566
- } : {
567
- anchor: adjustedStartPoint ?? startPoint,
568
- focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint
569
- };
570
- if (isSelectionCollapsed$1({
571
- context: {
572
- ...snapshot.context,
573
- selection: trimmedSelection
574
- }
575
- })) {
576
- const focusTextBlock = getFocusTextBlock({
577
- ...snapshot,
578
- context: {
579
- ...snapshot.context,
580
- selection: trimmedSelection
581
- }
582
- });
583
- if (focusTextBlock && !isEmptyTextBlock(snapshot.context, focusTextBlock.node))
584
- return null;
585
- }
586
- return trimmedSelection;
587
- }, getActiveAnnotations = (snapshot) => {
499
+ const getActiveAnnotations = (snapshot) => {
588
500
  if (!snapshot.context.selection)
589
501
  return [];
590
502
  const selectedBlocks = getSelectedBlocks(snapshot), activeAnnotations = (getMarkState(snapshot)?.marks ?? []).filter((mark) => !snapshot.context.schema.decorators.map((decorator) => decorator.name).includes(mark));
@@ -865,7 +777,6 @@ export {
865
777
  getSelectionEndBlock,
866
778
  getSelectionEndPoint,
867
779
  getSelectionStartBlock,
868
- getTrimmedSelection,
869
780
  isActiveAnnotation,
870
781
  isActiveDecorator,
871
782
  isActiveListItem,