@portabletext/editor 2.16.0 → 2.17.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.
Files changed (30) hide show
  1. package/lib/_chunks-cjs/selector.get-selection-text.cjs +1 -1
  2. package/lib/_chunks-cjs/selector.get-selection-text.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +1 -0
  4. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  5. package/lib/_chunks-dts/behavior.types.action.d.cts +2 -2
  6. package/lib/_chunks-dts/behavior.types.action.d.ts +5 -5
  7. package/lib/_chunks-es/selector.get-selection-text.js +1 -1
  8. package/lib/_chunks-es/selector.get-selection-text.js.map +1 -1
  9. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +1 -0
  10. package/lib/index.cjs +485 -511
  11. package/lib/index.cjs.map +1 -1
  12. package/lib/index.js +488 -514
  13. package/lib/index.js.map +1 -1
  14. package/lib/selectors/index.cjs +1 -0
  15. package/lib/selectors/index.cjs.map +1 -1
  16. package/lib/selectors/index.d.cts +8 -1
  17. package/lib/selectors/index.d.ts +8 -1
  18. package/lib/selectors/index.js +2 -1
  19. package/lib/utils/index.d.ts +2 -2
  20. package/package.json +2 -2
  21. package/src/behaviors/behavior.abstract.delete.ts +12 -16
  22. package/src/behaviors/behavior.abstract.insert.ts +37 -6
  23. package/src/behaviors/behavior.abstract.split.ts +24 -89
  24. package/src/behaviors/behavior.core.lists.ts +9 -3
  25. package/src/behaviors/behavior.types.event.ts +1 -1
  26. package/src/editor/plugins/create-with-event-listeners.ts +30 -31
  27. package/src/operations/behavior.operation.delete.ts +76 -80
  28. package/src/selectors/index.ts +1 -0
  29. package/src/selectors/selector.is-selection-expanded.test.ts +63 -0
  30. package/src/selectors/selector.is-selection-expanded.ts +1 -1
@@ -6,7 +6,7 @@ import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
6
6
  import * as react20 from "react";
7
7
  import React$1, { BaseSyntheticEvent, ClipboardEvent, Component, FocusEvent, JSX, KeyboardEvent as KeyboardEvent$1, MutableRefObject, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
8
8
  import { Patch, Patch as Patch$1 } from "@portabletext/patches";
9
- import * as _portabletext_schema5 from "@portabletext/schema";
9
+ import * as _portabletext_schema6 from "@portabletext/schema";
10
10
  import { AnnotationDefinition, AnnotationSchemaType, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, DecoratorDefinition, DecoratorSchemaType, FieldDefinition, InlineObjectDefinition, InlineObjectSchemaType, ListDefinition, ListSchemaType, PortableTextObject as PortableTextObject$1, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, defineSchema } from "@portabletext/schema";
11
11
  import { Observable, Subject } from "rxjs";
12
12
  import { DOMNode } from "slate-dom";
@@ -1697,7 +1697,7 @@ declare const editorMachine: xstate229.StateMachine<{
1697
1697
  }, xstate229.AnyEventObject>;
1698
1698
  }) => {
1699
1699
  behaviors: Set<{
1700
- behavior: Behavior<"*" | "split" | `custom.${string}` | "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" | "clipboard.copy" | "clipboard.cut" | "clipboard.paste" | "drag.dragstart" | "drag.drag" | "drag.dragend" | "drag.dragenter" | "drag.dragover" | "drag.dragleave" | "drag.drop" | "input.*" | "keyboard.keydown" | "keyboard.keyup" | "mouse.click" | "style.*" | "history.*" | "split.*" | "delete.*" | "select.*" | "deserialize.*" | "serialize.*" | "annotation.*" | "block.*" | "child.*" | "decorator.*" | "insert.*" | "move.*" | "deserialization.*" | "list item.*" | "serialization.*" | "clipboard.*" | "drag.*" | "keyboard.*" | "mouse.*", true, {
1700
+ behavior: Behavior<"*" | "split" | `custom.${string}` | "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" | "clipboard.copy" | "clipboard.cut" | "clipboard.paste" | "drag.dragstart" | "drag.drag" | "drag.dragend" | "drag.dragenter" | "drag.dragover" | "drag.dragleave" | "drag.drop" | "input.*" | "keyboard.keydown" | "keyboard.keyup" | "mouse.click" | "history.*" | "split.*" | "delete.*" | "select.*" | "deserialize.*" | "serialize.*" | "annotation.*" | "block.*" | "child.*" | "decorator.*" | "insert.*" | "move.*" | "deserialization.*" | "list item.*" | "serialization.*" | "style.*" | "clipboard.*" | "drag.*" | "keyboard.*" | "mouse.*", true, {
1701
1701
  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", "annotation.add">;
1702
1702
  annotation: {
1703
1703
  name: string;
@@ -1740,7 +1740,7 @@ declare const editorMachine: xstate229.StateMachine<{
1740
1740
  decorator: string;
1741
1741
  } | {
1742
1742
  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">;
1743
- at: NonNullable<EditorSelection>;
1743
+ at?: NonNullable<EditorSelection>;
1744
1744
  direction?: "backward" | "forward";
1745
1745
  unit?: "character" | "word" | "line" | "block";
1746
1746
  } | {
@@ -1982,7 +1982,7 @@ declare const editorMachine: xstate229.StateMachine<{
1982
1982
  keyGenerator: () => string;
1983
1983
  pendingEvents: never[];
1984
1984
  pendingIncomingPatchesEvents: never[];
1985
- schema: _portabletext_schema5.Schema;
1985
+ schema: _portabletext_schema6.Schema;
1986
1986
  selection: null;
1987
1987
  initialReadOnly: boolean;
1988
1988
  maxBlocks: number | undefined;
@@ -3261,7 +3261,7 @@ type SyntheticBehaviorEvent = {
3261
3261
  decorator: string;
3262
3262
  } | {
3263
3263
  type: StrictExtract<SyntheticBehaviorEventType, 'delete'>;
3264
- at: NonNullable<EditorSelection>;
3264
+ at?: NonNullable<EditorSelection>;
3265
3265
  /**
3266
3266
  * Defaults to forward deletion.
3267
3267
  */
@@ -39,7 +39,7 @@ const getFocusBlock = (snapshot) => {
39
39
  }, getSelectionStartPoint = (snapshot) => {
40
40
  if (snapshot.context.selection)
41
41
  return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
42
- }, isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, isSelectionExpanded = (snapshot) => !isSelectionCollapsed(snapshot), getSelectedValue = (snapshot) => {
42
+ }, isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, isSelectionExpanded = (snapshot) => snapshot.context.selection !== null && !isSelectionCollapsed(snapshot), getSelectedValue = (snapshot) => {
43
43
  const selection = snapshot.context.selection;
44
44
  if (!selection)
45
45
  return [];
@@ -1 +1 @@
1
- {"version":3,"file":"selector.get-selection-text.js","sources":["../../src/selectors/selector.get-focus-block.ts","../../src/selectors/selector.get-focus-text-block.ts","../../src/selectors/selector.get-focus-child.ts","../../src/selectors/selector.get-focus-span.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.get-selected-value.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selection-text.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isSpan} from '@portabletext/schema'\nimport type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isSpan(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = (snapshot) => {\n return !isSelectionCollapsed(snapshot)\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {sliceBlocks} from '../utils/util.slice-blocks'\n\n/**\n * @public\n */\nexport const getSelectedValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return []\n }\n\n const startPoint = getSelectionStartPoint(selection)\n const endPoint = getSelectionEndPoint(selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return []\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return []\n }\n\n const startBlock = snapshot.context.value.at(startBlockIndex)\n const slicedStartBlock = startBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [startBlock],\n }).at(0)\n : undefined\n\n if (startBlockIndex === endBlockIndex) {\n return slicedStartBlock ? [slicedStartBlock] : []\n }\n\n const endBlock = snapshot.context.value.at(endBlockIndex)\n const slicedEndBlock = endBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [endBlock],\n }).at(0)\n : undefined\n\n const middleBlocks = snapshot.context.value.slice(\n startBlockIndex + 1,\n endBlockIndex,\n )\n\n return [\n ...(slicedStartBlock ? [slicedStartBlock] : []),\n ...middleBlocks,\n ...(slicedEndBlock ? [slicedEndBlock] : []),\n ]\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedValue = getSelectedValue(snapshot)\n\n return selectedValue.reduce((text, block) => {\n if (!isTextBlock(snapshot.context, block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isSpan(snapshot.context, child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n"],"names":["getFocusBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","focus","index","blockIndexMap","get","undefined","node","value","at","path","_key","getFocusTextBlock","focusBlock","isTextBlock","getFocusChild","getChildKeyFromSelectionPoint","children","find","span","getFocusSpan","focusChild","isSpan","getSelectionStartPoint","backward","anchor","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","getSelectedValue","startPoint","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startBlockIndex","endBlockIndex","startBlock","slicedStartBlock","sliceBlocks","blocks","endBlock","slicedEndBlock","middleBlocks","slice","getPreviousInlineObject","focusTextBlock","selectionStartPoint","selectionStartPointChildKey","isKeySegment","inlineObject","child","getSelectionText","reduce","text","block"],"mappings":";;;AAQO,MAAMA,gBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,8BAA8BJ,SAASC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,CAClB,EAAElC,GAAG,CAAC,IACPH,QAEEuC,eAAehD,SAASC,QAAQU,MAAMsC,MAC1CT,kBAAkB,GAClBC,aACF;AAEA,SAAO,CACL,GAAIE,mBAAmB,CAACA,gBAAgB,IAAI,CAAA,GAC5C,GAAGK,cACH,GAAID,iBAAiB,CAACA,cAAc,IAAI,CAAA,CAAG;AAE/C,GCvDaG,0BAMRlD,CAAAA,aAAa;AAChB,QAAMmD,iBAAiBpC,kBAAkBf,QAAQ,GAC3CoD,sBAAsB1B,uBAAuB1B,QAAQ,GACrDqD,8BACJD,uBAAuBE,aAAaF,oBAAoBvC,KAAK,CAAC,CAAC,IAC3DuC,oBAAoBvC,KAAK,CAAC,EAAEC,OAC5BL;AAEN,MAAI,CAAC0C,kBAAkB,CAACE;AACtB;AAGF,MAAIE;AAOJ,aAAWC,SAASL,eAAezC,KAAKU,UAAU;AAChD,QAAIoC,MAAM1C,SAASuC;AACjB;AAGG5B,WAAOzB,SAASC,SAASuD,KAAK,MACjCD,eAAe;AAAA,MACb7C,MAAM8C;AAAAA,MACN3C,MAAM,CAAC,GAAGsC,eAAetC,MAAM,YAAY;AAAA,QAACC,MAAM0C,MAAM1C;AAAAA,MAAAA,CAAK;AAAA,IAAA;AAAA,EAGnE;AAEA,SAAOyC;AACT,GC1CaE,mBAA4CzD,CAAAA,aACjCkC,iBAAiBlC,QAAQ,EAE1B0D,OAAO,CAACC,MAAMC,UAC5B3C,YAAYjB,SAASC,SAAS2D,KAAK,IAKtCD,OACAC,MAAMxC,SAASsC,OAAO,CAACC,OAAMH,UACvB/B,OAAOzB,SAASC,SAASuD,KAAK,IACzBG,QAAOH,MAAMG,OAGfA,OACN,EAAE,IAXEA,MAaR,EAAE;"}
1
+ {"version":3,"file":"selector.get-selection-text.js","sources":["../../src/selectors/selector.get-focus-block.ts","../../src/selectors/selector.get-focus-text-block.ts","../../src/selectors/selector.get-focus-child.ts","../../src/selectors/selector.get-focus-span.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.get-selected-value.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selection-text.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isSpan} from '@portabletext/schema'\nimport type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isSpan(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = (snapshot) => {\n return snapshot.context.selection !== null && !isSelectionCollapsed(snapshot)\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {sliceBlocks} from '../utils/util.slice-blocks'\n\n/**\n * @public\n */\nexport const getSelectedValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return []\n }\n\n const startPoint = getSelectionStartPoint(selection)\n const endPoint = getSelectionEndPoint(selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return []\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return []\n }\n\n const startBlock = snapshot.context.value.at(startBlockIndex)\n const slicedStartBlock = startBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [startBlock],\n }).at(0)\n : undefined\n\n if (startBlockIndex === endBlockIndex) {\n return slicedStartBlock ? [slicedStartBlock] : []\n }\n\n const endBlock = snapshot.context.value.at(endBlockIndex)\n const slicedEndBlock = endBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [endBlock],\n }).at(0)\n : undefined\n\n const middleBlocks = snapshot.context.value.slice(\n startBlockIndex + 1,\n endBlockIndex,\n )\n\n return [\n ...(slicedStartBlock ? [slicedStartBlock] : []),\n ...middleBlocks,\n ...(slicedEndBlock ? [slicedEndBlock] : []),\n ]\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedValue = getSelectedValue(snapshot)\n\n return selectedValue.reduce((text, block) => {\n if (!isTextBlock(snapshot.context, block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isSpan(snapshot.context, child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n"],"names":["getFocusBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","focus","index","blockIndexMap","get","undefined","node","value","at","path","_key","getFocusTextBlock","focusBlock","isTextBlock","getFocusChild","getChildKeyFromSelectionPoint","children","find","span","getFocusSpan","focusChild","isSpan","getSelectionStartPoint","backward","anchor","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","getSelectedValue","startPoint","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startBlockIndex","endBlockIndex","startBlock","slicedStartBlock","sliceBlocks","blocks","endBlock","slicedEndBlock","middleBlocks","slice","getPreviousInlineObject","focusTextBlock","selectionStartPoint","selectionStartPointChildKey","isKeySegment","inlineObject","child","getSelectionText","reduce","text","block"],"mappings":";;;A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ject,
859
859
  getNextSpan,
860
860
  getPreviousBlock,
861
+ getPreviousSpan,
861
862
  getSelectedBlocks,
862
863
  getSelectedSpans,
863
864
  getSelectedTextBlocks,