@portabletext/editor 2.19.2 → 2.20.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;
@@ -1787,10 +1784,7 @@ declare const editorMachine: xstate229.StateMachine<{
1787
1784
  } | {
1788
1785
  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
1786
  decorator: string;
1790
- at?: {
1791
- anchor: BlockOffset;
1792
- focus: BlockOffset;
1793
- };
1787
+ at?: NonNullable<EditorSelection>;
1794
1788
  } | {
1795
1789
  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
1790
  unit: "character" | "word" | "line" | "block";
@@ -1805,10 +1799,7 @@ declare const editorMachine: xstate229.StateMachine<{
1805
1799
  unit: "character" | "word" | "line" | "block";
1806
1800
  } | {
1807
1801
  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
- };
1802
+ at: NonNullable<EditorSelection>;
1812
1803
  } | {
1813
1804
  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
1805
  originEvent: PickFromUnion<NativeBehaviorEvent, "type", "drag.drop" | "clipboard.paste"> | InputBehaviorEvent;
@@ -3254,10 +3245,7 @@ type SyntheticBehaviorEvent = {
3254
3245
  } | {
3255
3246
  type: StrictExtract<SyntheticBehaviorEventType, 'decorator.add'>;
3256
3247
  decorator: string;
3257
- at?: {
3258
- anchor: BlockOffset;
3259
- focus: BlockOffset;
3260
- };
3248
+ at?: NonNullable<EditorSelection>;
3261
3249
  } | {
3262
3250
  type: StrictExtract<SyntheticBehaviorEventType, 'decorator.remove'>;
3263
3251
  decorator: string;
@@ -3324,10 +3312,7 @@ type AbstractBehaviorEvent = {
3324
3312
  } | {
3325
3313
  type: StrictExtract<SyntheticBehaviorEventType, 'decorator.toggle'>;
3326
3314
  decorator: string;
3327
- at?: {
3328
- anchor: BlockOffset;
3329
- focus: BlockOffset;
3330
- };
3315
+ at?: NonNullable<EditorSelection>;
3331
3316
  } | {
3332
3317
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>;
3333
3318
  unit: 'character' | 'word' | 'line' | 'block';
@@ -3342,10 +3327,7 @@ type AbstractBehaviorEvent = {
3342
3327
  unit: 'character' | 'word' | 'line' | 'block';
3343
3328
  } | {
3344
3329
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>;
3345
- at: {
3346
- anchor: BlockOffset;
3347
- focus: BlockOffset;
3348
- };
3330
+ at: NonNullable<EditorSelection>;
3349
3331
  } | {
3350
3332
  type: StrictExtract<SyntheticBehaviorEventType, 'deserialize'>;
3351
3333
  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,