@portabletext/editor 1.49.2 → 1.49.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
  2. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +40 -230
  4. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +201 -0
  6. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -0
  7. package/lib/_chunks-cjs/use-editor.cjs +28 -0
  8. package/lib/_chunks-cjs/use-editor.cjs.map +1 -0
  9. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +79 -0
  10. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -0
  11. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +34 -0
  12. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -0
  13. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +6 -78
  14. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  15. package/lib/_chunks-cjs/util.slice-blocks.cjs +0 -31
  16. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  17. package/lib/_chunks-es/selector.get-text-before.js +1 -1
  18. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +13 -201
  19. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  20. package/lib/_chunks-es/selector.is-selection-expanded.js +203 -0
  21. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -0
  22. package/lib/_chunks-es/use-editor.js +25 -0
  23. package/lib/_chunks-es/use-editor.js.map +1 -0
  24. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +80 -0
  25. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -0
  26. package/lib/_chunks-es/util.is-equal-selection-points.js +35 -0
  27. package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -0
  28. package/lib/_chunks-es/util.selection-point-to-block-offset.js +6 -77
  29. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  30. package/lib/_chunks-es/util.slice-blocks.js +0 -31
  31. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  32. package/lib/index.cjs +8998 -290
  33. package/lib/index.cjs.map +1 -1
  34. package/lib/index.d.cts +2 -2
  35. package/lib/index.d.ts +2 -2
  36. package/lib/index.js +8945 -222
  37. package/lib/index.js.map +1 -1
  38. package/lib/plugins/index.cjs +23 -23
  39. package/lib/plugins/index.cjs.map +1 -1
  40. package/lib/plugins/index.js +3 -3
  41. package/lib/plugins/index.js.map +1 -1
  42. package/lib/selectors/index.cjs +22 -22
  43. package/lib/selectors/index.cjs.map +1 -1
  44. package/lib/selectors/index.js +4 -3
  45. package/lib/selectors/index.js.map +1 -1
  46. package/lib/utils/index.cjs +10 -10
  47. package/lib/utils/index.cjs.map +1 -1
  48. package/lib/utils/index.js +6 -4
  49. package/lib/utils/index.js.map +1 -1
  50. package/package.json +13 -13
  51. package/src/editor/create-editor.ts +2 -58
  52. package/src/editor/editor-context.tsx +1 -1
  53. package/src/editor/editor-provider.tsx +4 -31
  54. package/src/editor/editor-selector.ts +2 -1
  55. package/src/editor/use-editor.ts +27 -0
  56. package/src/editor-event-listener.tsx +1 -1
  57. package/src/editor.ts +57 -0
  58. package/src/index.ts +9 -9
  59. package/src/internal-utils/text-selection.test.ts +11 -0
  60. package/src/plugins/plugin.behavior.tsx +1 -1
  61. package/src/plugins/plugin.decorator-shortcut.ts +2 -2
  62. package/src/plugins/plugin.editor-ref.tsx +2 -2
  63. package/src/plugins/plugin.event-listener.tsx +1 -1
  64. package/src/plugins/plugin.markdown.tsx +1 -1
  65. package/lib/_chunks-cjs/editor-provider.cjs +0 -8756
  66. package/lib/_chunks-cjs/editor-provider.cjs.map +0 -1
  67. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +0 -11
  68. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +0 -1
  69. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +0 -6
  70. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +0 -1
  71. package/lib/_chunks-es/editor-provider.js +0 -8782
  72. package/lib/_chunks-es/editor-provider.js.map +0 -1
  73. package/lib/_chunks-es/selector.get-focus-inline-object.js +0 -13
  74. package/lib/_chunks-es/selector.get-focus-inline-object.js.map +0 -1
  75. package/lib/_chunks-es/util.is-selection-collapsed.js +0 -7
  76. package/lib/_chunks-es/util.is-selection-collapsed.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/plugins/plugin.behavior.tsx","../../src/internal-utils/get-text-to-emphasize.ts","../../src/behaviors/behavior.decorator-pair.ts","../../src/plugins/plugin.decorator-shortcut.ts","../../src/plugins/plugin.editor-ref.tsx","../../src/plugins/plugin.event-listener.tsx","../../src/behaviors/behavior.markdown.ts","../../src/plugins/plugin.markdown.tsx","../../src/plugins/plugin.one-line.tsx"],"sourcesContent":["import {useEffect} from 'react'\nimport type {Behavior} from '../behaviors'\nimport {useEditor} from '../editor/editor-provider'\n\n/**\n * @beta\n */\nexport function BehaviorPlugin(props: {behaviors: Array<Behavior>}) {\n const editor = useEditor()\n\n useEffect(() => {\n const unregisterBehaviors = props.behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n unregisterBehaviors.forEach((unregister) => unregister())\n }\n }, [editor, props.behaviors])\n\n return null\n}\n","export function createPairRegex(char: string, amount: number) {\n // Negative lookbehind: Ensures that the matched sequence is not preceded by the same character\n const prePrefix = `(?<!\\\\${char})`\n\n // Repeats the character `amount` times\n const prefix = `\\\\${char}`.repeat(Math.max(amount, 1))\n\n // Negative lookahead: Ensures that the opening pair (**, *, etc.) is not followed by a space\n const postPrefix = `(?!\\\\s)`\n\n // Captures the content inside the pair\n const content = `([^${char}\\\\n]+?)`\n\n // Negative lookbehind: Ensures that the content is not followed by a space\n const preSuffix = `(?<!\\\\s)`\n\n // Repeats the character `amount` times\n const suffix = `\\\\${char}`.repeat(Math.max(amount, 1))\n\n // Negative lookahead: Ensures that the matched sequence is not followed by the same character\n const postSuffix = `(?!\\\\${char})`\n\n return `${prePrefix}${prefix}${postPrefix}${content}${preSuffix}${suffix}${postSuffix}`\n}\n\nconst italicRegex = new RegExp(\n `(${createPairRegex('*', 1)}|${createPairRegex('_', 1)})$`,\n)\n\nconst boldRegex = new RegExp(\n `(${createPairRegex('*', 2)}|${createPairRegex('_', 2)})$`,\n)\n\nexport function getTextToItalic(text: string) {\n return text.match(italicRegex)?.at(0)\n}\n\nexport function getTextToBold(text: string) {\n return text.match(boldRegex)?.at(0)\n}\n","import type {EditorSchema} from '../editor/editor-schema'\nimport {createPairRegex} from '../internal-utils/get-text-to-emphasize'\nimport * as selectors from '../selectors'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {effect, execute} from './behavior.types.action'\nimport {defineBehavior} from './behavior.types.behavior'\n\nexport function createDecoratorPairBehavior(config: {\n decorator: ({schema}: {schema: EditorSchema}) => string | undefined\n pair: {char: string; amount: number}\n onDecorate: (offset: BlockOffset) => void\n}) {\n if (config.pair.amount < 1) {\n console.warn(\n `The amount of characters in the pair should be greater than 0`,\n )\n }\n\n const pairRegex = createPairRegex(config.pair.char, config.pair.amount)\n const regEx = new RegExp(`(${pairRegex})$`)\n\n return defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n if (config.pair.amount < 1) {\n return false\n }\n\n const decorator = config.decorator({schema: snapshot.context.schema})\n\n if (decorator === undefined) {\n return false\n }\n\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const selectionStartPoint = selectors.getSelectionStartPoint(snapshot)\n const selectionStartOffset = selectionStartPoint\n ? utils.spanSelectionPointToBlockOffset({\n context: {\n schema: snapshot.context.schema,\n value: snapshot.context.value,\n },\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartOffset) {\n return false\n }\n\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const newText = `${textBefore}${event.text}`\n const textToDecorate = newText.match(regEx)?.at(0)\n\n if (textToDecorate === undefined) {\n return false\n }\n\n const prefixOffsets = {\n anchor: {\n path: focusTextBlock.path,\n // Example: \"foo **bar**\".length - \"**bar**\".length = 4\n offset: newText.length - textToDecorate.length,\n },\n focus: {\n path: focusTextBlock.path,\n // Example: \"foo **bar**\".length - \"**bar**\".length + \"*\".length * 2 = 6\n offset:\n newText.length -\n textToDecorate.length +\n config.pair.char.length * config.pair.amount,\n },\n }\n\n const suffixOffsets = {\n anchor: {\n path: focusTextBlock.path,\n // Example: \"foo **bar*|\" (10) + \"*\".length - 2 = 9\n offset:\n selectionStartOffset.offset +\n event.text.length -\n config.pair.char.length * config.pair.amount,\n },\n focus: {\n path: focusTextBlock.path,\n // Example: \"foo **bar*|\" (10) + \"*\".length = 11\n offset: selectionStartOffset.offset + event.text.length,\n },\n }\n\n // If the prefix is more than one character, then we need to check if\n // there is an inline object inside it\n if (prefixOffsets.focus.offset - prefixOffsets.anchor.offset > 1) {\n const prefixSelection = utils.blockOffsetsToSelection({\n context: snapshot.context,\n offsets: prefixOffsets,\n })\n const inlineObjectBeforePrefixFocus = selectors.getPreviousInlineObject(\n {\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: prefixSelection\n ? {\n anchor: prefixSelection.focus,\n focus: prefixSelection.focus,\n }\n : null,\n },\n },\n )\n const inlineObjectBeforePrefixFocusOffset =\n inlineObjectBeforePrefixFocus\n ? utils.childSelectionPointToBlockOffset({\n context: {\n schema: snapshot.context.schema,\n value: snapshot.context.value,\n },\n selectionPoint: {\n path: inlineObjectBeforePrefixFocus.path,\n offset: 0,\n },\n })\n : undefined\n\n if (\n inlineObjectBeforePrefixFocusOffset &&\n inlineObjectBeforePrefixFocusOffset.offset >\n prefixOffsets.anchor.offset &&\n inlineObjectBeforePrefixFocusOffset.offset <\n prefixOffsets.focus.offset\n ) {\n return false\n }\n }\n\n // If the suffix is more than one character, then we need to check if\n // there is an inline object inside it\n if (suffixOffsets.focus.offset - suffixOffsets.anchor.offset > 1) {\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const previousInlineObjectOffset = previousInlineObject\n ? utils.childSelectionPointToBlockOffset({\n context: {\n schema: snapshot.context.schema,\n value: snapshot.context.value,\n },\n selectionPoint: {\n path: previousInlineObject.path,\n offset: 0,\n },\n })\n : undefined\n\n if (\n previousInlineObjectOffset &&\n previousInlineObjectOffset.offset > suffixOffsets.anchor.offset &&\n previousInlineObjectOffset.offset < suffixOffsets.focus.offset\n ) {\n return false\n }\n }\n\n return {\n prefixOffsets,\n suffixOffsets,\n decorator,\n }\n },\n actions: [\n // Insert the text as usual in its own undo step\n ({event}) => [execute(event)],\n (_, {prefixOffsets, suffixOffsets, decorator}) => [\n // Decorate the text between the prefix and suffix\n execute({\n type: 'decorator.add',\n decorator,\n at: {\n anchor: prefixOffsets.focus,\n focus: suffixOffsets.anchor,\n },\n }),\n // Delete the suffix\n execute({\n type: 'delete.text',\n at: suffixOffsets,\n }),\n // Delete the prefix\n execute({\n type: 'delete.text',\n at: prefixOffsets,\n }),\n // Toggle the decorator off so the next inserted text isn't emphasized\n execute({\n type: 'decorator.remove',\n decorator,\n }),\n effect(() => {\n config.onDecorate({\n ...suffixOffsets.anchor,\n offset:\n suffixOffsets.anchor.offset -\n (prefixOffsets.focus.offset - prefixOffsets.anchor.offset),\n })\n }),\n ],\n ],\n })\n}\n","import {useActorRef} from '@xstate/react'\nimport {isEqual} from 'lodash'\nimport {\n assign,\n fromCallback,\n setup,\n type AnyEventObject,\n type CallbackLogicFunction,\n} from 'xstate'\nimport {createDecoratorPairBehavior} from '../behaviors/behavior.decorator-pair'\nimport {effect, execute, forward} from '../behaviors/behavior.types.action'\nimport {defineBehavior} from '../behaviors/behavior.types.behavior'\nimport type {Editor} from '../editor/create-editor'\nimport {useEditor} from '../editor/editor-provider'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\n\n/**\n * @beta\n * @deprecated Install the plugin from `@portabletext/plugin-character-pair-decorator`\n */\nexport function DecoratorShortcutPlugin(config: {\n decorator: ({schema}: {schema: EditorSchema}) => string | undefined\n pair: {char: string; amount: number}\n}) {\n const editor = useEditor()\n\n useActorRef(decoratorPairMachine, {\n input: {\n editor,\n decorator: config.decorator,\n pair: config.pair,\n },\n })\n\n return null\n}\n\ntype MarkdownEmphasisEvent =\n | {\n type: 'emphasis.add'\n blockOffset: BlockOffset\n }\n | {\n type: 'selection'\n blockOffsets?: {\n anchor: BlockOffset\n focus: BlockOffset\n }\n }\n | {\n type: 'delete.backward'\n }\n\nconst emphasisListener: CallbackLogicFunction<\n AnyEventObject,\n MarkdownEmphasisEvent,\n {\n decorator: ({schema}: {schema: EditorSchema}) => string | undefined\n editor: Editor\n pair: {char: string; amount: number}\n }\n> = ({sendBack, input}) => {\n const unregister = input.editor.registerBehavior({\n behavior: createDecoratorPairBehavior({\n decorator: input.decorator,\n pair: input.pair,\n onDecorate: (offset) => {\n sendBack({type: 'emphasis.add', blockOffset: offset})\n },\n }),\n })\n\n return unregister\n}\n\nconst selectionListenerCallback: CallbackLogicFunction<\n AnyEventObject,\n MarkdownEmphasisEvent,\n {editor: Editor}\n> = ({sendBack, input}) => {\n const unregister = input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'select',\n guard: ({snapshot, event}) => {\n if (!event.at) {\n return {blockOffsets: undefined}\n }\n\n const anchor = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: event.at.anchor,\n })\n const focus = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: event.at.focus,\n })\n\n if (!anchor || !focus) {\n return {blockOffsets: undefined}\n }\n\n return {\n blockOffsets: {\n anchor,\n focus,\n },\n }\n },\n actions: [\n ({event}, {blockOffsets}) => [\n {\n type: 'effect',\n effect: () => {\n sendBack({type: 'selection', blockOffsets})\n },\n },\n forward(event),\n ],\n ],\n }),\n })\n\n return unregister\n}\n\nconst deleteBackwardListenerCallback: CallbackLogicFunction<\n AnyEventObject,\n MarkdownEmphasisEvent,\n {editor: Editor}\n> = ({sendBack, input}) => {\n const unregister = input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'delete.backward',\n actions: [\n () => [\n execute({\n type: 'history.undo',\n }),\n effect(() => {\n sendBack({type: 'delete.backward'})\n }),\n ],\n ],\n }),\n })\n\n return unregister\n}\n\nconst decoratorPairMachine = setup({\n types: {\n context: {} as {\n decorator: ({schema}: {schema: EditorSchema}) => string | undefined\n editor: Editor\n offsetAfterEmphasis?: BlockOffset\n pair: {char: string; amount: number}\n },\n input: {} as {\n decorator: ({schema}: {schema: EditorSchema}) => string | undefined\n editor: Editor\n pair: {char: string; amount: number}\n },\n events: {} as MarkdownEmphasisEvent,\n },\n actors: {\n 'emphasis listener': fromCallback(emphasisListener),\n 'delete.backward listener': fromCallback(deleteBackwardListenerCallback),\n 'selection listener': fromCallback(selectionListenerCallback),\n },\n}).createMachine({\n id: 'decorator pair',\n context: ({input}) => ({\n decorator: input.decorator,\n editor: input.editor,\n pair: input.pair,\n }),\n initial: 'idle',\n states: {\n 'idle': {\n invoke: [\n {\n src: 'emphasis listener',\n input: ({context}) => ({\n decorator: context.decorator,\n editor: context.editor,\n pair: context.pair,\n }),\n },\n ],\n on: {\n 'emphasis.add': {\n target: 'emphasis added',\n actions: assign({\n offsetAfterEmphasis: ({event}) => event.blockOffset,\n }),\n },\n },\n },\n 'emphasis added': {\n exit: [\n assign({\n offsetAfterEmphasis: undefined,\n }),\n ],\n invoke: [\n {\n src: 'selection listener',\n input: ({context}) => ({editor: context.editor}),\n },\n {\n src: 'delete.backward listener',\n input: ({context}) => ({editor: context.editor}),\n },\n ],\n on: {\n 'selection': {\n target: 'idle',\n guard: ({context, event}) => {\n const selectionChanged = !isEqual(\n {\n anchor: context.offsetAfterEmphasis,\n focus: context.offsetAfterEmphasis,\n },\n event.blockOffsets,\n )\n\n return selectionChanged\n },\n },\n 'delete.backward': {\n target: 'idle',\n },\n },\n },\n },\n})\n","import React from 'react'\nimport type {Editor} from '../editor/create-editor'\nimport {useEditor} from '../editor/editor-provider'\n\n/**\n * @beta\n */\nexport const EditorRefPlugin = React.forwardRef<Editor | null>((_, ref) => {\n const editor = useEditor()\n\n const portableTextEditorRef = React.useRef(editor)\n\n React.useImperativeHandle(ref, () => portableTextEditorRef.current, [])\n\n return null\n})\nEditorRefPlugin.displayName = 'EditorRefPlugin'\n","import {useEffect} from 'react'\nimport {useEffectEvent} from 'use-effect-event'\nimport type {EditorEmittedEvent} from '../editor/editor-machine'\nimport {useEditor} from '../editor/editor-provider'\n\n/**\n * @public\n * Listen for events emitted by the editor. Must be used inside `EditorProvider`. Events available include:\n * - 'blurred'\n * - 'done loading'\n * - 'editable'\n * - 'error'\n * - 'focused'\n * - 'invalid value'\n * - 'loading'\n * - 'mutation'\n * - 'patch'\n * - 'read only'\n * - 'ready'\n * - 'selection'\n * - 'value changed'\n *\n * @example\n * Listen and log events.\n * ```tsx\n * import {EditorProvider} from '@portabletext/editor'\n * import {EventListenerPlugin} from '@portabletext/editor/plugins'\n *\n * function MyComponent() {\n * return (\n * <EditorProvider>\n * <EventListenerPlugin\n * on={(event) => {\n * console.log(event)\n * }\n * } />\n * { ... }\n * </EditorProvider>\n * )\n * }\n * ```\n * @example\n * Handle events when there is a mutation.\n * ```tsx\n * <EventListenerPlugin\n * on={(event) => {\n * if (event.type === 'mutation') {\n * console.log('Value changed:', event.snapshot)\n * }\n * }}\n * />\n * ```\n * @group Components\n */\nexport function EventListenerPlugin(props: {\n on: (event: EditorEmittedEvent) => void\n}) {\n const editor = useEditor()\n const on = useEffectEvent(props.on)\n\n useEffect(() => {\n const subscription = editor.on('*', on)\n\n return () => {\n subscription.unsubscribe()\n }\n }, [editor])\n\n return null\n}\n","import type {EditorSchema} from '../editor/editor-schema'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport * as selectors from '../selectors'\nimport {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\nimport {getTextBlockText} from '../utils/util.get-text-block-text'\nimport {execute} from './behavior.types.action'\nimport {defineBehavior} from './behavior.types.behavior'\n\nexport type MarkdownBehaviorsConfig = {\n horizontalRuleObject?: (context: {\n schema: EditorSchema\n }) => {name: string; value?: {[prop: string]: unknown}} | undefined\n defaultStyle?: (context: {schema: EditorSchema}) => string | undefined\n headingStyle?: (context: {\n schema: EditorSchema\n level: number\n }) => string | undefined\n blockquoteStyle?: (context: {schema: EditorSchema}) => string | undefined\n unorderedListStyle?: (context: {schema: EditorSchema}) => string | undefined\n orderedListStyle?: (context: {schema: EditorSchema}) => string | undefined\n}\n\nexport function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {\n const automaticBlockquoteOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const blockOffset = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: snapshot.context.selection?.focus.offset ?? 0,\n },\n })\n\n if (previousInlineObject || !blockOffset) {\n return false\n }\n\n const blockText = getTextBlockText(focusTextBlock.node)\n const caretAtTheEndOfQuote = blockOffset.offset === 1\n const looksLikeMarkdownQuote = /^>/.test(blockText)\n const blockquoteStyle = config.blockquoteStyle?.(snapshot.context)\n\n if (\n caretAtTheEndOfQuote &&\n looksLikeMarkdownQuote &&\n blockquoteStyle !== undefined\n ) {\n return {focusTextBlock, style: blockquoteStyle}\n }\n\n return false\n },\n actions: [\n () => [\n execute({\n type: 'insert.text',\n text: ' ',\n }),\n ],\n (_, {focusTextBlock, style}) => [\n execute({\n type: 'block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n }),\n execute({\n type: 'block.set',\n props: {style},\n at: focusTextBlock.path,\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: focusTextBlock.path,\n offset: 0,\n },\n focus: {\n path: focusTextBlock.path,\n offset: 2,\n },\n },\n }),\n ],\n ],\n })\n const automaticHr = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const hrCharacter =\n event.text === '-'\n ? '-'\n : event.text === '*'\n ? '*'\n : event.text === '_'\n ? '_'\n : undefined\n\n if (hrCharacter === undefined) {\n return false\n }\n\n const hrObject = config.horizontalRuleObject?.(snapshot.context)\n const focusBlock = selectors.getFocusTextBlock(snapshot)\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n\n if (!hrObject || !focusBlock || !selectionCollapsed) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const hrBlockOffsets = {\n anchor: {\n path: focusBlock.path,\n offset: 0,\n },\n focus: {\n path: focusBlock.path,\n offset: 3,\n },\n }\n\n if (\n !previousInlineObject &&\n textBefore === `${hrCharacter}${hrCharacter}`\n ) {\n return {hrObject, focusBlock, hrCharacter, hrBlockOffsets}\n }\n\n return false\n },\n actions: [\n (_, {hrCharacter}) => [\n execute({\n type: 'insert.text',\n text: hrCharacter,\n }),\n ],\n (_, {hrObject, hrBlockOffsets}) => [\n execute({\n type: 'insert.block',\n placement: 'before',\n block: {\n _type: hrObject.name,\n ...(hrObject.value ?? {}),\n },\n }),\n execute({\n type: 'delete.text',\n at: hrBlockOffsets,\n }),\n ],\n ],\n })\n const automaticHrOnPaste = defineBehavior({\n on: 'clipboard.paste',\n guard: ({snapshot, event}) => {\n const text = event.originEvent.dataTransfer.getData('text/plain')\n const hrRegExp = /^(---)$|(___)$|(\\*\\*\\*)$/\n const hrCharacters = text.match(hrRegExp)?.[0]\n const hrObject = config.horizontalRuleObject?.(snapshot.context)\n const focusBlock = selectors.getFocusBlock(snapshot)\n\n if (!hrCharacters || !hrObject || !focusBlock) {\n return false\n }\n\n return {hrCharacters, hrObject, focusBlock}\n },\n actions: [\n (_, {hrCharacters}) => [\n execute({\n type: 'insert.text',\n text: hrCharacters,\n }),\n ],\n ({snapshot}, {hrObject, focusBlock}) =>\n isTextBlock(snapshot.context, focusBlock.node)\n ? [\n execute({\n type: 'insert.block',\n block: {\n _type: snapshot.context.schema.block.name,\n children: focusBlock.node.children,\n },\n placement: 'after',\n }),\n execute({\n type: 'insert.block',\n block: {\n _type: hrObject.name,\n ...(hrObject.value ?? {}),\n },\n placement: 'after',\n }),\n execute({\n type: 'delete.block',\n at: focusBlock.path,\n }),\n ]\n : [\n execute({\n type: 'insert.block',\n block: {\n _type: hrObject.name,\n ...(hrObject.value ?? {}),\n },\n placement: 'after',\n }),\n ],\n ],\n })\n const automaticHeadingOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const blockOffset = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: snapshot.context.selection?.focus.offset ?? 0,\n },\n })\n\n if (!blockOffset) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const blockText = getTextBlockText(focusTextBlock.node)\n const markdownHeadingSearch = /^#+/.exec(blockText)\n const level = markdownHeadingSearch\n ? markdownHeadingSearch[0].length\n : undefined\n const caretAtTheEndOfHeading = blockOffset.offset === level\n\n if (previousInlineObject || !caretAtTheEndOfHeading) {\n return false\n }\n\n const style =\n level !== undefined\n ? config.headingStyle?.({schema: snapshot.context.schema, level})\n : undefined\n\n if (level !== undefined && style !== undefined) {\n return {\n focusTextBlock,\n style: style,\n level,\n }\n }\n\n return false\n },\n actions: [\n ({event}) => [execute(event)],\n (_, {focusTextBlock, style, level}) => [\n execute({\n type: 'block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n }),\n execute({\n type: 'block.set',\n props: {style},\n at: focusTextBlock.path,\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: focusTextBlock.path,\n offset: 0,\n },\n focus: {\n path: focusTextBlock.path,\n offset: level + 1,\n },\n },\n }),\n ],\n ],\n })\n const clearStyleOnBackspace = defineBehavior({\n on: 'delete.backward',\n guard: ({snapshot}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const atTheBeginningOfBLock =\n focusTextBlock.node.children[0]._key === focusSpan.node._key &&\n snapshot.context.selection?.focus.offset === 0\n\n const defaultStyle = config.defaultStyle?.(snapshot.context)\n\n if (\n atTheBeginningOfBLock &&\n defaultStyle &&\n focusTextBlock.node.style !== defaultStyle\n ) {\n return {defaultStyle, focusTextBlock}\n }\n\n return false\n },\n actions: [\n (_, {defaultStyle, focusTextBlock}) => [\n execute({\n type: 'block.set',\n props: {style: defaultStyle},\n at: focusTextBlock.path,\n }),\n ],\n ],\n })\n const automaticListOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const blockOffset = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: snapshot.context.selection?.focus.offset ?? 0,\n },\n })\n\n if (previousInlineObject || !blockOffset) {\n return false\n }\n\n const blockText = getTextBlockText(focusTextBlock.node)\n const defaultStyle = config.defaultStyle?.(snapshot.context)\n const looksLikeUnorderedList = /^(-|\\*)/.test(blockText)\n const unorderedListStyle = config.unorderedListStyle?.(snapshot.context)\n const caretAtTheEndOfUnorderedList = blockOffset.offset === 1\n\n if (\n defaultStyle &&\n caretAtTheEndOfUnorderedList &&\n looksLikeUnorderedList &&\n unorderedListStyle !== undefined\n ) {\n return {\n focusTextBlock,\n listItem: unorderedListStyle,\n listItemLength: 1,\n style: defaultStyle,\n }\n }\n\n const looksLikeOrderedList = /^1\\./.test(blockText)\n const orderedListStyle = config.orderedListStyle?.(snapshot.context)\n const caretAtTheEndOfOrderedList = blockOffset.offset === 2\n\n if (\n defaultStyle &&\n caretAtTheEndOfOrderedList &&\n looksLikeOrderedList &&\n orderedListStyle !== undefined\n ) {\n return {\n focusTextBlock,\n listItem: orderedListStyle,\n listItemLength: 2,\n style: defaultStyle,\n }\n }\n\n return false\n },\n actions: [\n ({event}) => [execute(event)],\n (_, {focusTextBlock, style, listItem, listItemLength}) => [\n execute({\n type: 'block.set',\n props: {\n listItem,\n level: 1,\n style,\n },\n at: focusTextBlock.path,\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: focusTextBlock.path,\n offset: 0,\n },\n focus: {\n path: focusTextBlock.path,\n offset: listItemLength + 1,\n },\n },\n }),\n ],\n ],\n })\n\n const markdownBehaviors = [\n automaticBlockquoteOnSpace,\n automaticHeadingOnSpace,\n automaticHr,\n automaticHrOnPaste,\n clearStyleOnBackspace,\n automaticListOnSpace,\n ]\n\n return markdownBehaviors\n}\n","import {useEffect} from 'react'\nimport {\n createMarkdownBehaviors,\n type MarkdownBehaviorsConfig,\n} from '../behaviors/behavior.markdown'\nimport {useEditor} from '../editor/editor-provider'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport {DecoratorShortcutPlugin} from './plugin.decorator-shortcut'\n\n/**\n * @beta\n */\nexport type MarkdownPluginConfig = MarkdownBehaviorsConfig & {\n boldDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined\n codeDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined\n italicDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined\n strikeThroughDecorator?: ({\n schema,\n }: {\n schema: EditorSchema\n }) => string | undefined\n}\n\n/**\n * @beta\n * Add markdown behaviors for common markdown actions such as converting ### to headings, --- to HRs, and more.\n *\n * @example\n * Configure the bundled markdown behaviors\n * ```ts\n * import {EditorProvider} from '@portabletext/editor'\n * import {MarkdownPlugin} from '@portabletext/editor/plugins'\n *\n * function App() {\n * return (\n * <EditorProvider>\n * <MarkdownPlugin\n * config={{\n * boldDecorator: ({schema}) =>\n * schema.decorators.find((decorator) => decorator.value === 'strong')?.value,\n * codeDecorator: ({schema}) =>\n * schema.decorators.find((decorator) => decorator.value === 'code')?.value,\n * italicDecorator: ({schema}) =>\n * schema.decorators.find((decorator) => decorator.value === 'em')?.value,\n * strikeThroughDecorator: ({schema}) =>\n * schema.decorators.find((decorator) => decorator.value === 'strike-through')?.value,\n * horizontalRuleObject: ({schema}) => {\n * const name = schema.blockObjects.find(\n * (object) => object.name === 'break',\n * )?.name\n * return name ? {name} : undefined\n * },\n * defaultStyle: ({schema}) => schema.styles[0].value,\n * headingStyle: ({schema, level}) =>\n * schema.styles.find((style) => style.value === `h${level}`)\n * ?.value,\n * blockquoteStyle: ({schema}) =>\n * schema.styles.find((style) => style.value === 'blockquote')\n * ?.value,\n * unorderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'bullet')?.value,\n * orderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'number')?.value,\n * }}\n * />\n * {...}\n * </EditorProvider>\n * )\n * }\n * ```\n *\n * @deprecated Install the plugin from `@portabletext/plugin-markdown-shortcuts`\n */\nexport function MarkdownPlugin(props: {config: MarkdownPluginConfig}) {\n const editor = useEditor()\n\n useEffect(() => {\n const behaviors = createMarkdownBehaviors(props.config)\n\n const unregisterBehaviors = behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n for (const unregisterBehavior of unregisterBehaviors) {\n unregisterBehavior()\n }\n }\n }, [editor, props.config])\n\n return (\n <>\n {props.config.boldDecorator ? (\n <>\n <DecoratorShortcutPlugin\n decorator={props.config.boldDecorator}\n pair={{char: '*', amount: 2}}\n />\n <DecoratorShortcutPlugin\n decorator={props.config.boldDecorator}\n pair={{char: '_', amount: 2}}\n />\n </>\n ) : null}\n {props.config.codeDecorator ? (\n <DecoratorShortcutPlugin\n decorator={props.config.codeDecorator}\n pair={{char: '`', amount: 1}}\n />\n ) : null}\n {props.config.italicDecorator ? (\n <>\n <DecoratorShortcutPlugin\n decorator={props.config.italicDecorator}\n pair={{char: '*', amount: 1}}\n />\n <DecoratorShortcutPlugin\n decorator={props.config.italicDecorator}\n pair={{char: '_', amount: 1}}\n />\n </>\n ) : null}\n {props.config.strikeThroughDecorator ? (\n <DecoratorShortcutPlugin\n decorator={props.config.strikeThroughDecorator}\n pair={{char: '~', amount: 2}}\n />\n ) : null}\n </>\n )\n}\n","import {defineBehavior, execute, raise} from '../behaviors'\nimport * as selectors from '../selectors'\nimport * as utils from '../utils'\nimport {BehaviorPlugin} from './plugin.behavior'\n\nconst oneLineBehaviors = [\n /**\n * Hitting Enter on an expanded selection should just delete that selection\n * without causing a line break.\n */\n defineBehavior({\n on: 'insert.break',\n guard: ({snapshot}) =>\n snapshot.context.selection && selectors.isSelectionExpanded(snapshot)\n ? {selection: snapshot.context.selection}\n : false,\n actions: [(_, {selection}) => [execute({type: 'delete', at: selection})]],\n }),\n /**\n * All other cases of `insert.break` should be aborted.\n */\n defineBehavior({\n on: 'insert.break',\n actions: [],\n }),\n /**\n * `insert.block` `before` or `after` is not allowed in a one-line editor.\n */\n defineBehavior({\n on: 'insert.block',\n guard: ({event}) =>\n event.placement === 'before' || event.placement === 'after',\n actions: [],\n }),\n /**\n * An ordinary `insert.block` is acceptable if it's a text block. In that\n * case it will get merged into the existing text block.\n */\n defineBehavior({\n on: 'insert.block',\n guard: ({snapshot, event}) => {\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n\n if (\n !focusTextBlock ||\n !utils.isTextBlock(snapshot.context, event.block)\n ) {\n return false\n }\n\n return true\n },\n actions: [\n ({event}) => [\n execute({\n type: 'insert.block',\n block: event.block,\n placement: 'auto',\n select: 'end',\n }),\n ],\n ],\n }),\n /**\n * Fallback Behavior to avoid `insert.block` in case the Behaviors above all\n * end up with a falsy guard.\n */\n defineBehavior({\n on: 'insert.block',\n actions: [],\n }),\n /**\n * If multiple blocks are inserted, then the non-text blocks are filtered out\n * and the text blocks are merged into one block\n */\n defineBehavior({\n on: 'insert.blocks',\n guard: ({snapshot, event}) => {\n const textBlocks = event.blocks.filter((block) =>\n utils.isTextBlock(snapshot.context, block),\n )\n\n if (textBlocks.length === 0) {\n return false\n }\n\n return textBlocks.reduce((targetBlock, incomingBlock) => {\n return utils.mergeTextBlocks({\n context: snapshot.context,\n targetBlock,\n incomingBlock,\n })\n })\n },\n actions: [\n // `insert.block` is raised so the Behavior above can handle the\n // insertion\n (_, block) => [raise({type: 'insert.block', block, placement: 'auto'})],\n ],\n }),\n /**\n * Fallback Behavior to avoid `insert.blocks` in case the Behavior above\n * ends up with a falsy guard.\n */\n defineBehavior({\n on: 'insert.blocks',\n actions: [],\n }),\n]\n\n/**\n * @beta\n * Restrict the editor to one line. The plugin takes care of blocking\n * `insert.break` events and smart handling of other `insert.*` events.\n *\n * Place it with as high priority as possible to make sure other plugins don't\n * overwrite `insert.*` events before this plugin gets a chance to do so.\n *\n * @deprecated Install the plugin from `@portabletext/plugin-one-line`\n */\nexport function OneLinePlugin() {\n return <BehaviorPlugin behaviors={oneLineBehaviors} />\n}\n"],"names":["BehaviorPlugin","props","$","_c","editor","useEditor","t0","t1","behaviors","unregisterBehaviors","map","behavior","registerBehavior","forEach","_temp","useEffect","unregister","createPairRegex","char","amount","prePrefix","prefix","repeat","Math","max","postPrefix","content","preSuffix","suffix","postSuffix","createDecoratorPairBehavior","config","pair","console","warn","pairRegex","regEx","RegExp","defineBehavior","on","guard","snapshot","event","decorator","schema","context","undefined","focusTextBlock","selectors","selectionStartPoint","selectionStartOffset","utils","value","selectionPoint","newText","text","textToDecorate","match","at","prefixOffsets","anchor","path","offset","length","focus","suffixOffsets","prefixSelection","offsets","inlineObjectBeforePrefixFocus","selection","inlineObjectBeforePrefixFocusOffset","previousInlineObject","previousInlineObjectOffset","actions","execute","_","type","effect","onDecorate","DecoratorShortcutPlugin","input","useActorRef","decoratorPairMachine","emphasisListener","sendBack","blockOffset","selectionListenerCallback","blockOffsets","forward","deleteBackwardListenerCallback","setup","types","events","actors","fromCallback","createMachine","id","initial","states","invoke","src","target","assign","offsetAfterEmphasis","exit","isEqual","EditorRefPlugin","React","forwardRef","ref","portableTextEditorRef","useRef","Symbol","for","current","useImperativeHandle","displayName","EventListenerPlugin","useEffectEvent","subscription","unsubscribe","createMarkdownBehaviors","automaticBlockquoteOnSpace","selectionCollapsed","focusSpan","spanSelectionPointToBlockOffset","_key","node","blockText","getTextBlockText","caretAtTheEndOfQuote","looksLikeMarkdownQuote","test","blockquoteStyle","style","automaticHr","hrCharacter","hrObject","horizontalRuleObject","focusBlock","textBefore","hrBlockOffsets","placement","block","_type","name","automaticHrOnPaste","originEvent","dataTransfer","getData","hrRegExp","hrCharacters","isTextBlock","children","automaticHeadingOnSpace","markdownHeadingSearch","exec","level","caretAtTheEndOfHeading","headingStyle","clearStyleOnBackspace","atTheBeginningOfBLock","defaultStyle","automaticListOnSpace","looksLikeUnorderedList","unorderedListStyle","caretAtTheEndOfUnorderedList","listItem","listItemLength","looksLikeOrderedList","orderedListStyle","caretAtTheEndOfOrderedList","MarkdownPlugin","unregisterBehavior","t2","boldDecorator","t3","codeDecorator","t4","italicDecorator","t5","strikeThroughDecorator","t6","oneLineBehaviors","select","textBlocks","blocks","filter","reduce","targetBlock","incomingBlock","raise","OneLinePlugin"],"mappings":";;;;;;;;;;;;;;AAOO,SAAAA,eAAAC,OAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GACLC,SAAeC,UAAU;AAAC,MAAAC,IAAAC;AAAAL,SAAAA,SAAAE,UAAAF,EAAAD,CAAAA,MAAAA,MAAAO,aAEhBF,KAAAA,MAAA;AACR,UAAAG,sBAA4BR,MAAKO,UAAAE,IAAAC,CAAAA,aAC/BP,OAAMQ,iBAAA;AAAA,MAAAD;AAAAA,IAAAA,CAA4B,CACpC;AAAC,WAAA,MAAA;AAGCF,0BAAmBI,QAAAC,KAAqC;AAAA,IAAC;AAAA,EAAA,GAE1DP,KAACH,CAAAA,QAAQH,MAAKO,SAAA,GAAWN,OAAAE,QAAAF,EAAA,CAAA,IAAAD,MAAAO,WAAAN,OAAAI,IAAAJ,OAAAK,OAAAD,KAAAJ,EAAA,CAAA,GAAAK,KAAAL,EAAA,CAAA,IAR5Ba,UAAUT,IAQPC,EAAyB,GAAC;AAAA;AAXxB,SAAAO,MAAAE,YAAA;AAAA,SAS2CA,WAAW;AAAC;AChB9CC,SAAAA,gBAAgBC,MAAcC,QAAgB;AAE5D,QAAMC,YAAY,SAASF,IAAI,KAGzBG,SAAS,KAAKH,IAAI,GAAGI,OAAOC,KAAKC,IAAIL,QAAQ,CAAC,CAAC,GAG/CM,aAAa,WAGbC,UAAU,MAAMR,IAAI,WAG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,QACAC;AAAAA,MAAAA,CACD,CACF;AAAA,IACH;AAAA,IACArH,SAAS;AAAA;AAAA;AAAA,MAGP,CAACE,GAAGoE,UAAU,CAACgD,MAAM;AAAA,QAACnH,MAAM;AAAA,QAAgBmE;AAAAA,QAAOD,WAAW;AAAA,MAAA,CAAO,CAAC;AAAA,IAAA;AAAA,EAAC,CAE1E;AAAA;AAAA;AAAA;AAAA;AAAA,EAKDxG,eAAe;AAAA,IACbC,IAAI;AAAA,IACJkC,SAAS,CAAA;AAAA,EACV,CAAA;AAAC;AAaG,SAAAuH,gBAAA;AAAA9L,QAAAA,IAAAC,EAAA,CAAA;AAAAG,MAAAA;AAAAJ,SAAAA,EAAA,CAAA,MAAA8G,OAAAC,IAAA,2BAAA,KACE3G,KAAC,oBAAA,gBAAA,EAA0BiL,WAAAA,iBAAoB,CAAA,GAAArL,OAAAI,MAAAA,KAAAJ,EAAA,CAAA,GAA/CI;AAA+C;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/plugins/plugin.behavior.tsx","../../src/internal-utils/get-text-to-emphasize.ts","../../src/behaviors/behavior.decorator-pair.ts","../../src/plugins/plugin.decorator-shortcut.ts","../../src/plugins/plugin.editor-ref.tsx","../../src/plugins/plugin.event-listener.tsx","../../src/behaviors/behavior.markdown.ts","../../src/plugins/plugin.markdown.tsx","../../src/plugins/plugin.one-line.tsx"],"sourcesContent":["import {useEffect} from 'react'\nimport type {Behavior} from '../behaviors'\nimport {useEditor} from '../editor/use-editor'\n\n/**\n * @beta\n */\nexport function BehaviorPlugin(props: {behaviors: Array<Behavior>}) {\n const editor = useEditor()\n\n useEffect(() => {\n const unregisterBehaviors = props.behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n unregisterBehaviors.forEach((unregister) => unregister())\n }\n }, [editor, props.behaviors])\n\n return null\n}\n","export function createPairRegex(char: string, amount: number) {\n // Negative lookbehind: Ensures that the matched sequence is not preceded by the same character\n const prePrefix = `(?<!\\\\${char})`\n\n // Repeats the character `amount` times\n const prefix = `\\\\${char}`.repeat(Math.max(amount, 1))\n\n // Negative lookahead: Ensures that the opening pair (**, *, etc.) is not followed by a space\n const postPrefix = `(?!\\\\s)`\n\n // Captures the content inside the pair\n const content = `([^${char}\\\\n]+?)`\n\n // Negative lookbehind: Ensures that the content is not followed by a space\n const preSuffix = `(?<!\\\\s)`\n\n // Repeats the character `amount` times\n const suffix = `\\\\${char}`.repeat(Math.max(amount, 1))\n\n // Negative lookahead: Ensures that the matched sequence is not followed by the same character\n const postSuffix = `(?!\\\\${char})`\n\n return `${prePrefix}${prefix}${postPrefix}${content}${preSuffix}${suffix}${postSuffix}`\n}\n\nconst italicRegex = new RegExp(\n `(${createPairRegex('*', 1)}|${createPairRegex('_', 1)})$`,\n)\n\nconst boldRegex = new RegExp(\n `(${createPairRegex('*', 2)}|${createPairRegex('_', 2)})$`,\n)\n\nexport function getTextToItalic(text: string) {\n return text.match(italicRegex)?.at(0)\n}\n\nexport function getTextToBold(text: string) {\n return text.match(boldRegex)?.at(0)\n}\n","import type {EditorSchema} from '../editor/editor-schema'\nimport {createPairRegex} from '../internal-utils/get-text-to-emphasize'\nimport * as selectors from '../selectors'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {effect, execute} from './behavior.types.action'\nimport {defineBehavior} from './behavior.types.behavior'\n\nexport function createDecoratorPairBehavior(config: {\n decorator: ({schema}: {schema: EditorSchema}) => string | undefined\n pair: {char: string; amount: number}\n onDecorate: (offset: BlockOffset) => void\n}) {\n if (config.pair.amount < 1) {\n console.warn(\n `The amount of characters in the pair should be greater than 0`,\n )\n }\n\n const pairRegex = createPairRegex(config.pair.char, config.pair.amount)\n const regEx = new RegExp(`(${pairRegex})$`)\n\n return defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n if (config.pair.amount < 1) {\n return false\n }\n\n const decorator = config.decorator({schema: snapshot.context.schema})\n\n if (decorator === undefined) {\n return false\n }\n\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const selectionStartPoint = selectors.getSelectionStartPoint(snapshot)\n const selectionStartOffset = selectionStartPoint\n ? utils.spanSelectionPointToBlockOffset({\n context: {\n schema: snapshot.context.schema,\n value: snapshot.context.value,\n },\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartOffset) {\n return false\n }\n\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const newText = `${textBefore}${event.text}`\n const textToDecorate = newText.match(regEx)?.at(0)\n\n if (textToDecorate === undefined) {\n return false\n }\n\n const prefixOffsets = {\n anchor: {\n path: focusTextBlock.path,\n // Example: \"foo **bar**\".length - \"**bar**\".length = 4\n offset: newText.length - textToDecorate.length,\n },\n focus: {\n path: focusTextBlock.path,\n // Example: \"foo **bar**\".length - \"**bar**\".length + \"*\".length * 2 = 6\n offset:\n newText.length -\n textToDecorate.length +\n config.pair.char.length * config.pair.amount,\n },\n }\n\n const suffixOffsets = {\n anchor: {\n path: focusTextBlock.path,\n // Example: \"foo **bar*|\" (10) + \"*\".length - 2 = 9\n offset:\n selectionStartOffset.offset +\n event.text.length -\n config.pair.char.length * config.pair.amount,\n },\n focus: {\n path: focusTextBlock.path,\n // Example: \"foo **bar*|\" (10) + \"*\".length = 11\n offset: selectionStartOffset.offset + event.text.length,\n },\n }\n\n // If the prefix is more than one character, then we need to check if\n // there is an inline object inside it\n if (prefixOffsets.focus.offset - prefixOffsets.anchor.offset > 1) {\n const prefixSelection = utils.blockOffsetsToSelection({\n context: snapshot.context,\n offsets: prefixOffsets,\n })\n const inlineObjectBeforePrefixFocus = selectors.getPreviousInlineObject(\n {\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: prefixSelection\n ? {\n anchor: prefixSelection.focus,\n focus: prefixSelection.focus,\n }\n : null,\n },\n },\n )\n const inlineObjectBeforePrefixFocusOffset =\n inlineObjectBeforePrefixFocus\n ? utils.childSelectionPointToBlockOffset({\n context: {\n schema: snapshot.context.schema,\n value: snapshot.context.value,\n },\n selectionPoint: {\n path: inlineObjectBeforePrefixFocus.path,\n offset: 0,\n },\n })\n : undefined\n\n if (\n inlineObjectBeforePrefixFocusOffset &&\n inlineObjectBeforePrefixFocusOffset.offset >\n prefixOffsets.anchor.offset &&\n inlineObjectBeforePrefixFocusOffset.offset <\n prefixOffsets.focus.offset\n ) {\n return false\n }\n }\n\n // If the suffix is more than one character, then we need to check if\n // there is an inline object inside it\n if (suffixOffsets.focus.offset - suffixOffsets.anchor.offset > 1) {\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const previousInlineObjectOffset = previousInlineObject\n ? utils.childSelectionPointToBlockOffset({\n context: {\n schema: snapshot.context.schema,\n value: snapshot.context.value,\n },\n selectionPoint: {\n path: previousInlineObject.path,\n offset: 0,\n },\n })\n : undefined\n\n if (\n previousInlineObjectOffset &&\n previousInlineObjectOffset.offset > suffixOffsets.anchor.offset &&\n previousInlineObjectOffset.offset < suffixOffsets.focus.offset\n ) {\n return false\n }\n }\n\n return {\n prefixOffsets,\n suffixOffsets,\n decorator,\n }\n },\n actions: [\n // Insert the text as usual in its own undo step\n ({event}) => [execute(event)],\n (_, {prefixOffsets, suffixOffsets, decorator}) => [\n // Decorate the text between the prefix and suffix\n execute({\n type: 'decorator.add',\n decorator,\n at: {\n anchor: prefixOffsets.focus,\n focus: suffixOffsets.anchor,\n },\n }),\n // Delete the suffix\n execute({\n type: 'delete.text',\n at: suffixOffsets,\n }),\n // Delete the prefix\n execute({\n type: 'delete.text',\n at: prefixOffsets,\n }),\n // Toggle the decorator off so the next inserted text isn't emphasized\n execute({\n type: 'decorator.remove',\n decorator,\n }),\n effect(() => {\n config.onDecorate({\n ...suffixOffsets.anchor,\n offset:\n suffixOffsets.anchor.offset -\n (prefixOffsets.focus.offset - prefixOffsets.anchor.offset),\n })\n }),\n ],\n ],\n })\n}\n","import {useActorRef} from '@xstate/react'\nimport {isEqual} from 'lodash'\nimport {\n assign,\n fromCallback,\n setup,\n type AnyEventObject,\n type CallbackLogicFunction,\n} from 'xstate'\nimport {createDecoratorPairBehavior} from '../behaviors/behavior.decorator-pair'\nimport {effect, execute, forward} from '../behaviors/behavior.types.action'\nimport {defineBehavior} from '../behaviors/behavior.types.behavior'\nimport type {Editor} from '../editor'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport {useEditor} from '../editor/use-editor'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\n\n/**\n * @beta\n * @deprecated Install the plugin from `@portabletext/plugin-character-pair-decorator`\n */\nexport function DecoratorShortcutPlugin(config: {\n decorator: ({schema}: {schema: EditorSchema}) => string | undefined\n pair: {char: string; amount: number}\n}) {\n const editor = useEditor()\n\n useActorRef(decoratorPairMachine, {\n input: {\n editor,\n decorator: config.decorator,\n pair: config.pair,\n },\n })\n\n return null\n}\n\ntype MarkdownEmphasisEvent =\n | {\n type: 'emphasis.add'\n blockOffset: BlockOffset\n }\n | {\n type: 'selection'\n blockOffsets?: {\n anchor: BlockOffset\n focus: BlockOffset\n }\n }\n | {\n type: 'delete.backward'\n }\n\nconst emphasisListener: CallbackLogicFunction<\n AnyEventObject,\n MarkdownEmphasisEvent,\n {\n decorator: ({schema}: {schema: EditorSchema}) => string | undefined\n editor: Editor\n pair: {char: string; amount: number}\n }\n> = ({sendBack, input}) => {\n const unregister = input.editor.registerBehavior({\n behavior: createDecoratorPairBehavior({\n decorator: input.decorator,\n pair: input.pair,\n onDecorate: (offset) => {\n sendBack({type: 'emphasis.add', blockOffset: offset})\n },\n }),\n })\n\n return unregister\n}\n\nconst selectionListenerCallback: CallbackLogicFunction<\n AnyEventObject,\n MarkdownEmphasisEvent,\n {editor: Editor}\n> = ({sendBack, input}) => {\n const unregister = input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'select',\n guard: ({snapshot, event}) => {\n if (!event.at) {\n return {blockOffsets: undefined}\n }\n\n const anchor = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: event.at.anchor,\n })\n const focus = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: event.at.focus,\n })\n\n if (!anchor || !focus) {\n return {blockOffsets: undefined}\n }\n\n return {\n blockOffsets: {\n anchor,\n focus,\n },\n }\n },\n actions: [\n ({event}, {blockOffsets}) => [\n {\n type: 'effect',\n effect: () => {\n sendBack({type: 'selection', blockOffsets})\n },\n },\n forward(event),\n ],\n ],\n }),\n })\n\n return unregister\n}\n\nconst deleteBackwardListenerCallback: CallbackLogicFunction<\n AnyEventObject,\n MarkdownEmphasisEvent,\n {editor: Editor}\n> = ({sendBack, input}) => {\n const unregister = input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'delete.backward',\n actions: [\n () => [\n execute({\n type: 'history.undo',\n }),\n effect(() => {\n sendBack({type: 'delete.backward'})\n }),\n ],\n ],\n }),\n })\n\n return unregister\n}\n\nconst decoratorPairMachine = setup({\n types: {\n context: {} as {\n decorator: ({schema}: {schema: EditorSchema}) => string | undefined\n editor: Editor\n offsetAfterEmphasis?: BlockOffset\n pair: {char: string; amount: number}\n },\n input: {} as {\n decorator: ({schema}: {schema: EditorSchema}) => string | undefined\n editor: Editor\n pair: {char: string; amount: number}\n },\n events: {} as MarkdownEmphasisEvent,\n },\n actors: {\n 'emphasis listener': fromCallback(emphasisListener),\n 'delete.backward listener': fromCallback(deleteBackwardListenerCallback),\n 'selection listener': fromCallback(selectionListenerCallback),\n },\n}).createMachine({\n id: 'decorator pair',\n context: ({input}) => ({\n decorator: input.decorator,\n editor: input.editor,\n pair: input.pair,\n }),\n initial: 'idle',\n states: {\n 'idle': {\n invoke: [\n {\n src: 'emphasis listener',\n input: ({context}) => ({\n decorator: context.decorator,\n editor: context.editor,\n pair: context.pair,\n }),\n },\n ],\n on: {\n 'emphasis.add': {\n target: 'emphasis added',\n actions: assign({\n offsetAfterEmphasis: ({event}) => event.blockOffset,\n }),\n },\n },\n },\n 'emphasis added': {\n exit: [\n assign({\n offsetAfterEmphasis: undefined,\n }),\n ],\n invoke: [\n {\n src: 'selection listener',\n input: ({context}) => ({editor: context.editor}),\n },\n {\n src: 'delete.backward listener',\n input: ({context}) => ({editor: context.editor}),\n },\n ],\n on: {\n 'selection': {\n target: 'idle',\n guard: ({context, event}) => {\n const selectionChanged = !isEqual(\n {\n anchor: context.offsetAfterEmphasis,\n focus: context.offsetAfterEmphasis,\n },\n event.blockOffsets,\n )\n\n return selectionChanged\n },\n },\n 'delete.backward': {\n target: 'idle',\n },\n },\n },\n },\n})\n","import React from 'react'\nimport type {Editor} from '../editor'\nimport {useEditor} from '../editor/use-editor'\n\n/**\n * @beta\n */\nexport const EditorRefPlugin = React.forwardRef<Editor | null>((_, ref) => {\n const editor = useEditor()\n\n const portableTextEditorRef = React.useRef(editor)\n\n React.useImperativeHandle(ref, () => portableTextEditorRef.current, [])\n\n return null\n})\nEditorRefPlugin.displayName = 'EditorRefPlugin'\n","import {useEffect} from 'react'\nimport {useEffectEvent} from 'use-effect-event'\nimport type {EditorEmittedEvent} from '../editor/editor-machine'\nimport {useEditor} from '../editor/use-editor'\n\n/**\n * @public\n * Listen for events emitted by the editor. Must be used inside `EditorProvider`. Events available include:\n * - 'blurred'\n * - 'done loading'\n * - 'editable'\n * - 'error'\n * - 'focused'\n * - 'invalid value'\n * - 'loading'\n * - 'mutation'\n * - 'patch'\n * - 'read only'\n * - 'ready'\n * - 'selection'\n * - 'value changed'\n *\n * @example\n * Listen and log events.\n * ```tsx\n * import {EditorProvider} from '@portabletext/editor'\n * import {EventListenerPlugin} from '@portabletext/editor/plugins'\n *\n * function MyComponent() {\n * return (\n * <EditorProvider>\n * <EventListenerPlugin\n * on={(event) => {\n * console.log(event)\n * }\n * } />\n * { ... }\n * </EditorProvider>\n * )\n * }\n * ```\n * @example\n * Handle events when there is a mutation.\n * ```tsx\n * <EventListenerPlugin\n * on={(event) => {\n * if (event.type === 'mutation') {\n * console.log('Value changed:', event.snapshot)\n * }\n * }}\n * />\n * ```\n * @group Components\n */\nexport function EventListenerPlugin(props: {\n on: (event: EditorEmittedEvent) => void\n}) {\n const editor = useEditor()\n const on = useEffectEvent(props.on)\n\n useEffect(() => {\n const subscription = editor.on('*', on)\n\n return () => {\n subscription.unsubscribe()\n }\n }, [editor])\n\n return null\n}\n","import type {EditorSchema} from '../editor/editor-schema'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport * as selectors from '../selectors'\nimport {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\nimport {getTextBlockText} from '../utils/util.get-text-block-text'\nimport {execute} from './behavior.types.action'\nimport {defineBehavior} from './behavior.types.behavior'\n\nexport type MarkdownBehaviorsConfig = {\n horizontalRuleObject?: (context: {\n schema: EditorSchema\n }) => {name: string; value?: {[prop: string]: unknown}} | undefined\n defaultStyle?: (context: {schema: EditorSchema}) => string | undefined\n headingStyle?: (context: {\n schema: EditorSchema\n level: number\n }) => string | undefined\n blockquoteStyle?: (context: {schema: EditorSchema}) => string | undefined\n unorderedListStyle?: (context: {schema: EditorSchema}) => string | undefined\n orderedListStyle?: (context: {schema: EditorSchema}) => string | undefined\n}\n\nexport function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {\n const automaticBlockquoteOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const blockOffset = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: snapshot.context.selection?.focus.offset ?? 0,\n },\n })\n\n if (previousInlineObject || !blockOffset) {\n return false\n }\n\n const blockText = getTextBlockText(focusTextBlock.node)\n const caretAtTheEndOfQuote = blockOffset.offset === 1\n const looksLikeMarkdownQuote = /^>/.test(blockText)\n const blockquoteStyle = config.blockquoteStyle?.(snapshot.context)\n\n if (\n caretAtTheEndOfQuote &&\n looksLikeMarkdownQuote &&\n blockquoteStyle !== undefined\n ) {\n return {focusTextBlock, style: blockquoteStyle}\n }\n\n return false\n },\n actions: [\n () => [\n execute({\n type: 'insert.text',\n text: ' ',\n }),\n ],\n (_, {focusTextBlock, style}) => [\n execute({\n type: 'block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n }),\n execute({\n type: 'block.set',\n props: {style},\n at: focusTextBlock.path,\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: focusTextBlock.path,\n offset: 0,\n },\n focus: {\n path: focusTextBlock.path,\n offset: 2,\n },\n },\n }),\n ],\n ],\n })\n const automaticHr = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const hrCharacter =\n event.text === '-'\n ? '-'\n : event.text === '*'\n ? '*'\n : event.text === '_'\n ? '_'\n : undefined\n\n if (hrCharacter === undefined) {\n return false\n }\n\n const hrObject = config.horizontalRuleObject?.(snapshot.context)\n const focusBlock = selectors.getFocusTextBlock(snapshot)\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n\n if (!hrObject || !focusBlock || !selectionCollapsed) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const hrBlockOffsets = {\n anchor: {\n path: focusBlock.path,\n offset: 0,\n },\n focus: {\n path: focusBlock.path,\n offset: 3,\n },\n }\n\n if (\n !previousInlineObject &&\n textBefore === `${hrCharacter}${hrCharacter}`\n ) {\n return {hrObject, focusBlock, hrCharacter, hrBlockOffsets}\n }\n\n return false\n },\n actions: [\n (_, {hrCharacter}) => [\n execute({\n type: 'insert.text',\n text: hrCharacter,\n }),\n ],\n (_, {hrObject, hrBlockOffsets}) => [\n execute({\n type: 'insert.block',\n placement: 'before',\n block: {\n _type: hrObject.name,\n ...(hrObject.value ?? {}),\n },\n }),\n execute({\n type: 'delete.text',\n at: hrBlockOffsets,\n }),\n ],\n ],\n })\n const automaticHrOnPaste = defineBehavior({\n on: 'clipboard.paste',\n guard: ({snapshot, event}) => {\n const text = event.originEvent.dataTransfer.getData('text/plain')\n const hrRegExp = /^(---)$|(___)$|(\\*\\*\\*)$/\n const hrCharacters = text.match(hrRegExp)?.[0]\n const hrObject = config.horizontalRuleObject?.(snapshot.context)\n const focusBlock = selectors.getFocusBlock(snapshot)\n\n if (!hrCharacters || !hrObject || !focusBlock) {\n return false\n }\n\n return {hrCharacters, hrObject, focusBlock}\n },\n actions: [\n (_, {hrCharacters}) => [\n execute({\n type: 'insert.text',\n text: hrCharacters,\n }),\n ],\n ({snapshot}, {hrObject, focusBlock}) =>\n isTextBlock(snapshot.context, focusBlock.node)\n ? [\n execute({\n type: 'insert.block',\n block: {\n _type: snapshot.context.schema.block.name,\n children: focusBlock.node.children,\n },\n placement: 'after',\n }),\n execute({\n type: 'insert.block',\n block: {\n _type: hrObject.name,\n ...(hrObject.value ?? {}),\n },\n placement: 'after',\n }),\n execute({\n type: 'delete.block',\n at: focusBlock.path,\n }),\n ]\n : [\n execute({\n type: 'insert.block',\n block: {\n _type: hrObject.name,\n ...(hrObject.value ?? {}),\n },\n placement: 'after',\n }),\n ],\n ],\n })\n const automaticHeadingOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const blockOffset = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: snapshot.context.selection?.focus.offset ?? 0,\n },\n })\n\n if (!blockOffset) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const blockText = getTextBlockText(focusTextBlock.node)\n const markdownHeadingSearch = /^#+/.exec(blockText)\n const level = markdownHeadingSearch\n ? markdownHeadingSearch[0].length\n : undefined\n const caretAtTheEndOfHeading = blockOffset.offset === level\n\n if (previousInlineObject || !caretAtTheEndOfHeading) {\n return false\n }\n\n const style =\n level !== undefined\n ? config.headingStyle?.({schema: snapshot.context.schema, level})\n : undefined\n\n if (level !== undefined && style !== undefined) {\n return {\n focusTextBlock,\n style: style,\n level,\n }\n }\n\n return false\n },\n actions: [\n ({event}) => [execute(event)],\n (_, {focusTextBlock, style, level}) => [\n execute({\n type: 'block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n }),\n execute({\n type: 'block.set',\n props: {style},\n at: focusTextBlock.path,\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: focusTextBlock.path,\n offset: 0,\n },\n focus: {\n path: focusTextBlock.path,\n offset: level + 1,\n },\n },\n }),\n ],\n ],\n })\n const clearStyleOnBackspace = defineBehavior({\n on: 'delete.backward',\n guard: ({snapshot}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const atTheBeginningOfBLock =\n focusTextBlock.node.children[0]._key === focusSpan.node._key &&\n snapshot.context.selection?.focus.offset === 0\n\n const defaultStyle = config.defaultStyle?.(snapshot.context)\n\n if (\n atTheBeginningOfBLock &&\n defaultStyle &&\n focusTextBlock.node.style !== defaultStyle\n ) {\n return {defaultStyle, focusTextBlock}\n }\n\n return false\n },\n actions: [\n (_, {defaultStyle, focusTextBlock}) => [\n execute({\n type: 'block.set',\n props: {style: defaultStyle},\n at: focusTextBlock.path,\n }),\n ],\n ],\n })\n const automaticListOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const blockOffset = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: snapshot.context.selection?.focus.offset ?? 0,\n },\n })\n\n if (previousInlineObject || !blockOffset) {\n return false\n }\n\n const blockText = getTextBlockText(focusTextBlock.node)\n const defaultStyle = config.defaultStyle?.(snapshot.context)\n const looksLikeUnorderedList = /^(-|\\*)/.test(blockText)\n const unorderedListStyle = config.unorderedListStyle?.(snapshot.context)\n const caretAtTheEndOfUnorderedList = blockOffset.offset === 1\n\n if (\n defaultStyle &&\n caretAtTheEndOfUnorderedList &&\n looksLikeUnorderedList &&\n unorderedListStyle !== undefined\n ) {\n return {\n focusTextBlock,\n listItem: unorderedListStyle,\n listItemLength: 1,\n style: defaultStyle,\n }\n }\n\n const looksLikeOrderedList = /^1\\./.test(blockText)\n const orderedListStyle = config.orderedListStyle?.(snapshot.context)\n const caretAtTheEndOfOrderedList = blockOffset.offset === 2\n\n if (\n defaultStyle &&\n caretAtTheEndOfOrderedList &&\n looksLikeOrderedList &&\n orderedListStyle !== undefined\n ) {\n return {\n focusTextBlock,\n listItem: orderedListStyle,\n listItemLength: 2,\n style: defaultStyle,\n }\n }\n\n return false\n },\n actions: [\n ({event}) => [execute(event)],\n (_, {focusTextBlock, style, listItem, listItemLength}) => [\n execute({\n type: 'block.set',\n props: {\n listItem,\n level: 1,\n style,\n },\n at: focusTextBlock.path,\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: focusTextBlock.path,\n offset: 0,\n },\n focus: {\n path: focusTextBlock.path,\n offset: listItemLength + 1,\n },\n },\n }),\n ],\n ],\n })\n\n const markdownBehaviors = [\n automaticBlockquoteOnSpace,\n automaticHeadingOnSpace,\n automaticHr,\n automaticHrOnPaste,\n clearStyleOnBackspace,\n automaticListOnSpace,\n ]\n\n return markdownBehaviors\n}\n","import {useEffect} from 'react'\nimport {\n createMarkdownBehaviors,\n type MarkdownBehaviorsConfig,\n} from '../behaviors/behavior.markdown'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport {useEditor} from '../editor/use-editor'\nimport {DecoratorShortcutPlugin} from './plugin.decorator-shortcut'\n\n/**\n * @beta\n */\nexport type MarkdownPluginConfig = MarkdownBehaviorsConfig & {\n boldDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined\n codeDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined\n italicDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined\n strikeThroughDecorator?: ({\n schema,\n }: {\n schema: EditorSchema\n }) => string | undefined\n}\n\n/**\n * @beta\n * Add markdown behaviors for common markdown actions such as converting ### to headings, --- to HRs, and more.\n *\n * @example\n * Configure the bundled markdown behaviors\n * ```ts\n * import {EditorProvider} from '@portabletext/editor'\n * import {MarkdownPlugin} from '@portabletext/editor/plugins'\n *\n * function App() {\n * return (\n * <EditorProvider>\n * <MarkdownPlugin\n * config={{\n * boldDecorator: ({schema}) =>\n * schema.decorators.find((decorator) => decorator.value === 'strong')?.value,\n * codeDecorator: ({schema}) =>\n * schema.decorators.find((decorator) => decorator.value === 'code')?.value,\n * italicDecorator: ({schema}) =>\n * schema.decorators.find((decorator) => decorator.value === 'em')?.value,\n * strikeThroughDecorator: ({schema}) =>\n * schema.decorators.find((decorator) => decorator.value === 'strike-through')?.value,\n * horizontalRuleObject: ({schema}) => {\n * const name = schema.blockObjects.find(\n * (object) => object.name === 'break',\n * )?.name\n * return name ? {name} : undefined\n * },\n * defaultStyle: ({schema}) => schema.styles[0].value,\n * headingStyle: ({schema, level}) =>\n * schema.styles.find((style) => style.value === `h${level}`)\n * ?.value,\n * blockquoteStyle: ({schema}) =>\n * schema.styles.find((style) => style.value === 'blockquote')\n * ?.value,\n * unorderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'bullet')?.value,\n * orderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'number')?.value,\n * }}\n * />\n * {...}\n * </EditorProvider>\n * )\n * }\n * ```\n *\n * @deprecated Install the plugin from `@portabletext/plugin-markdown-shortcuts`\n */\nexport function MarkdownPlugin(props: {config: MarkdownPluginConfig}) {\n const editor = useEditor()\n\n useEffect(() => {\n const behaviors = createMarkdownBehaviors(props.config)\n\n const unregisterBehaviors = behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n for (const unregisterBehavior of unregisterBehaviors) {\n unregisterBehavior()\n }\n }\n }, [editor, props.config])\n\n return (\n <>\n {props.config.boldDecorator ? (\n <>\n <DecoratorShortcutPlugin\n decorator={props.config.boldDecorator}\n pair={{char: '*', amount: 2}}\n />\n <DecoratorShortcutPlugin\n decorator={props.config.boldDecorator}\n pair={{char: '_', amount: 2}}\n />\n </>\n ) : null}\n {props.config.codeDecorator ? (\n <DecoratorShortcutPlugin\n decorator={props.config.codeDecorator}\n pair={{char: '`', amount: 1}}\n />\n ) : null}\n {props.config.italicDecorator ? (\n <>\n <DecoratorShortcutPlugin\n decorator={props.config.italicDecorator}\n pair={{char: '*', amount: 1}}\n />\n <DecoratorShortcutPlugin\n decorator={props.config.italicDecorator}\n pair={{char: '_', amount: 1}}\n />\n </>\n ) : null}\n {props.config.strikeThroughDecorator ? (\n <DecoratorShortcutPlugin\n decorator={props.config.strikeThroughDecorator}\n pair={{char: '~', amount: 2}}\n />\n ) : null}\n </>\n )\n}\n","import {defineBehavior, execute, raise} from '../behaviors'\nimport * as selectors from '../selectors'\nimport * as utils from '../utils'\nimport {BehaviorPlugin} from './plugin.behavior'\n\nconst oneLineBehaviors = [\n /**\n * Hitting Enter on an expanded selection should just delete that selection\n * without causing a line break.\n */\n defineBehavior({\n on: 'insert.break',\n guard: ({snapshot}) =>\n snapshot.context.selection && selectors.isSelectionExpanded(snapshot)\n ? {selection: snapshot.context.selection}\n : false,\n actions: [(_, {selection}) => [execute({type: 'delete', at: selection})]],\n }),\n /**\n * All other cases of `insert.break` should be aborted.\n */\n defineBehavior({\n on: 'insert.break',\n actions: [],\n }),\n /**\n * `insert.block` `before` or `after` is not allowed in a one-line editor.\n */\n defineBehavior({\n on: 'insert.block',\n guard: ({event}) =>\n event.placement === 'before' || event.placement === 'after',\n actions: [],\n }),\n /**\n * An ordinary `insert.block` is acceptable if it's a text block. In that\n * case it will get merged into the existing text block.\n */\n defineBehavior({\n on: 'insert.block',\n guard: ({snapshot, event}) => {\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n\n if (\n !focusTextBlock ||\n !utils.isTextBlock(snapshot.context, event.block)\n ) {\n return false\n }\n\n return true\n },\n actions: [\n ({event}) => [\n execute({\n type: 'insert.block',\n block: event.block,\n placement: 'auto',\n select: 'end',\n }),\n ],\n ],\n }),\n /**\n * Fallback Behavior to avoid `insert.block` in case the Behaviors above all\n * end up with a falsy guard.\n */\n defineBehavior({\n on: 'insert.block',\n actions: [],\n }),\n /**\n * If multiple blocks are inserted, then the non-text blocks are filtered out\n * and the text blocks are merged into one block\n */\n defineBehavior({\n on: 'insert.blocks',\n guard: ({snapshot, event}) => {\n const textBlocks = event.blocks.filter((block) =>\n utils.isTextBlock(snapshot.context, block),\n )\n\n if (textBlocks.length === 0) {\n return false\n }\n\n return textBlocks.reduce((targetBlock, incomingBlock) => {\n return utils.mergeTextBlocks({\n context: snapshot.context,\n targetBlock,\n incomingBlock,\n })\n })\n },\n actions: [\n // `insert.block` is raised so the Behavior above can handle the\n // insertion\n (_, block) => [raise({type: 'insert.block', block, placement: 'auto'})],\n ],\n }),\n /**\n * Fallback Behavior to avoid `insert.blocks` in case the Behavior above\n * ends up with a falsy guard.\n */\n defineBehavior({\n on: 'insert.blocks',\n actions: [],\n }),\n]\n\n/**\n * @beta\n * Restrict the editor to one line. The plugin takes care of blocking\n * `insert.break` events and smart handling of other `insert.*` events.\n *\n * Place it with as high priority as possible to make sure other plugins don't\n * overwrite `insert.*` events before this plugin gets a chance to do so.\n *\n * @deprecated Install the plugin from `@portabletext/plugin-one-line`\n */\nexport function OneLinePlugin() {\n return <BehaviorPlugin behaviors={oneLineBehaviors} />\n}\n"],"names":["BehaviorPlugin","props","$","_c","editor","useEditor","t0","t1","behaviors","unregisterBehaviors","map","behavior","registerBehavior","forEach","_temp","useEffect","unregister","createPairRegex","char","amount","prePrefix","prefix","repeat","Math","max","postPrefix","content","preSuffix","suffix","postSuffix","createDecoratorPairBehavior","config","pair","console","warn","pairRegex","regEx","RegExp","defineBehavior","on","guard","snapshot","event","decorator","schema","context","undefined","focusTextBlock","selectors","selectionStartPoint","selectionStartOffset","utils","value","selectionPoint","newText","text","textToDecorate","match","at","prefixOffsets","anchor","path","offset","length","focus","suffixOffsets","prefixSelection","offsets","inlineObjectBeforePrefixFocus","selection","inlineObjectBeforePrefixFocusOffset","previousInlineObject","previousInlineObjectOffset","actions","execute","_","type","effect","onDecorate","DecoratorShortcutPlugin","input","useActorRef","decoratorPairMachine","emphasisListener","sendBack","blockOffset","selectionListenerCallback","blockOffsets","forward","deleteBackwardListenerCallback","setup","types","events","actors","fromCallback","createMachine","id","initial","states","invoke","src","target","assign","offsetAfterEmphasis","exit","isEqual","EditorRefPlugin","React","forwardRef","ref","portableTextEditorRef","useRef","Symbol","for","current","useImperativeHandle","displayName","EventListenerPlugin","useEffectEvent","subscription","unsubscribe","createMarkdownBehaviors","automaticBlockquoteOnSpace","selectionCollapsed","focusSpan","spanSelectionPointToBlockOffset","_key","node","blockText","getTextBlockText","caretAtTheEndOfQuote","looksLikeMarkdownQuote","test","blockquoteStyle","style","automaticHr","hrCharacter","hrObject","horizontalRuleObject","focusBlock","textBefore","hrBlockOffsets","placement","block","_type","name","automaticHrOnPaste","originEvent","dataTransfer","getData","hrRegExp","hrCharacters","isTextBlock","children","automaticHeadingOnSpace","markdownHeadingSearch","exec","level","caretAtTheEndOfHeading","headingStyle","clearStyleOnBackspace","atTheBeginningOfBLock","defaultStyle","automaticListOnSpace","looksLikeUnorderedList","unorderedListStyle","caretAtTheEndOfUnorderedList","listItem","listItemLength","looksLikeOrderedList","orderedListStyle","caretAtTheEndOfOrderedList","MarkdownPlugin","unregisterBehavior","t2","boldDecorator","t3","codeDecorator","t4","italicDecorator","t5","strikeThroughDecorator","t6","oneLineBehaviors","select","textBlocks","blocks","filter","reduce","targetBlock","incomingBlock","raise","OneLinePlugin"],"mappings":";;;;;;;;;;;;;;AAOO,SAAAA,eAAAC,OAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GACLC,SAAeC,UAAU;AAAC,MAAAC,IAAAC;AAAAL,SAAAA,SAAAE,UAAAF,EAAAD,CAAAA,MAAAA,MAAAO,aAEhBF,KAAAA,MAAA;AACR,UAAAG,sBAA4BR,MAAKO,UAAAE,IAAAC,CAAAA,aAC/BP,OAAMQ,iBAAA;AAAA,MAAAD;AAAAA,IAAAA,CAA4B,CACpC;AAAC,WAAA,MAAA;AAGCF,0BAAmBI,QAAAC,KAAqC;AAAA,IAAC;AAAA,EAAA,GAE1DP,KAACH,CAAAA,QAAQH,MAAKO,SAAA,GAAWN,OAAAE,QAAAF,EAAA,CAAA,IAAAD,MAAAO,WAAAN,OAAAI,IAAAJ,OAAAK,OAAAD,KAAAJ,EAAA,CAAA,GAAAK,KAAAL,EAAA,CAAA,IAR5Ba,UAAUT,IAQPC,EAAyB,GAAC;AAAA;AAXxB,SAAAO,MAAAE,YAAA;AAAA,SAS2CA,WAAW;AAAC;AChB9CC,SAAAA,gBAAgBC,MAAcC,QAAgB;AAE5D,QAAMC,YAAY,SAASF,IAAI,KAGzBG,SAAS,KAA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GF0H,WAAWG,OAAO,CAACC,aAAaC,kBAC9B3I,gBAAsB;AAAA,QAC3BN,SAASJ,SAASI;AAAAA,QAClBgJ;AAAAA,QACAC;AAAAA,MAAAA,CACD,CACF;AAAA,IACH;AAAA,IACArH,SAAS;AAAA;AAAA;AAAA,MAGP,CAACE,GAAGoE,UAAU,CAACgD,MAAM;AAAA,QAACnH,MAAM;AAAA,QAAgBmE;AAAAA,QAAOD,WAAW;AAAA,MAAA,CAAO,CAAC;AAAA,IAAA;AAAA,EAAC,CAE1E;AAAA;AAAA;AAAA;AAAA;AAAA,EAKDxG,eAAe;AAAA,IACbC,IAAI;AAAA,IACJkC,SAAS,CAAA;AAAA,EACV,CAAA;AAAC;AAaG,SAAAuH,gBAAA;AAAA9L,QAAAA,IAAAC,EAAA,CAAA;AAAAG,MAAAA;AAAAJ,SAAAA,EAAA,CAAA,MAAA8G,OAAAC,IAAA,2BAAA,KACE3G,KAAC,oBAAA,gBAAA,EAA0BiL,WAAAA,iBAAoB,CAAA,GAAArL,OAAAI,MAAAA,KAAAJ,EAAA,CAAA,GAA/CI;AAA+C;"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var selector_isSelectingEntireBlocks = require("../_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), types = require("@sanity/types"), selector_getFocusInlineObject = require("../_chunks-cjs/selector.get-focus-inline-object.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs");
3
+ var selector_isSelectingEntireBlocks = require("../_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), types = require("@sanity/types"), selector_isSelectionExpanded = require("../_chunks-cjs/selector.is-selection-expanded.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs");
4
4
  const getAnchorBlock = (snapshot) => {
5
5
  const key = snapshot.context.selection && util_sliceBlocks.isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
6
6
  return node && key ? {
@@ -35,7 +35,7 @@ const getAnchorBlock = (snapshot) => {
35
35
  }, getBlockOffsets = (snapshot) => {
36
36
  if (!snapshot.context.selection)
37
37
  return;
38
- const selectionStartPoint = selector_isSelectingEntireBlocks.getSelectionStartPoint(snapshot), selectionEndPoint = selector_isSelectingEntireBlocks.getSelectionEndPoint(snapshot);
38
+ const selectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), selectionEndPoint = selector_isSelectingEntireBlocks.getSelectionEndPoint(snapshot);
39
39
  if (!selectionStartPoint || !selectionEndPoint)
40
40
  return;
41
41
  const start = util_sliceBlocks.spanSelectionPointToBlockOffset({
@@ -54,27 +54,11 @@ exports.getActiveAnnotations = selector_isSelectingEntireBlocks.getActiveAnnotat
54
54
  exports.getActiveListItem = selector_isSelectingEntireBlocks.getActiveListItem;
55
55
  exports.getActiveStyle = selector_isSelectingEntireBlocks.getActiveStyle;
56
56
  exports.getCaretWordSelection = selector_isSelectingEntireBlocks.getCaretWordSelection;
57
- exports.getFirstBlock = selector_isSelectingEntireBlocks.getFirstBlock;
58
- exports.getFocusBlock = selector_isSelectingEntireBlocks.getFocusBlock;
59
- exports.getFocusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject;
60
- exports.getFocusChild = selector_isSelectingEntireBlocks.getFocusChild;
61
- exports.getFocusListBlock = selector_isSelectingEntireBlocks.getFocusListBlock;
62
- exports.getFocusSpan = selector_isSelectingEntireBlocks.getFocusSpan;
63
- exports.getFocusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock;
64
- exports.getLastBlock = selector_isSelectingEntireBlocks.getLastBlock;
65
- exports.getNextBlock = selector_isSelectingEntireBlocks.getNextBlock;
57
+ exports.getFocusInlineObject = selector_isSelectingEntireBlocks.getFocusInlineObject;
66
58
  exports.getNextInlineObject = selector_isSelectingEntireBlocks.getNextInlineObject;
67
- exports.getPreviousBlock = selector_isSelectingEntireBlocks.getPreviousBlock;
68
- exports.getPreviousInlineObject = selector_isSelectingEntireBlocks.getPreviousInlineObject;
69
- exports.getSelectedBlocks = selector_isSelectingEntireBlocks.getSelectedBlocks;
70
- exports.getSelectedSlice = selector_isSelectingEntireBlocks.getSelectedSlice;
71
59
  exports.getSelectedSpans = selector_isSelectingEntireBlocks.getSelectedSpans;
72
60
  exports.getSelectedTextBlocks = selector_isSelectingEntireBlocks.getSelectedTextBlocks;
73
- exports.getSelectionEndBlock = selector_isSelectingEntireBlocks.getSelectionEndBlock;
74
61
  exports.getSelectionEndPoint = selector_isSelectingEntireBlocks.getSelectionEndPoint;
75
- exports.getSelectionStartBlock = selector_isSelectingEntireBlocks.getSelectionStartBlock;
76
- exports.getSelectionStartPoint = selector_isSelectingEntireBlocks.getSelectionStartPoint;
77
- exports.getSelectionText = selector_isSelectingEntireBlocks.getSelectionText;
78
62
  exports.getTrimmedSelection = selector_isSelectingEntireBlocks.getTrimmedSelection;
79
63
  exports.isActiveAnnotation = selector_isSelectingEntireBlocks.isActiveAnnotation;
80
64
  exports.isActiveDecorator = selector_isSelectingEntireBlocks.isActiveDecorator;
@@ -86,9 +70,25 @@ exports.isOverlappingSelection = selector_isSelectingEntireBlocks.isOverlappingS
86
70
  exports.isPointAfterSelection = selector_isSelectingEntireBlocks.isPointAfterSelection;
87
71
  exports.isPointBeforeSelection = selector_isSelectingEntireBlocks.isPointBeforeSelection;
88
72
  exports.isSelectingEntireBlocks = selector_isSelectingEntireBlocks.isSelectingEntireBlocks;
89
- exports.isSelectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed;
90
- exports.isSelectionExpanded = selector_isSelectingEntireBlocks.isSelectionExpanded;
91
- exports.getFocusInlineObject = selector_getFocusInlineObject.getFocusInlineObject;
73
+ exports.getFirstBlock = selector_isSelectionExpanded.getFirstBlock;
74
+ exports.getFocusBlock = selector_isSelectionExpanded.getFocusBlock;
75
+ exports.getFocusBlockObject = selector_isSelectionExpanded.getFocusBlockObject;
76
+ exports.getFocusChild = selector_isSelectionExpanded.getFocusChild;
77
+ exports.getFocusListBlock = selector_isSelectionExpanded.getFocusListBlock;
78
+ exports.getFocusSpan = selector_isSelectionExpanded.getFocusSpan;
79
+ exports.getFocusTextBlock = selector_isSelectionExpanded.getFocusTextBlock;
80
+ exports.getLastBlock = selector_isSelectionExpanded.getLastBlock;
81
+ exports.getNextBlock = selector_isSelectionExpanded.getNextBlock;
82
+ exports.getPreviousBlock = selector_isSelectionExpanded.getPreviousBlock;
83
+ exports.getPreviousInlineObject = selector_isSelectionExpanded.getPreviousInlineObject;
84
+ exports.getSelectedBlocks = selector_isSelectionExpanded.getSelectedBlocks;
85
+ exports.getSelectedSlice = selector_isSelectionExpanded.getSelectedSlice;
86
+ exports.getSelectionEndBlock = selector_isSelectionExpanded.getSelectionEndBlock;
87
+ exports.getSelectionStartBlock = selector_isSelectionExpanded.getSelectionStartBlock;
88
+ exports.getSelectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint;
89
+ exports.getSelectionText = selector_isSelectionExpanded.getSelectionText;
90
+ exports.isSelectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed;
91
+ exports.isSelectionExpanded = selector_isSelectionExpanded.isSelectionExpanded;
92
92
  exports.getBlockTextBefore = selector_getTextBefore.getBlockTextBefore;
93
93
  exports.getAnchorBlock = getAnchorBlock;
94
94
  exports.getAnchorChild = getAnchorChild;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","key","context","selection","isKeyedSegment","anchor","path","_key","undefined","node","value","find","block","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue"],"mappings":";;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,iBAAAA,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMC,CAAAA,UAAUA,MAAML,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GCbaK,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,iBAAAA,YAAYf,SAASE,SAASY,YAAYL,IAAI,IAChE;AAAA,IAACA,MAAMK,YAAYL;AAAAA,IAAMH,MAAMQ,YAAYR;AAAAA,EAAAA,IAC3CE;AACN,GCPaQ,iBAMRhB,CAAa,aAAA;AACVc,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMb,MAAMD,SAASE,QAAQC,aACzBC,iBAAAA,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTa,YAAYL,KAAKQ,SAASN,KAAMO,CAAAA,SAASA,KAAKX,SAASN,GAAG,IAC1DO;AAEJ,SAAOC,QAAQR,MACX;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC,GAAGQ,YAAYR,MAAM,YAAY;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAC1DO;AACN,GC3BaW,gBAGRnB,CAAa,aAAA;AACVoB,QAAAA,cAAcJ,eAAehB,QAAQ;AAE3C,SAAOoB,eAAeC,MAAAA,mBAAmBD,YAAYX,IAAI,IACrD;AAAA,IAACA,MAAMW,YAAYX;AAAAA,IAAMH,MAAMc,YAAYd;AAAAA,EAAAA,IAC3CE;AACN,GCRac,kBAERtB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASE,QAAQC;AACpB;AAGF,QAAMoB,sBAAsBC,iCAAAA,uBAAuBxB,QAAQ,GACrDyB,oBAAoBC,sDAAqB1B,QAAQ;AAEnD,MAAA,CAACuB,uBAAuB,CAACE;AAC3B;AAGIE,QAAAA,QAAQC,iBAAAA,gCAAsC;AAAA,IAClD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBN;AAAAA,EAAAA,CACjB,GACKO,MAAMF,iDAAsC;AAAA,IAChD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBJ;AAAAA,EAAAA,CACjB;AAED,SAAOE,SAASG,MAAM;AAAA,IAACH;AAAAA,IAAOG;AAAAA,EAAAA,IAAOtB;AACvC,GC3BauB,eAAiD/B,CACrDA,aAAAA,SAASE,QAAQC,WCDb6B,WACXhC,CAEOA,aAAAA,SAASE,QAAQQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","key","context","selection","isKeyedSegment","anchor","path","_key","undefined","node","value","find","block","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue"],"mappings":";;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,iBAAAA,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMC,CAAAA,UAAUA,MAAML,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GCbaK,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,iBAAAA,YAAYf,SAASE,SAASY,YAAYL,IAAI,IAChE;AAAA,IAACA,MAAMK,YAAYL;AAAAA,IAAMH,MAAMQ,YAAYR;AAAAA,EAAAA,IAC3CE;AACN,GCPaQ,iBAMRhB,CAAa,aAAA;AACVc,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMb,MAAMD,SAASE,QAAQC,aACzBC,iBAAAA,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTa,YAAYL,KAAKQ,SAASN,KAAMO,CAAAA,SAASA,KAAKX,SAASN,GAAG,IAC1DO;AAEJ,SAAOC,QAAQR,MACX;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC,GAAGQ,YAAYR,MAAM,YAAY;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAC1DO;AACN,GC3BaW,gBAGRnB,CAAa,aAAA;AACVoB,QAAAA,cAAcJ,eAAehB,QAAQ;AAE3C,SAAOoB,eAAeC,MAAAA,mBAAmBD,YAAYX,IAAI,IACrD;AAAA,IAACA,MAAMW,YAAYX;AAAAA,IAAMH,MAAMc,YAAYd;AAAAA,EAAAA,IAC3CE;AACN,GCRac,kBAERtB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASE,QAAQC;AACpB;AAGF,QAAMoB,sBAAsBC,6BAAAA,uBAAuBxB,QAAQ,GACrDyB,oBAAoBC,sDAAqB1B,QAAQ;AAEnD,MAAA,CAACuB,uBAAuB,CAACE;AAC3B;AAGIE,QAAAA,QAAQC,iBAAAA,gCAAsC;AAAA,IAClD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBN;AAAAA,EAAAA,CACjB,GACKO,MAAMF,iDAAsC;AAAA,IAChD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBJ;AAAAA,EAAAA,CACjB;AAED,SAAOE,SAASG,MAAM;AAAA,IAACH;AAAAA,IAAOG;AAAAA,EAAAA,IAAOtB;AACvC,GC3BauB,eAAiD/B,CACrDA,aAAAA,SAASE,QAAQC,WCDb6B,WACXhC,CAEOA,aAAAA,SAASE,QAAQQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,8 +1,9 @@
1
- import { getSelectionStartPoint, getSelectionEndPoint } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
2
- import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
1
+ import { getSelectionEndPoint } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
2
+ import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFocusInlineObject, getNextInlineObject, getSelectedSpans, getSelectedTextBlocks, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
3
3
  import { isKeyedSegment, isTextBlock, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
4
4
  import { isPortableTextSpan } from "@sanity/types";
5
- import { getFocusInlineObject } from "../_chunks-es/selector.get-focus-inline-object.js";
5
+ import { getSelectionStartPoint } from "../_chunks-es/selector.is-selection-expanded.js";
6
+ import { getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-selection-expanded.js";
6
7
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
7
8
  const getAnchorBlock = (snapshot) => {
8
9
  const key = snapshot.context.selection && isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","key","context","selection","isKeyedSegment","anchor","path","_key","undefined","node","value","find","block","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue"],"mappings":";;;;;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMC,CAAAA,UAAUA,MAAML,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GCbaK,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,YAAYf,SAASE,SAASY,YAAYL,IAAI,IAChE;AAAA,IAACA,MAAMK,YAAYL;AAAAA,IAAMH,MAAMQ,YAAYR;AAAAA,EAAAA,IAC3CE;AACN,GCPaQ,iBAMRhB,CAAa,aAAA;AACVc,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMb,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTa,YAAYL,KAAKQ,SAASN,KAAMO,CAAAA,SAASA,KAAKX,SAASN,GAAG,IAC1DO;AAEJ,SAAOC,QAAQR,MACX;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC,GAAGQ,YAAYR,MAAM,YAAY;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAC1DO;AACN,GC3BaW,gBAGRnB,CAAa,aAAA;AACVoB,QAAAA,cAAcJ,eAAehB,QAAQ;AAE3C,SAAOoB,eAAeC,mBAAmBD,YAAYX,IAAI,IACrD;AAAA,IAACA,MAAMW,YAAYX;AAAAA,IAAMH,MAAMc,YAAYd;AAAAA,EAAAA,IAC3CE;AACN,GCRac,kBAERtB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASE,QAAQC;AACpB;AAGF,QAAMoB,sBAAsBC,uBAAuBxB,QAAQ,GACrDyB,oBAAoBC,qBAAqB1B,QAAQ;AAEnD,MAAA,CAACuB,uBAAuB,CAACE;AAC3B;AAGIE,QAAAA,QAAQC,gCAAsC;AAAA,IAClD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBN;AAAAA,EAAAA,CACjB,GACKO,MAAMF,gCAAsC;AAAA,IAChD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBJ;AAAAA,EAAAA,CACjB;AAED,SAAOE,SAASG,MAAM;AAAA,IAACH;AAAAA,IAAOG;AAAAA,EAAAA,IAAOtB;AACvC,GC3BauB,eAAiD/B,CACrDA,aAAAA,SAASE,QAAQC,WCDb6B,WACXhC,CAEOA,aAAAA,SAASE,QAAQQ;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","key","context","selection","isKeyedSegment","anchor","path","_key","undefined","node","value","find","block","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue"],"mappings":";;;;;;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMC,CAAAA,UAAUA,MAAML,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GCbaK,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,YAAYf,SAASE,SAASY,YAAYL,IAAI,IAChE;AAAA,IAACA,MAAMK,YAAYL;AAAAA,IAAMH,MAAMQ,YAAYR;AAAAA,EAAAA,IAC3CE;AACN,GCPaQ,iBAMRhB,CAAa,aAAA;AACVc,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMb,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTa,YAAYL,KAAKQ,SAASN,KAAMO,CAAAA,SAASA,KAAKX,SAASN,GAAG,IAC1DO;AAEJ,SAAOC,QAAQR,MACX;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC,GAAGQ,YAAYR,MAAM,YAAY;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAC1DO;AACN,GC3BaW,gBAGRnB,CAAa,aAAA;AACVoB,QAAAA,cAAcJ,eAAehB,QAAQ;AAE3C,SAAOoB,eAAeC,mBAAmBD,YAAYX,IAAI,IACrD;AAAA,IAACA,MAAMW,YAAYX;AAAAA,IAAMH,MAAMc,YAAYd;AAAAA,EAAAA,IAC3CE;AACN,GCRac,kBAERtB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASE,QAAQC;AACpB;AAGF,QAAMoB,sBAAsBC,uBAAuBxB,QAAQ,GACrDyB,oBAAoBC,qBAAqB1B,QAAQ;AAEnD,MAAA,CAACuB,uBAAuB,CAACE;AAC3B;AAGIE,QAAAA,QAAQC,gCAAsC;AAAA,IAClD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBN;AAAAA,EAAAA,CACjB,GACKO,MAAMF,gCAAsC;AAAA,IAChD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBJ;AAAAA,EAAAA,CACjB;AAED,SAAOE,SAASG,MAAM;AAAA,IAACH;AAAAA,IAAOG;AAAAA,EAAAA,IAAOtB;AACvC,GC3BauB,eAAiD/B,CACrDA,aAAAA,SAASE,QAAQC,WCDb6B,WACXhC,CAEOA,aAAAA,SAASE,QAAQQ;"}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), util_selectionPointToBlockOffset = require("../_chunks-cjs/util.selection-point-to-block-offset.cjs"), util_isSelectionCollapsed = require("../_chunks-cjs/util.is-selection-collapsed.cjs"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
3
+ var util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_isEqualSelectionPoints = require("../_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("../_chunks-cjs/util.selection-point-to-block-offset.cjs"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
4
4
  function isEqualSelections(a, b) {
5
- return !a && !b ? !0 : !a || !b ? !1 : util_sliceBlocks.isEqualSelectionPoints(a.anchor, b.anchor) && util_sliceBlocks.isEqualSelectionPoints(a.focus, b.focus);
5
+ return !a && !b ? !0 : !a || !b ? !1 : util_isEqualSelectionPoints.isEqualSelectionPoints(a.anchor, b.anchor) && util_isEqualSelectionPoints.isEqualSelectionPoints(a.focus, b.focus);
6
6
  }
7
7
  function splitTextBlock({
8
8
  context,
@@ -52,24 +52,24 @@ function splitTextBlock({
52
52
  };
53
53
  }
54
54
  exports.blockOffsetToSpanSelectionPoint = util_sliceBlocks.blockOffsetToSpanSelectionPoint;
55
- exports.getBlockEndPoint = util_sliceBlocks.getBlockEndPoint;
56
55
  exports.getBlockStartPoint = util_sliceBlocks.getBlockStartPoint;
57
56
  exports.getTextBlockText = util_sliceBlocks.getTextBlockText;
58
- exports.isEmptyTextBlock = util_sliceBlocks.isEmptyTextBlock;
59
- exports.isEqualSelectionPoints = util_sliceBlocks.isEqualSelectionPoints;
60
57
  exports.isKeyedSegment = util_sliceBlocks.isKeyedSegment;
61
58
  exports.isSpan = util_sliceBlocks.isSpan;
62
59
  exports.reverseSelection = util_sliceBlocks.reverseSelection;
63
60
  exports.sliceBlocks = util_sliceBlocks.sliceBlocks;
64
61
  exports.spanSelectionPointToBlockOffset = util_sliceBlocks.spanSelectionPointToBlockOffset;
65
- exports.blockOffsetToBlockSelectionPoint = util_selectionPointToBlockOffset.blockOffsetToBlockSelectionPoint;
66
- exports.blockOffsetToSelectionPoint = util_selectionPointToBlockOffset.blockOffsetToSelectionPoint;
67
- exports.blockOffsetsToSelection = util_selectionPointToBlockOffset.blockOffsetsToSelection;
68
- exports.childSelectionPointToBlockOffset = util_selectionPointToBlockOffset.childSelectionPointToBlockOffset;
62
+ exports.blockOffsetToBlockSelectionPoint = util_childSelectionPointToBlockOffset.blockOffsetToBlockSelectionPoint;
63
+ exports.blockOffsetToSelectionPoint = util_childSelectionPointToBlockOffset.blockOffsetToSelectionPoint;
64
+ exports.blockOffsetsToSelection = util_childSelectionPointToBlockOffset.blockOffsetsToSelection;
65
+ exports.childSelectionPointToBlockOffset = util_childSelectionPointToBlockOffset.childSelectionPointToBlockOffset;
66
+ exports.getBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint;
67
+ exports.isEmptyTextBlock = util_isEqualSelectionPoints.isEmptyTextBlock;
68
+ exports.isEqualSelectionPoints = util_isEqualSelectionPoints.isEqualSelectionPoints;
69
69
  exports.getSelectionEndPoint = util_selectionPointToBlockOffset.getSelectionEndPoint;
70
70
  exports.getSelectionStartPoint = util_selectionPointToBlockOffset.getSelectionStartPoint;
71
+ exports.isSelectionCollapsed = util_selectionPointToBlockOffset.isSelectionCollapsed;
71
72
  exports.selectionPointToBlockOffset = util_selectionPointToBlockOffset.selectionPointToBlockOffset;
72
- exports.isSelectionCollapsed = util_isSelectionCollapsed.isSelectionCollapsed;
73
73
  exports.isTextBlock = util_mergeTextBlocks.isTextBlock;
74
74
  exports.mergeTextBlocks = util_mergeTextBlocks.mergeTextBlocks;
75
75
  exports.isEqualSelections = isEqualSelections;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n blocks: [block],\n }).at(0)\n const after = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n blocks: [block],\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","schema","selection","path","_key","offset","blocks","after","isSpan","text","isTextBlock"],"mappings":";;;AAMgBA,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,iBAAAA,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,wCAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACTO,SAASC,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAEzD,MAAA,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,iBAAAA,YAAY;AAAA,IACzBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBC,WAAW;AAAA,QACTd,QAAQ;AAAA,UACNe,MAAM,CAAC;AAAA,YAACC,MAAMZ,MAAMY;AAAAA,aAAO,YAAY;AAAA,YAACA,MAAMV,WAAWU;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QACV;AAAA,QACAhB,OAAOI;AAAAA,MAAAA;AAAAA,IAEX;AAAA,IACAa,QAAQ,CAACd,KAAK;AAAA,EACf,CAAA,EAAEI,GAAG,CAAC,GACDW,QAAQP,iBAAAA,YAAY;AAAA,IACxBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBC,WAAW;AAAA,QACTd,QAAQK;AAAAA,QACRJ,OAAO;AAAA,UACLc,MAAM,CAAC;AAAA,YAACC,MAAMZ,MAAMY;AAAAA,aAAO,YAAY;AAAA,YAACA,MAAMP,UAAUO;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQG,iBAAOjB,OAAAA,SAASM,SAAS,IAAIA,UAAUY,KAAKX,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IAEJ;AAAA,IACAQ,QAAQ,CAACd,KAAK;AAAA,EAAA,CACf,EAAEI,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACQ,UAIZ,EAACG,CAAAA,qBAAAA,YAAYnB,SAASQ,MAAM,KAAK,CAACW,qBAAYnB,YAAAA,SAASgB,KAAK;AAIzD,WAAA;AAAA,MAACR;AAAAA,MAAQQ;AAAAA,IAAK;AACvB;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n blocks: [block],\n }).at(0)\n const after = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n blocks: [block],\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","schema","selection","path","_key","offset","blocks","after","isSpan","text","isTextBlock"],"mappings":";;;AAMgBA,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,4BAAAA,uBAAuBF,EAAEG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AASgB,KAAK;AAIzD,WAAA;AAAA,MAACR;AAAAA,MAAQQ;AAAAA,IAAK;AACvB;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,7 +1,9 @@
1
- import { isEqualSelectionPoints, sliceBlocks, isSpan } from "../_chunks-es/util.slice-blocks.js";
2
- import { blockOffsetToSpanSelectionPoint, getBlockEndPoint, getBlockStartPoint, getTextBlockText, isEmptyTextBlock, isKeyedSegment, reverseSelection, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
3
- import { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset, getSelectionEndPoint, getSelectionStartPoint, selectionPointToBlockOffset } from "../_chunks-es/util.selection-point-to-block-offset.js";
4
- import { isSelectionCollapsed } from "../_chunks-es/util.is-selection-collapsed.js";
1
+ import { sliceBlocks, isSpan } from "../_chunks-es/util.slice-blocks.js";
2
+ import { blockOffsetToSpanSelectionPoint, getBlockStartPoint, getTextBlockText, isKeyedSegment, reverseSelection, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
3
+ import { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset } from "../_chunks-es/util.child-selection-point-to-block-offset.js";
4
+ import { isEqualSelectionPoints } from "../_chunks-es/util.is-equal-selection-points.js";
5
+ import { getBlockEndPoint, isEmptyTextBlock } from "../_chunks-es/util.is-equal-selection-points.js";
6
+ import { getSelectionEndPoint, getSelectionStartPoint, isSelectionCollapsed, selectionPointToBlockOffset } from "../_chunks-es/util.selection-point-to-block-offset.js";
5
7
  import { isTextBlock } from "../_chunks-es/util.merge-text-blocks.js";
6
8
  import { mergeTextBlocks } from "../_chunks-es/util.merge-text-blocks.js";
7
9
  function isEqualSelections(a, b) {