@portabletext/editor 2.17.0 → 2.17.2

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.
@@ -38,7 +38,7 @@ const getFocusBlock = (snapshot) => {
38
38
  }, getSelectionStartPoint = (snapshot) => {
39
39
  if (snapshot.context.selection)
40
40
  return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
41
- }, 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) => {
41
+ }, 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) => {
42
42
  const selection = snapshot.context.selection;
43
43
  if (!selection)
44
44
  return [];
@@ -1 +1 @@
1
- {"version":3,"file":"selector.get-selection-text.cjs","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,sBAAAA,8BAA8BJ,SAASC,QAAQC,UAAUG,KAAK,GACpEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAEhDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAA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AAA,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,MAAAA,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,WAAAA,OAAOzB,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,OAAAA,YAAYjB,SAASC,SAAS2D,KAAK,IAKtCD,OACAC,MAAMxC,SAASsC,OAAO,CAACC,OAAMH,UACvB/B,OAAAA,OAAOzB,SAASC,SAASuD,KAAK,IACzBG,QAAOH,MAAMG,OAGfA,OACN,EAAE,IAXEA,MAaR,EAAE;;;;;;;;;;;"}
1
+ {"version":3,"file":"selector.get-selection-text.cjs","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":";;AAQO,MAAMA,gBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,sBAAAA,8BAA8BJ,S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= require("@portabletext/schema"), getRandomValues = require("get-random-values-esm");
3
- function _interopDefaultCompat(e) {
4
- return e && typeof e == "object" && "default" in e ? e : { default: e };
5
- }
6
- var getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
2
+ var schema = require("@portabletext/schema");
7
3
  function getBlockStartPoint({
8
4
  context,
9
5
  block
@@ -322,7 +318,7 @@ const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__
322
318
  })();
323
319
  function whatwgRNG(length = 16) {
324
320
  const rnds8 = new Uint8Array(length);
325
- return getRandomValues__default.default(rnds8), rnds8;
321
+ return crypto.getRandomValues(rnds8), rnds8;
326
322
  }
327
323
  function randomKey(length) {
328
324
  const table = getByteHexTable();
@@ -1 +1 @@
1
- {"version":3,"file":"util.get-text-block-text.cjs","sources":["../../src/utils/util.get-block-start-point.ts","../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.selection-point.ts","../../src/utils/util.block-offset.ts","../../src/utils/asserters.ts","../../src/utils/parse-blocks.ts","../../src/utils/key-generator.ts","../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.slice-blocks.ts","../../src/utils/util.get-text-block-text.ts"],"sourcesContent":["import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: BlockPath\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n return {\n path: [...block.path, 'children', {_key: block.node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {KeyedSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: unknown): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\nexport function getBlockKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const blockPathSegment = point.path.at(0)\n\n if (isKeyedSegment(blockPathSegment)) {\n return blockPathSegment._key\n }\n\n return undefined\n}\n\nexport function getChildKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const childPathSegment = point.path.at(2)\n\n if (isKeyedSegment(childPathSegment)) {\n return childPathSegment._key\n }\n\n return undefined\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {ChildPath} from '../types/paths'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n context,\n blockOffset,\n direction,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint: {path: ChildPath; offset: number} | undefined\n let skippedInlineObject = false\n\n for (const block of context.value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (direction === 'forward') {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n\n continue\n }\n\n if (!isSpan(context, child)) {\n skippedInlineObject = true\n continue\n }\n\n if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {\n if (skippedInlineObject) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n }\n break\n }\n\n if (offsetLeft > child.text.length) {\n offsetLeft -= child.text.length\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n\n offsetLeft -= child.text.length\n\n if (offsetLeft !== 0) {\n break\n }\n }\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n const spanKey = getChildKeyFromSelectionPoint(selectionPoint)\n\n if (!blockKey || !spanKey) {\n return undefined\n }\n\n for (const block of context.value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (child._key === spanKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import type {TypedObject} from '@sanity/types'\n\nexport function isTypedObject(object: unknown): object is TypedObject {\n return isRecord(object) && typeof object._type === 'string'\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {\n PortableTextBlock,\n PortableTextListBlock,\n PortableTextObject,\n PortableTextSpan,\n PortableTextTextBlock,\n TypedObject,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTypedObject} from './asserters'\n\nexport function parseBlocks({\n context,\n blocks,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n blocks: unknown\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): Array<PortableTextBlock> {\n if (!Array.isArray(blocks)) {\n return []\n }\n\n return blocks.flatMap((block) => {\n const parsedBlock = parseBlock({context, block, options})\n\n return parsedBlock ? [parsedBlock] : []\n })\n}\n\nexport function parseBlock({\n context,\n block,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n block: unknown\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): PortableTextBlock | undefined {\n return (\n parseTextBlock({block, context, options}) ??\n parseBlockObject({blockObject: block, context, options})\n )\n}\n\nexport function parseBlockObject({\n blockObject,\n context,\n options,\n}: {\n blockObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(blockObject)) {\n return undefined\n }\n\n const schemaType = context.schema.blockObjects.find(\n ({name}) => name === blockObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: blockObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function isListBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextListBlock {\n return (\n isTextBlock(context, block) &&\n block.level !== undefined &&\n block.listItem !== undefined\n )\n}\n\nexport function parseTextBlock({\n block,\n context,\n options,\n}: {\n block: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): PortableTextTextBlock | undefined {\n if (!isTypedObject(block)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(block)) {\n if (\n key === '_type' ||\n key === '_key' ||\n key === 'children' ||\n key === 'markDefs' ||\n key === 'style' ||\n key === 'listItem' ||\n key === 'level'\n ) {\n continue\n }\n\n if (options.validateFields) {\n if (context.schema.block.fields?.some((field) => field.name === key)) {\n customFields[key] = block[key]\n }\n } else {\n customFields[key] = block[key]\n }\n }\n\n if (block._type !== context.schema.block.name) {\n return undefined\n }\n\n const _key =\n typeof block._key === 'string' ? block._key : context.keyGenerator()\n\n const unparsedMarkDefs: Array<unknown> = Array.isArray(block.markDefs)\n ? block.markDefs\n : []\n const markDefKeyMap = new Map<string, string>()\n const markDefs = unparsedMarkDefs.flatMap((markDef) => {\n if (!isTypedObject(markDef)) {\n return []\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === markDef._type,\n )\n\n if (!schemaType) {\n return []\n }\n\n if (typeof markDef._key !== 'string') {\n // If the `markDef` doesn't have a `_key` then we don't know what spans\n // it belongs to and therefore we have to discard it.\n return []\n }\n\n const parsedAnnotation = parseObject({\n object: markDef,\n context: {\n schemaType,\n keyGenerator: context.keyGenerator,\n },\n options,\n })\n\n if (!parsedAnnotation) {\n return []\n }\n\n markDefKeyMap.set(markDef._key, parsedAnnotation._key)\n\n return [parsedAnnotation]\n })\n\n const unparsedChildren: Array<unknown> = Array.isArray(block.children)\n ? block.children\n : []\n\n const children = unparsedChildren\n .map(\n (child) =>\n parseSpan({span: child, context, markDefKeyMap, options}) ??\n parseInlineObject({inlineObject: child, context, options}),\n )\n .filter((child) => child !== undefined)\n const marks = children.flatMap((child) => child.marks ?? [])\n\n const parsedBlock: PortableTextTextBlock = {\n _type: context.schema.block.name,\n _key,\n children:\n children.length > 0\n ? children\n : [\n {\n _key: context.keyGenerator(),\n _type: context.schema.span.name,\n text: '',\n marks: [],\n },\n ],\n markDefs: options.removeUnusedMarkDefs\n ? markDefs.filter((markDef) => marks.includes(markDef._key))\n : markDefs,\n ...customFields,\n }\n\n if (\n typeof block.style === 'string' &&\n context.schema.styles.find((style) => style.name === block.style)\n ) {\n parsedBlock.style = block.style\n } else {\n const defaultStyle = context.schema.styles.at(0)?.name\n\n if (defaultStyle !== undefined) {\n parsedBlock.style = defaultStyle\n } else {\n console.error('Expected default style')\n }\n }\n\n if (\n typeof block.listItem === 'string' &&\n context.schema.lists.find((list) => list.name === block.listItem)\n ) {\n parsedBlock.listItem = block.listItem\n }\n\n if (typeof block.level === 'number') {\n parsedBlock.level = block.level\n }\n\n return parsedBlock\n}\n\nexport function parseSpan({\n span,\n context,\n markDefKeyMap,\n options,\n}: {\n span: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n markDefKeyMap: Map<string, string>\n options: {validateFields: boolean}\n}): PortableTextSpan | undefined {\n if (!isTypedObject(span)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(span)) {\n if (\n key !== '_type' &&\n key !== '_key' &&\n key !== 'text' &&\n key !== 'marks'\n ) {\n customFields[key] = span[key]\n }\n }\n\n // In reality, the span schema name is always 'span', but we only the check here anyway\n if (span._type !== context.schema.span.name || span._type !== 'span') {\n return undefined\n }\n\n const unparsedMarks: Array<unknown> = Array.isArray(span.marks)\n ? span.marks\n : []\n const marks = unparsedMarks.flatMap((mark) => {\n if (typeof mark !== 'string') {\n return []\n }\n\n const markDefKey = markDefKeyMap.get(mark)\n\n if (markDefKey !== undefined) {\n return [markDefKey]\n }\n\n if (\n context.schema.decorators.some((decorator) => decorator.name === mark)\n ) {\n return [mark]\n }\n\n return []\n })\n\n return {\n _type: 'span',\n _key: typeof span._key === 'string' ? span._key : context.keyGenerator(),\n text: typeof span.text === 'string' ? span.text : '',\n marks,\n ...(options.validateFields ? {} : customFields),\n }\n}\n\nexport function parseInlineObject({\n inlineObject,\n context,\n options,\n}: {\n inlineObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(inlineObject)) {\n return undefined\n }\n\n const schemaType = context.schema.inlineObjects.find(\n ({name}) => name === inlineObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: inlineObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function parseAnnotation({\n annotation,\n context,\n options,\n}: {\n annotation: TypedObject\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(annotation)) {\n return undefined\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === annotation._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: annotation,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nfunction parseObject({\n object,\n context,\n options,\n}: {\n object: TypedObject\n context: Pick<EditorContext, 'keyGenerator'> & {\n schemaType: EditorSchema['blockObjects'][0]\n }\n options: {validateFields: boolean}\n}): PortableTextObject {\n const {_type, _key, ...customFields} = object\n\n // Validates all props on the object and only takes those that match\n // the name of a field\n const values = options.validateFields\n ? context.schemaType.fields.reduce<Record<string, unknown>>(\n (fieldValues, field) => {\n const fieldValue = object[field.name]\n\n if (fieldValue !== undefined) {\n fieldValues[field.name] = fieldValue\n }\n\n return fieldValues\n },\n {},\n )\n : customFields\n\n return {\n _type: context.schemaType.name,\n _key:\n typeof object._key === 'string' ? object._key : context.keyGenerator(),\n ...values,\n }\n}\n","import getRandomValues from 'get-random-values-esm'\n\n/**\n * @public\n */\nexport const defaultKeyGenerator = (): string => randomKey(12)\n\nconst getByteHexTable = (() => {\n let table: any[]\n return () => {\n if (table) {\n return table\n }\n\n table = []\n for (let i = 0; i < 256; ++i) {\n table[i] = (i + 0x100).toString(16).slice(1)\n }\n return table\n }\n})()\n\n// WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html\nfunction whatwgRNG(length = 16) {\n const rnds8 = new Uint8Array(length)\n getRandomValues(rnds8)\n return rnds8\n}\n\nfunction randomKey(length?: number): string {\n const table = getByteHexTable()\n return whatwgRNG(length)\n .reduce((str, n) => str + table[n], '')\n .slice(0, length)\n}\n","import type {EditorSelection, EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection, EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getSelectionStartPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.focus : selection.anchor\n ) as TEditorSelectionPoint\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {defaultKeyGenerator} from './key-generator'\nimport {parseBlock} from './parse-blocks'\nimport {getSelectionEndPoint} from './util.get-selection-end-point'\nimport {getSelectionStartPoint} from './util.get-selection-start-point'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\n/**\n * @public\n */\nexport function sliceBlocks({\n context,\n blocks,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n blocks: Array<PortableTextBlock>\n}): Array<PortableTextBlock> {\n const slice: Array<PortableTextBlock> = []\n\n if (!context.selection) {\n return slice\n }\n\n let startBlock: PortableTextBlock | undefined\n const middleBlocks: PortableTextBlock[] = []\n let endBlock: PortableTextBlock | undefined\n\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return slice\n }\n\n for (const block of blocks) {\n if (!isTextBlock(context, block)) {\n if (block._key === startBlockKey && block._key === endBlockKey) {\n startBlock = block\n break\n }\n }\n\n if (block._key === startBlockKey) {\n if (!isTextBlock(context, block)) {\n startBlock = block\n continue\n }\n\n if (startChildKey) {\n for (const child of block.children) {\n if (child._key === startChildKey) {\n if (isSpan(context, child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n startBlock = {\n ...block,\n children: [\n {\n ...child,\n text,\n },\n ],\n }\n } else {\n startBlock = {\n ...block,\n children: [child],\n }\n }\n\n if (block._key === endBlockKey && startChildKey === endChildKey) {\n break\n }\n continue\n }\n\n if (startBlock && isTextBlock(context, startBlock)) {\n if (\n endChildKey &&\n child._key === endChildKey &&\n isSpan(context, child)\n ) {\n startBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n startBlock.children.push(child)\n }\n\n if (\n block._key === endBlockKey &&\n endChildKey &&\n child._key === endChildKey\n ) {\n break\n }\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n startBlock = block\n\n if (startBlockKey === endBlockKey) {\n break\n }\n }\n\n if (block._key === endBlockKey) {\n if (!isTextBlock(context, block)) {\n endBlock = block\n break\n }\n\n if (endChildKey) {\n endBlock = {\n ...block,\n children: [],\n }\n\n for (const child of block.children) {\n if (endBlock && isTextBlock(context, endBlock)) {\n if (child._key === endChildKey && isSpan(context, child)) {\n endBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n\n break\n }\n\n endBlock.children.push(child)\n\n if (endChildKey && child._key === endChildKey) {\n break\n }\n }\n }\n\n break\n }\n\n endBlock = block\n\n break\n }\n\n if (startBlock) {\n middleBlocks.push(\n parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n }) ?? block,\n )\n }\n }\n\n const parsedStartBlock = startBlock\n ? parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block: startBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n : undefined\n\n const parsedEndBlock = endBlock\n ? parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block: endBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n : undefined\n\n return [\n ...(parsedStartBlock ? [parsedStartBlock] : []),\n ...middleBlocks,\n ...(parsedEndBlock ? [parsedEndBlock] : []),\n ]\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n"],"names":["getBlockStartPoint","context","block","isTextBlock","node","path","_key","children","offset","isKeyedSegment","segment","getBlockKeyFromSelectionPoint","point","blockPathSegment","at","getChildKeyFromSelectionPoint","childPathSegment","blockOffsetToSpanSelectionPoint","blockOffset","direction","offsetLeft","selectionPoint","skippedInlineObject","value","child","isSpan","text","length","spanSelectionPointToBlockOffset","blockKey","spanKey","isTypedObject","object","isRecord","_type","parseBlocks","blocks","options","Array","isArray","flatMap","parsedBlock","parseBlock","parseTextBlock","parseBlockObject","blockObject","schemaType","schema","blockObjects","find","name","parseObject","keyGenerator","isListBlock","level","undefined","listItem","customFields","key","Object","keys","validateFields","fields","some","field","unparsedMarkDefs","markDefs","markDefKeyMap","Map","markDef","annotations","parsedAnnotation","set","map","parseSpan","span","parseInlineObject","inlineObject","filter","marks","removeUnusedMarkDefs","includes","style","styles","defaultStyle","console","error","lists","list","mark","markDefKey","get","decorators","decorator","inlineObjects","parseAnnotation","annotation","values","reduce","fieldValues","fieldValue","defaultKeyGenerator","randomKey","getByteHexTable","table","i","toString","slice","whatwgRNG","rnds8","Uint8Array","getRandomValues","str","n","getSelectionEndPoint","selection","backward","anchor","focus","getSelectionStartPoint","sliceBlocks","startBlock","middleBlocks","endBlock","startPoint","endPoint","startBlockKey","startChildKey","endBlockKey","endChildKey","push","pars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ACTzC,SAAS;AAAA,QACP,GAAGA;AAAAA,QACHmD,cAAciD;AAAAA,MAAAA;AAAAA,MAEhBnG;AAAAA,MACAmC,SAAS;AAAA,QAAC2C,sBAAsB;AAAA,QAAMnB,gBAAgB;AAAA,MAAA;AAAA,IAAK,CAC5D,KAAK3D,KACR;AAAA,EAEJ;AAEA,QAAMiI,mBAAmBV,aACrB/E,WAAW;AAAA,IACTzC,SAAS;AAAA,MACP,GAAGA;AAAAA,MACHmD,cAAciD;AAAAA,IAAAA;AAAAA,IAEhBnG,OAAOuH;AAAAA,IACPpF,SAAS;AAAA,MAAC2C,sBAAsB;AAAA,MAAMnB,gBAAgB;AAAA,IAAA;AAAA,EAAK,CAC5D,IACDN,QAEE6E,iBAAiBT,WACnBjF,WAAW;AAAA,IACTzC,SAAS;AAAA,MACP,GAAGA;AAAAA,MACHmD,cAAciD;AAAAA,IAAAA;AAAAA,IAEhBnG,OAAOyH;AAAAA,IACPtF,SAAS;AAAA,MAAC2C,sBAAsB;AAAA,MAAMnB,gBAAgB;AAAA,IAAA;AAAA,EAAK,CAC5D,IACDN;AAEJ,SAAO,CACL,GAAI4E,mBAAmB,CAACA,gBAAgB,IAAI,CAAA,GAC5C,GAAGT,cACH,GAAIU,iBAAiB,CAACA,cAAc,IAAI,CAAA,CAAG;AAE/C;ACzMO,SAASC,iBAAiBnI,OAA8B;AAC7D,SAAOA,MAAMK,SAASkE,IAAKjD,CAAAA,UAAUA,MAAME,QAAQ,EAAE,EAAE4G,KAAK,EAAE;AAChE;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"util.get-text-block-text.cjs","sources":["../../src/utils/util.get-block-start-point.ts","../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.selection-point.ts","../../src/utils/util.block-offset.ts","../../src/utils/asserters.ts","../../src/utils/parse-blocks.ts","../../src/utils/key-generator.ts","../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.slice-blocks.ts","../../src/utils/util.get-text-block-text.ts"],"sourcesContent":["import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: BlockPath\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n return {\n path: [...block.path, 'children', {_key: block.node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {KeyedSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: unknown): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\nexport function getBlockKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const blockPathSegment = point.path.at(0)\n\n if (isKeyedSegment(blockPathSegment)) {\n return blockPathSegment._key\n }\n\n return undefined\n}\n\nexport function getChildKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const childPathSegment = point.path.at(2)\n\n if (isKeyedSegment(childPathSegment)) {\n return childPathSegment._key\n }\n\n return undefined\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {ChildPath} from '../types/paths'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n context,\n blockOffset,\n direction,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint: {path: ChildPath; offset: number} | undefined\n let skippedInlineObject = false\n\n for (const block of context.value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (direction === 'forward') {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n\n continue\n }\n\n if (!isSpan(context, child)) {\n skippedInlineObject = true\n continue\n }\n\n if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {\n if (skippedInlineObject) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n }\n break\n }\n\n if (offsetLeft > child.text.length) {\n offsetLeft -= child.text.length\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n\n offsetLeft -= child.text.length\n\n if (offsetLeft !== 0) {\n break\n }\n }\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n const spanKey = getChildKeyFromSelectionPoint(selectionPoint)\n\n if (!blockKey || !spanKey) {\n return undefined\n }\n\n for (const block of context.value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (child._key === spanKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import type {TypedObject} from '@sanity/types'\n\nexport function isTypedObject(object: unknown): object is TypedObject {\n return isRecord(object) && typeof object._type === 'string'\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {\n PortableTextBlock,\n PortableTextListBlock,\n PortableTextObject,\n PortableTextSpan,\n PortableTextTextBlock,\n TypedObject,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTypedObject} from './asserters'\n\nexport function parseBlocks({\n context,\n blocks,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n blocks: unknown\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): Array<PortableTextBlock> {\n if (!Array.isArray(blocks)) {\n return []\n }\n\n return blocks.flatMap((block) => {\n const parsedBlock = parseBlock({context, block, options})\n\n return parsedBlock ? [parsedBlock] : []\n })\n}\n\nexport function parseBlock({\n context,\n block,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n block: unknown\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): PortableTextBlock | undefined {\n return (\n parseTextBlock({block, context, options}) ??\n parseBlockObject({blockObject: block, context, options})\n )\n}\n\nexport function parseBlockObject({\n blockObject,\n context,\n options,\n}: {\n blockObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(blockObject)) {\n return undefined\n }\n\n const schemaType = context.schema.blockObjects.find(\n ({name}) => name === blockObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: blockObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function isListBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextListBlock {\n return (\n isTextBlock(context, block) &&\n block.level !== undefined &&\n block.listItem !== undefined\n )\n}\n\nexport function parseTextBlock({\n block,\n context,\n options,\n}: {\n block: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): PortableTextTextBlock | undefined {\n if (!isTypedObject(block)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(block)) {\n if (\n key === '_type' ||\n key === '_key' ||\n key === 'children' ||\n key === 'markDefs' ||\n key === 'style' ||\n key === 'listItem' ||\n key === 'level'\n ) {\n continue\n }\n\n if (options.validateFields) {\n if (context.schema.block.fields?.some((field) => field.name === key)) {\n customFields[key] = block[key]\n }\n } else {\n customFields[key] = block[key]\n }\n }\n\n if (block._type !== context.schema.block.name) {\n return undefined\n }\n\n const _key =\n typeof block._key === 'string' ? block._key : context.keyGenerator()\n\n const unparsedMarkDefs: Array<unknown> = Array.isArray(block.markDefs)\n ? block.markDefs\n : []\n const markDefKeyMap = new Map<string, string>()\n const markDefs = unparsedMarkDefs.flatMap((markDef) => {\n if (!isTypedObject(markDef)) {\n return []\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === markDef._type,\n )\n\n if (!schemaType) {\n return []\n }\n\n if (typeof markDef._key !== 'string') {\n // If the `markDef` doesn't have a `_key` then we don't know what spans\n // it belongs to and therefore we have to discard it.\n return []\n }\n\n const parsedAnnotation = parseObject({\n object: markDef,\n context: {\n schemaType,\n keyGenerator: context.keyGenerator,\n },\n options,\n })\n\n if (!parsedAnnotation) {\n return []\n }\n\n markDefKeyMap.set(markDef._key, parsedAnnotation._key)\n\n return [parsedAnnotation]\n })\n\n const unparsedChildren: Array<unknown> = Array.isArray(block.children)\n ? block.children\n : []\n\n const children = unparsedChildren\n .map(\n (child) =>\n parseSpan({span: child, context, markDefKeyMap, options}) ??\n parseInlineObject({inlineObject: child, context, options}),\n )\n .filter((child) => child !== undefined)\n const marks = children.flatMap((child) => child.marks ?? [])\n\n const parsedBlock: PortableTextTextBlock = {\n _type: context.schema.block.name,\n _key,\n children:\n children.length > 0\n ? children\n : [\n {\n _key: context.keyGenerator(),\n _type: context.schema.span.name,\n text: '',\n marks: [],\n },\n ],\n markDefs: options.removeUnusedMarkDefs\n ? markDefs.filter((markDef) => marks.includes(markDef._key))\n : markDefs,\n ...customFields,\n }\n\n if (\n typeof block.style === 'string' &&\n context.schema.styles.find((style) => style.name === block.style)\n ) {\n parsedBlock.style = block.style\n } else {\n const defaultStyle = context.schema.styles.at(0)?.name\n\n if (defaultStyle !== undefined) {\n parsedBlock.style = defaultStyle\n } else {\n console.error('Expected default style')\n }\n }\n\n if (\n typeof block.listItem === 'string' &&\n context.schema.lists.find((list) => list.name === block.listItem)\n ) {\n parsedBlock.listItem = block.listItem\n }\n\n if (typeof block.level === 'number') {\n parsedBlock.level = block.level\n }\n\n return parsedBlock\n}\n\nexport function parseSpan({\n span,\n context,\n markDefKeyMap,\n options,\n}: {\n span: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n markDefKeyMap: Map<string, string>\n options: {validateFields: boolean}\n}): PortableTextSpan | undefined {\n if (!isTypedObject(span)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(span)) {\n if (\n key !== '_type' &&\n key !== '_key' &&\n key !== 'text' &&\n key !== 'marks'\n ) {\n customFields[key] = span[key]\n }\n }\n\n // In reality, the span schema name is always 'span', but we only the check here anyway\n if (span._type !== context.schema.span.name || span._type !== 'span') {\n return undefined\n }\n\n const unparsedMarks: Array<unknown> = Array.isArray(span.marks)\n ? span.marks\n : []\n const marks = unparsedMarks.flatMap((mark) => {\n if (typeof mark !== 'string') {\n return []\n }\n\n const markDefKey = markDefKeyMap.get(mark)\n\n if (markDefKey !== undefined) {\n return [markDefKey]\n }\n\n if (\n context.schema.decorators.some((decorator) => decorator.name === mark)\n ) {\n return [mark]\n }\n\n return []\n })\n\n return {\n _type: 'span',\n _key: typeof span._key === 'string' ? span._key : context.keyGenerator(),\n text: typeof span.text === 'string' ? span.text : '',\n marks,\n ...(options.validateFields ? {} : customFields),\n }\n}\n\nexport function parseInlineObject({\n inlineObject,\n context,\n options,\n}: {\n inlineObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(inlineObject)) {\n return undefined\n }\n\n const schemaType = context.schema.inlineObjects.find(\n ({name}) => name === inlineObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: inlineObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function parseAnnotation({\n annotation,\n context,\n options,\n}: {\n annotation: TypedObject\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(annotation)) {\n return undefined\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === annotation._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: annotation,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nfunction parseObject({\n object,\n context,\n options,\n}: {\n object: TypedObject\n context: Pick<EditorContext, 'keyGenerator'> & {\n schemaType: EditorSchema['blockObjects'][0]\n }\n options: {validateFields: boolean}\n}): PortableTextObject {\n const {_type, _key, ...customFields} = object\n\n // Validates all props on the object and only takes those that match\n // the name of a field\n const values = options.validateFields\n ? context.schemaType.fields.reduce<Record<string, unknown>>(\n (fieldValues, field) => {\n const fieldValue = object[field.name]\n\n if (fieldValue !== undefined) {\n fieldValues[field.name] = fieldValue\n }\n\n return fieldValues\n },\n {},\n )\n : customFields\n\n return {\n _type: context.schemaType.name,\n _key:\n typeof object._key === 'string' ? object._key : context.keyGenerator(),\n ...values,\n }\n}\n","/**\n * @public\n */\nexport const defaultKeyGenerator = (): string => randomKey(12)\n\nconst getByteHexTable = (() => {\n let table: any[]\n return () => {\n if (table) {\n return table\n }\n\n table = []\n for (let i = 0; i < 256; ++i) {\n table[i] = (i + 0x100).toString(16).slice(1)\n }\n return table\n }\n})()\n\n// WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html\nfunction whatwgRNG(length = 16) {\n const rnds8 = new Uint8Array(length)\n crypto.getRandomValues(rnds8)\n return rnds8\n}\n\nfunction randomKey(length?: number): string {\n const table = getByteHexTable()\n return whatwgRNG(length)\n .reduce((str, n) => str + table[n], '')\n .slice(0, length)\n}\n","import type {EditorSelection, EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection, EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getSelectionStartPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.focus : selection.anchor\n ) as TEditorSelectionPoint\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {defaultKeyGenerator} from './key-generator'\nimport {parseBlock} from './parse-blocks'\nimport {getSelectionEndPoint} from './util.get-selection-end-point'\nimport {getSelectionStartPoint} from './util.get-selection-start-point'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\n/**\n * @public\n */\nexport function sliceBlocks({\n context,\n blocks,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n blocks: Array<PortableTextBlock>\n}): Array<PortableTextBlock> {\n const slice: Array<PortableTextBlock> = []\n\n if (!context.selection) {\n return slice\n }\n\n let startBlock: PortableTextBlock | undefined\n const middleBlocks: PortableTextBlock[] = []\n let endBlock: PortableTextBlock | undefined\n\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return slice\n }\n\n for (const block of blocks) {\n if (!isTextBlock(context, block)) {\n if (block._key === startBlockKey && block._key === endBlockKey) {\n startBlock = block\n break\n }\n }\n\n if (block._key === startBlockKey) {\n if (!isTextBlock(context, block)) {\n startBlock = block\n continue\n }\n\n if (startChildKey) {\n for (const child of block.children) {\n if (child._key === startChildKey) {\n if (isSpan(context, child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n startBlock = {\n ...block,\n children: [\n {\n ...child,\n text,\n },\n ],\n }\n } else {\n startBlock = {\n ...block,\n children: [child],\n }\n }\n\n if (block._key === endBlockKey && startChildKey === endChildKey) {\n break\n }\n continue\n }\n\n if (startBlock && isTextBlock(context, startBlock)) {\n if (\n endChildKey &&\n child._key === endChildKey &&\n isSpan(context, child)\n ) {\n startBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n startBlock.children.push(child)\n }\n\n if (\n block._key === endBlockKey &&\n endChildKey &&\n child._key === endChildKey\n ) {\n break\n }\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n startBlock = block\n\n if (startBlockKey === endBlockKey) {\n break\n }\n }\n\n if (block._key === endBlockKey) {\n if (!isTextBlock(context, block)) {\n endBlock = block\n break\n }\n\n if (endChildKey) {\n endBlock = {\n ...block,\n children: [],\n }\n\n for (const child of block.children) {\n if (endBlock && isTextBlock(context, endBlock)) {\n if (child._key === endChildKey && isSpan(context, child)) {\n endBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n\n break\n }\n\n endBlock.children.push(child)\n\n if (endChildKey && child._key === endChildKey) {\n break\n }\n }\n }\n\n break\n }\n\n endBlock = block\n\n break\n }\n\n if (startBlock) {\n middleBlocks.push(\n parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n }) ?? block,\n )\n }\n }\n\n const parsedStartBlock = startBlock\n ? parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block: startBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n : undefined\n\n const parsedEndBlock = endBlock\n ? parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block: endBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n : undefined\n\n return [\n ...(parsedStartBlock ? [parsedStartBlock] : []),\n ...middleBlocks,\n ...(parsedEndBlock ? [parsedEndBlock] : []),\n ]\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n"],"names":["getBlockStartPoint","context","block","isTextBlock","node","path","_key","children","offset","isKeyedSegment","segment","getBlockKeyFromSelectionPoint","point","blockPathSegment","at","getChildKeyFromSelectionPoint","childPathSegment","blockOffsetToSpanSelectionPoint","blockOffset","direction","offsetLeft","selectionPoint","skippedInlineObject","value","child","isSpan","text","length","spanSelectionPointToBlockOffset","blockKey","spanKey","isTypedObject","object","isRecord","_type","parseBlocks","blocks","options","Array","isArray","flatMap","parsedBlock","parseBlock","parseTextBlock","parseBlockObject","blockObject","schemaType","schema","blockObjects","find","name","parseObject","keyGenerator","isListBlock","level","undefined","listItem","customFields","key","Object","keys","validateFields","fields","some","field","unparsedMarkDefs","markDefs","markDefKeyMap","Map","markDef","annotations","parsedAnnotation","set","map","parseSpan","span","parseInlineObject","inlineObject","filter","marks","removeUnusedMarkDefs","includes","style","styles","defaultStyle","console","error","lists","list","mark","markDefKey","get","decorators","decorator","inlineObjects","parseAnnotation","annotation","values","reduce","fieldValues","fieldValue","defaultKeyGenerator","randomKey","getByteHexTable","table","i","toString","slice","whatwgRNG","rnds8","Uint8Array","crypto","getRandomValues","str","n","getSelectionEndPoint","selection","backward","anchor","focus","getSelectionStartPoint","sliceBlocks","startBlock","middleBlocks","endBlock","startPoint","endPoint","startBlockKey","startChildKey","endBlockKey","endChildKey","push","parsedStartBlock","parsedEndBlock","getTextBlockText","join"],"mappings":";;AASO,SAASA,mBAAmB;AAAA,EACjCC;AAAAA,EACAC;AAOF,GAAyB;AACvB,SAAIC,mBAAYF,SAASC,MAAME,IAAI,IAC1B;AAAA,IACLC,MAAM,CAAC,GAAGH,MAAMG,MAAM,YAAY;AAAA,MAACC,MAAMJ,MAAME,KAAKG,SAAS,CAAC,EAAED;AAAAA,IAAAA,CAAK;AAAA,IACrEE,QAAQ;AAAA,EAAA,IAIL;AAAA,IACLH,MAAMH,MAAMG;AAAAA,IACZG,QAAQ;AAAA,EAAA;AAEZ;ACzBO,SAASC,eAAeC,SAA2C;AACxE,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;ACJO,SAASC,8BAA8BC,OAA6B;AACzE,QAAMC,mBAAmBD,MAAMP,KAAKS,GAAG,CAAC;AAExC,MAAIL,eAAeI,gBAAgB;AACjC,WAAOA,iBAAiBP;AAI5B;AAEO,SAASS,8BAA8BH,OAA6B;AACzE,QAAMI,mBAAmBJ,MAAMP,KAAKS,GAAG,CAAC;AAExC,MAAIL,eAAeO,gBAAgB;AACjC,WAAOA,iBAAiBV;AAI5B;ACRO,SAASW,g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,GAC5C,GAAGT,cACH,GAAIU,iBAAiB,CAACA,cAAc,IAAI,CAAA,CAAG;AAE/C;ACzMO,SAASC,iBAAiBpI,OAA8B;AAC7D,SAAOA,MAAMK,SAASkE,IAAKjD,CAAAA,UAAUA,MAAME,QAAQ,EAAE,EAAE6G,KAAK,EAAE;AAChE;;;;;;;;;;;;;;;;;;;"}
@@ -3,7 +3,7 @@ import { ArrayDefinition, ArraySchemaType, BlockDecoratorDefinition, BlockListDe
3
3
  import { BaseRange, Descendant, Operation } from "slate";
4
4
  import * as xstate229 from "xstate";
5
5
  import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
6
- import * as react22 from "react";
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
9
  import * as _portabletext_schema5 from "@portabletext/schema";
@@ -219,7 +219,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
219
219
  componentDidUpdate(prevProps: PortableTextEditorProps): void;
220
220
  componentWillUnmount(): void;
221
221
  setEditable: (editable: EditableAPI) => void;
222
- render(): react22.JSX.Element;
222
+ render(): react20.JSX.Element;
223
223
  /**
224
224
  * @deprecated
225
225
  * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
@@ -614,7 +614,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
614
614
  * ```
615
615
  * @group Components
616
616
  */
617
- declare const PortableTextEditable: react22.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react22.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
617
+ declare const PortableTextEditable: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
618
618
  type DecoratedRange = BaseRange & {
619
619
  rangeDecoration: RangeDecoration;
620
620
  };
@@ -1532,7 +1532,7 @@ declare const editorMachine: xstate229.StateMachine<{
1532
1532
  initialValue?: Array<PortableTextBlock>;
1533
1533
  }, xstate229.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
1534
1534
  type: "blurred";
1535
- event: react22.FocusEvent<HTMLDivElement, Element>;
1535
+ event: react20.FocusEvent<HTMLDivElement, Element>;
1536
1536
  } | {
1537
1537
  type: "done loading";
1538
1538
  } | {
@@ -1544,7 +1544,7 @@ declare const editorMachine: xstate229.StateMachine<{
1544
1544
  data: unknown;
1545
1545
  } | {
1546
1546
  type: "focused";
1547
- event: react22.FocusEvent<HTMLDivElement, Element>;
1547
+ event: react20.FocusEvent<HTMLDivElement, Element>;
1548
1548
  } | {
1549
1549
  type: "invalid value";
1550
1550
  resolution: InvalidValueResolution | null;
@@ -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
  } | {
@@ -2205,7 +2205,7 @@ declare const editorMachine: xstate229.StateMachine<{
2205
2205
  editor: PortableTextSlateEditor;
2206
2206
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2207
2207
  type: "blurred";
2208
- event: react22.FocusEvent<HTMLDivElement, Element>;
2208
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2209
2209
  } | {
2210
2210
  type: "done loading";
2211
2211
  } | {
@@ -2217,7 +2217,7 @@ declare const editorMachine: xstate229.StateMachine<{
2217
2217
  data: unknown;
2218
2218
  } | {
2219
2219
  type: "focused";
2220
- event: react22.FocusEvent<HTMLDivElement, Element>;
2220
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2221
2221
  } | {
2222
2222
  type: "invalid value";
2223
2223
  resolution: InvalidValueResolution | null;
@@ -3078,7 +3078,7 @@ declare const editorMachine: xstate229.StateMachine<{
3078
3078
  editor: PortableTextSlateEditor;
3079
3079
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
3080
3080
  type: "blurred";
3081
- event: react22.FocusEvent<HTMLDivElement, Element>;
3081
+ event: react20.FocusEvent<HTMLDivElement, Element>;
3082
3082
  } | {
3083
3083
  type: "done loading";
3084
3084
  } | {
@@ -3090,7 +3090,7 @@ declare const editorMachine: xstate229.StateMachine<{
3090
3090
  data: unknown;
3091
3091
  } | {
3092
3092
  type: "focused";
3093
- event: react22.FocusEvent<HTMLDivElement, Element>;
3093
+ event: react20.FocusEvent<HTMLDivElement, Element>;
3094
3094
  } | {
3095
3095
  type: "invalid value";
3096
3096
  resolution: InvalidValueResolution | null;
@@ -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
  */
@@ -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
  } | {
@@ -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,QAAQC,UAAUG,KAAK,GACpEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAEhDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAAC;AAAA,MAACC,MAAMX;AAAAA,IAAAA,CAAI;AAAA,EAAA,IAAKM;AACrD,GCbaM,oBAERf,CAAAA,aAAa;AAChB,QAAMgB,aAAajB,cAAcC,QAAQ;AAEzC,SAAOgB,cAAcC,YAAYjB,SAASC,SAASe,WAAWN,IAAI,IAC9D;AAAA,IAACA,MAAMM,WAAWN;AAAAA,IAAMG,MAAMG,WAAWH;AAAAA,EAAAA,IACzCJ;AACN,GCRaS,gBAMRlB,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMc,aAAaD,kBAAkBf,QAAQ;AAE7C,MAAI,CAACgB;AACH;AAGF,QAAMb,MAAMgB,8BAA8BnB,SAASC,QAAQC,UAAUG,KAAK,GAEpEK,OAAOP,MACTa,WAAWN,KAAKU,SAASC,KAAMC,UAASA,KAAKR,SAASX,GAAG,IACzDM;AAEJ,SAAOC,QAAQP,MACX;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAA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AA,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":";;;AAQO,MAAMA,gBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,8BAA8BJ,SAASC,QAAQC,UAAUG,KAAK,GACpEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAEhDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAAC;AAAA,MAACC,MAAMX;AAAAA,IAAAA,CAAI;AAAA,EAAA,IAAKM;AACrD,GCbaM,oBAERf,CAAAA,aAAa;AAChB,QAAMgB,aAAajB,cAAcC,QAAQ;AAEzC,SAAOgB,cAAcC,YAAYjB,SAASC,SAASe,WAAWN,IAAI,IAC9D;AAAA,IAACA,MAAMM,WAAWN;AAAAA,IAAMG,MAAMG,WAAWH;AAAAA,EAAAA,IACzCJ;AACN,GCRaS,gBAMRlB,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMc,aAAaD,kBAAkBf,QAAQ;AAE7C,MAAI,CAACgB;AACH;AAGF,QAAMb,MAAMgB,8BAA8BnB,SAASC,QAAQC,UAAUG,KAAK,GAEpEK,OAAOP,MACTa,WAAWN,KAAKU,SA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AM,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,5 +1,4 @@
1
1
  import { isTextBlock, isSpan } from "@portabletext/schema";
2
- import getRandomValues from "get-random-values-esm";
3
2
  function getBlockStartPoint({
4
3
  context,
5
4
  block
@@ -318,7 +317,7 @@ const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__
318
317
  })();
319
318
  function whatwgRNG(length = 16) {
320
319
  const rnds8 = new Uint8Array(length);
321
- return getRandomValues(rnds8), rnds8;
320
+ return crypto.getRandomValues(rnds8), rnds8;
322
321
  }
323
322
  function randomKey(length) {
324
323
  const table = getByteHexTable();