@portabletext/editor 1.33.4 → 1.33.6
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.
- package/lib/_chunks-cjs/behavior.core.cjs +14 -8
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +20 -12
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/plugin.event-listener.cjs +82 -68
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs +103 -46
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +14 -8
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +20 -12
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/plugin.event-listener.js +87 -72
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js +102 -46
- package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
- package/lib/behaviors/index.d.cts +1 -33
- package/lib/behaviors/index.d.ts +1 -33
- package/lib/index.d.cts +162 -1496
- package/lib/index.d.ts +162 -1496
- package/lib/plugins/index.d.cts +162 -1496
- package/lib/plugins/index.d.ts +162 -1496
- package/package.json +9 -9
- package/src/behavior-actions/behavior.action.block.set.ts +48 -5
- package/src/behavior-actions/behavior.action.block.unset.ts +77 -3
- package/src/behavior-actions/behavior.actions.ts +1 -18
- package/src/behaviors/behavior.core.lists.ts +18 -14
- package/src/behaviors/behavior.markdown.ts +14 -12
- package/src/behaviors/behavior.types.ts +1 -13
- package/src/converters/converter.portable-text.deserialize.test.ts +3 -2
- package/src/internal-utils/parse-blocks.test.ts +455 -0
- package/src/internal-utils/parse-blocks.ts +202 -87
- package/src/behavior-actions/behavior.action.text-block.set.ts +0 -25
- package/src/behavior-actions/behavior.action.text-block.unset.ts +0 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"behavior.markdown.js","sources":["../../src/behaviors/behavior.markdown.ts"],"sourcesContent":["import {isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\nimport * as selectors from '../selectors'\nimport {getBlockTextBefore} from '../selectors/selector.get-text-before'\nimport {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\nimport {getTextBlockText} from '../utils/util.get-text-block-text'\nimport {defineBehavior} from './behavior.types'\n\n/**\n * @beta\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\n/**\n * @beta\n * Create 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 {createMarkdownBehaviors, coreBehaviors} from '@portabletext/editor/behaviors'\n *\n * function App() {\n * return (\n * <EditorProvider\n * initialConfig={{\n * behaviors: [\n * ...coreBehaviors,\n * ...createMarkdownBehaviors({\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 * >\n * {...}\n * </EditorProvider>\n * )\n * }\n * ```\n *\n */\nexport function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {\n const automaticBlockquoteOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({context, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject({context})\n const blockOffset = spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: 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?.(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 {\n type: 'insert.text',\n text: ' ',\n },\n ],\n (_, {focusTextBlock, style}) => [\n {\n type: 'text block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n },\n {\n type: 'text block.set',\n style,\n at: focusTextBlock.path,\n },\n {\n type: 'delete.text',\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 const automaticHr = defineBehavior({\n on: 'insert.text',\n guard: ({context, 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?.(context)\n const focusBlock = selectors.getFocusTextBlock({context})\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n\n if (!hrObject || !focusBlock || !selectionCollapsed) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject({context})\n const textBefore = getBlockTextBefore({context})\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 {\n type: 'insert.text',\n text: hrCharacter,\n },\n ],\n (_, {hrObject, hrBlockOffsets}) => [\n {\n type: 'insert.block object',\n placement: 'before',\n blockObject: hrObject,\n },\n {\n type: 'delete.text',\n ...hrBlockOffsets,\n },\n ],\n ],\n })\n const automaticHrOnPaste = defineBehavior({\n on: 'paste',\n guard: ({context, event}) => {\n const text = event.data.getData('text/plain')\n const hrRegExp = /^(---)$|(___)$|(\\*\\*\\*)$/gm\n const hrCharacters = text.match(hrRegExp)?.[0]\n const hrObject = config.horizontalRuleObject?.(context)\n const focusBlock = selectors.getFocusBlock({context})\n\n if (!hrCharacters || !hrObject || !focusBlock) {\n return false\n }\n\n return {hrCharacters, hrObject, focusBlock}\n },\n actions: [\n (_, {hrCharacters}) => [\n {\n type: 'insert.text',\n text: hrCharacters,\n },\n ],\n (_, {hrObject, focusBlock}) =>\n isPortableTextTextBlock(focusBlock.node)\n ? [\n {\n type: 'insert.text block',\n textBlock: {children: focusBlock.node.children},\n placement: 'after',\n },\n {\n type: 'insert.block object',\n blockObject: hrObject,\n placement: 'after',\n },\n {type: 'delete.block', blockPath: focusBlock.path},\n ]\n : [\n {\n type: 'insert.block object',\n blockObject: hrObject,\n placement: 'after',\n },\n ],\n ],\n })\n const automaticHeadingOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({context, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const blockOffset = spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: context.selection?.focus.offset ?? 0,\n },\n })\n\n if (!blockOffset) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject({context})\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: 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}) => [event],\n (_, {focusTextBlock, style, level}) => [\n {\n type: 'text block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n },\n {\n type: 'text block.set',\n style,\n at: focusTextBlock.path,\n },\n {\n type: 'delete.text',\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 const clearStyleOnBackspace = defineBehavior({\n on: 'delete.backward',\n guard: ({context}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const atTheBeginningOfBLock =\n focusTextBlock.node.children[0]._key === focusSpan.node._key &&\n context.selection?.focus.offset === 0\n\n const defaultStyle = config.defaultStyle?.(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 {\n type: 'text block.set',\n style: defaultStyle,\n at: focusTextBlock.path,\n },\n ],\n ],\n })\n const automaticListOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({context, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject({context})\n const blockOffset = spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: 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?.(context)\n const looksLikeUnorderedList = /^(-|\\*)/.test(blockText)\n const unorderedListStyle = config.unorderedListStyle?.(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?.(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}) => [event],\n (_, {focusTextBlock, style, listItem, listItemLength}) => [\n {\n type: 'text block.set',\n listItem,\n level: 1,\n style,\n at: focusTextBlock.path,\n },\n {\n type: 'delete.text',\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 const markdownBehaviors = [\n automaticBlockquoteOnSpace,\n automaticHeadingOnSpace,\n automaticHr,\n automaticHrOnPaste,\n clearStyleOnBackspace,\n automaticListOnSpace,\n ]\n\n return markdownBehaviors\n}\n"],"names":["createMarkdownBehaviors","config","automaticBlockquoteOnSpace","defineBehavior","on","guard","context","event","text","selectionCollapsed","selectors","focusTextBlock","focusSpan","previousInlineObject","blockOffset","spanSelectionPointToBlockOffset","value","selectionPoint","path","_key","node","offset","selection","focus","blockText","getTextBlockText","caretAtTheEndOfQuote","looksLikeMarkdownQuote","test","blockquoteStyle","undefined","style","actions","type","_","props","at","anchor","automaticHr","hrCharacter","hrObject","horizontalRuleObject","focusBlock","textBefore","getBlockTextBefore","hrBlockOffsets","placement","blockObject","automaticHrOnPaste","data","getData","hrRegExp","hrCharacters","match","isPortableTextTextBlock","textBlock","children","blockPath","automaticHeadingOnSpace","markdownHeadingSearch","exec","level","length","caretAtTheEndOfHeading","headingStyle","schema","clearStyleOnBackspace","atTheBeginningOfBLock","defaultStyle","automaticListOnSpace","looksLikeUnorderedList","unorderedListStyle","caretAtTheEndOfUnorderedList","listItem","listItemLength","looksLikeOrderedList","orderedListStyle","caretAtTheEndOfOrderedList"],"mappings":";;;;;AAsEO,SAASA,wBAAwBC,QAAiC;AACvE,QAAMC,6BAA6BC,eAAe;AAA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U,oBACAkB,uBACAG,oBAAoB;AAIxB;"}
|
|
1
|
+
{"version":3,"file":"behavior.markdown.js","sources":["../../src/behaviors/behavior.markdown.ts"],"sourcesContent":["import {isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\nimport * as selectors from '../selectors'\nimport {getBlockTextBefore} from '../selectors/selector.get-text-before'\nimport {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\nimport {getTextBlockText} from '../utils/util.get-text-block-text'\nimport {defineBehavior} from './behavior.types'\n\n/**\n * @beta\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\n/**\n * @beta\n * Create 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 {createMarkdownBehaviors, coreBehaviors} from '@portabletext/editor/behaviors'\n *\n * function App() {\n * return (\n * <EditorProvider\n * initialConfig={{\n * behaviors: [\n * ...coreBehaviors,\n * ...createMarkdownBehaviors({\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 * >\n * {...}\n * </EditorProvider>\n * )\n * }\n * ```\n *\n */\nexport function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {\n const automaticBlockquoteOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({context, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject({context})\n const blockOffset = spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: 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?.(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 {\n type: 'insert.text',\n text: ' ',\n },\n ],\n (_, {focusTextBlock, style}) => [\n {\n type: 'block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n },\n {\n type: 'block.set',\n props: {style},\n at: focusTextBlock.path,\n },\n {\n type: 'delete.text',\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 const automaticHr = defineBehavior({\n on: 'insert.text',\n guard: ({context, 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?.(context)\n const focusBlock = selectors.getFocusTextBlock({context})\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n\n if (!hrObject || !focusBlock || !selectionCollapsed) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject({context})\n const textBefore = getBlockTextBefore({context})\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 {\n type: 'insert.text',\n text: hrCharacter,\n },\n ],\n (_, {hrObject, hrBlockOffsets}) => [\n {\n type: 'insert.block object',\n placement: 'before',\n blockObject: hrObject,\n },\n {\n type: 'delete.text',\n ...hrBlockOffsets,\n },\n ],\n ],\n })\n const automaticHrOnPaste = defineBehavior({\n on: 'paste',\n guard: ({context, event}) => {\n const text = event.data.getData('text/plain')\n const hrRegExp = /^(---)$|(___)$|(\\*\\*\\*)$/gm\n const hrCharacters = text.match(hrRegExp)?.[0]\n const hrObject = config.horizontalRuleObject?.(context)\n const focusBlock = selectors.getFocusBlock({context})\n\n if (!hrCharacters || !hrObject || !focusBlock) {\n return false\n }\n\n return {hrCharacters, hrObject, focusBlock}\n },\n actions: [\n (_, {hrCharacters}) => [\n {\n type: 'insert.text',\n text: hrCharacters,\n },\n ],\n (_, {hrObject, focusBlock}) =>\n isPortableTextTextBlock(focusBlock.node)\n ? [\n {\n type: 'insert.text block',\n textBlock: {children: focusBlock.node.children},\n placement: 'after',\n },\n {\n type: 'insert.block object',\n blockObject: hrObject,\n placement: 'after',\n },\n {type: 'delete.block', blockPath: focusBlock.path},\n ]\n : [\n {\n type: 'insert.block object',\n blockObject: hrObject,\n placement: 'after',\n },\n ],\n ],\n })\n const automaticHeadingOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({context, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const blockOffset = spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: context.selection?.focus.offset ?? 0,\n },\n })\n\n if (!blockOffset) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject({context})\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: 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}) => [event],\n (_, {focusTextBlock, style, level}) => [\n {\n type: 'block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n },\n {\n type: 'block.set',\n props: {style},\n at: focusTextBlock.path,\n },\n {\n type: 'delete.text',\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 const clearStyleOnBackspace = defineBehavior({\n on: 'delete.backward',\n guard: ({context}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const atTheBeginningOfBLock =\n focusTextBlock.node.children[0]._key === focusSpan.node._key &&\n context.selection?.focus.offset === 0\n\n const defaultStyle = config.defaultStyle?.(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 {\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: ({context, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject({context})\n const blockOffset = spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: 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?.(context)\n const looksLikeUnorderedList = /^(-|\\*)/.test(blockText)\n const unorderedListStyle = config.unorderedListStyle?.(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?.(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}) => [event],\n (_, {focusTextBlock, style, listItem, listItemLength}) => [\n {\n type: 'block.set',\n props: {\n listItem,\n level: 1,\n style,\n },\n at: focusTextBlock.path,\n },\n {\n type: 'delete.text',\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 const markdownBehaviors = [\n automaticBlockquoteOnSpace,\n automaticHeadingOnSpace,\n automaticHr,\n automaticHrOnPaste,\n clearStyleOnBackspace,\n automaticListOnSpace,\n ]\n\n return markdownBehaviors\n}\n"],"names":["createMarkdownBehaviors","config","automaticBlockquoteOnSpace","defineBehavior","on","guard","context","event","text","selectionCollapsed","selectors","focusTextBlock","focusSpan","previousInlineObject","blockOffset","spanSelectionPointToBlockOffset","value","selectionPoint","path","_key","node","offset","selection","focus","blockText","getTextBlockText","caretAtTheEndOfQuote","looksLikeMarkdownQuote","test","blockquoteStyle","undefined","style","actions","type","_","props","at","anchor","automaticHr","hrCharacter","hrObject","horizontalRuleObject","focusBlock","textBefore","getBlockTextBefore","hrBlockOffsets","placement","blockObject","automaticHrOnPaste","data","getData","hrRegExp","hrCharacters","match","isPortableTextTextBlock","textBlock","children","blockPath","automaticHeadingOnSpace","markdownHeadingSearch","exec","level","length","caretAtTheEndOfHeading","headingStyle","schema","clearStyleOnBackspace","atTheBeginningOfBLock","defaultStyle","automaticListOnSpace","looksLikeUnorderedList","unorderedListStyle","caretAtTheEndOfUnorderedList","listItem","listItemLength","looksLikeOrderedList","orderedListStyle","caretAtTheEndOfOrderedList"],"mappings":";;;;;AAsEO,SAASA,wBAAwBC,QAAiC;AACvE,QAAMC,6BAA6BC,eAAe;AAAA,IAChDC,IAA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QAAQqD,iBAAiB;AAAA,MAAA;AAAA,IAC3B,CACD,CACF;AAAA,EAAA,CAEJ;AAWD,SAT0B,CACxBxE,4BACAwD,yBACApB,aACAU,oBACAkB,uBACAG,oBAAoB;AAIxB;"}
|
|
@@ -14,7 +14,7 @@ import flatten from "lodash/flatten.js";
|
|
|
14
14
|
import isPlainObject from "lodash/isPlainObject.js";
|
|
15
15
|
import uniq from "lodash/uniq.js";
|
|
16
16
|
import getRandomValues from "get-random-values-esm";
|
|
17
|
-
import { parseBlock, blockOffsetsToSelection } from "./util.block-offsets-to-selection.js";
|
|
17
|
+
import { parseBlock, blockOffsetsToSelection, isTextBlock } from "./util.block-offsets-to-selection.js";
|
|
18
18
|
import { sliceBlocks, spanSelectionPointToBlockOffset } from "./util.slice-blocks.js";
|
|
19
19
|
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
20
20
|
import { toHTML } from "@portabletext/to-html";
|
|
@@ -24,6 +24,7 @@ import isUndefined from "lodash/isUndefined.js";
|
|
|
24
24
|
import omitBy from "lodash/omitBy.js";
|
|
25
25
|
import { createGuards } from "./selector.is-at-the-start-of-block.js";
|
|
26
26
|
import { getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle } from "./selector.is-active-style.js";
|
|
27
|
+
import omit from "lodash/omit.js";
|
|
27
28
|
import startCase from "lodash.startcase";
|
|
28
29
|
import { defineBehavior, raise, coreBehaviors, isCustomBehaviorEvent } from "./behavior.core.js";
|
|
29
30
|
import { Subject } from "rxjs";
|
|
@@ -2537,13 +2538,13 @@ function createOperationToPatches(types) {
|
|
|
2537
2538
|
throw new Error(`Unexpected path encountered: ${JSON.stringify(operation.path)}`);
|
|
2538
2539
|
}
|
|
2539
2540
|
function insertNodePatch(editor, operation, beforeValue) {
|
|
2540
|
-
const block = beforeValue[operation.path[0]],
|
|
2541
|
+
const block = beforeValue[operation.path[0]], isTextBlock2 = editor.isTextBlock(block);
|
|
2541
2542
|
if (operation.path.length === 1) {
|
|
2542
2543
|
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block?._key : beforeBlock?._key;
|
|
2543
2544
|
return targetKey ? [insert([fromSlateValue([operation.node], textBlockName)[0]], position, [{
|
|
2544
2545
|
_key: targetKey
|
|
2545
2546
|
}])] : [setIfMissing(beforeValue, []), insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
|
|
2546
|
-
} else if (
|
|
2547
|
+
} else if (isTextBlock2 && operation.path.length === 2 && editor.children[operation.path[0]]) {
|
|
2547
2548
|
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = {
|
|
2548
2549
|
...operation.node
|
|
2549
2550
|
};
|
|
@@ -4005,6 +4006,7 @@ function insertBlock({
|
|
|
4005
4006
|
}
|
|
4006
4007
|
}
|
|
4007
4008
|
const blockSetBehaviorActionImplementation = ({
|
|
4009
|
+
context,
|
|
4008
4010
|
action
|
|
4009
4011
|
}) => {
|
|
4010
4012
|
const location = toSlateRange({
|
|
@@ -4018,17 +4020,40 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4018
4020
|
}
|
|
4019
4021
|
}, action.editor);
|
|
4020
4022
|
if (!location)
|
|
4021
|
-
|
|
4023
|
+
throw new Error(`Unable to convert ${JSON.stringify(action.at)} into a Slate Range`);
|
|
4024
|
+
const block = Editor.node(action.editor, location, {
|
|
4025
|
+
depth: 1
|
|
4026
|
+
})?.[0];
|
|
4027
|
+
if (!block)
|
|
4028
|
+
throw new Error(`Unable to find block at ${JSON.stringify(action.at)}`);
|
|
4029
|
+
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
|
|
4030
|
+
if (!parsedBlock)
|
|
4031
|
+
throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
|
|
4022
4032
|
const {
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4033
|
+
_type,
|
|
4034
|
+
...filteredProps
|
|
4035
|
+
} = action.props, updatedBlock = parseBlock({
|
|
4036
|
+
context,
|
|
4037
|
+
block: {
|
|
4038
|
+
...parsedBlock,
|
|
4039
|
+
...filteredProps
|
|
4040
|
+
},
|
|
4041
|
+
options: {
|
|
4042
|
+
refreshKeys: !1
|
|
4043
|
+
}
|
|
4044
|
+
});
|
|
4045
|
+
if (!updatedBlock)
|
|
4046
|
+
throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
|
|
4047
|
+
const slateBlock = toSlateValue([updatedBlock], {
|
|
4048
|
+
schemaTypes: context.schema
|
|
4049
|
+
})?.at(0);
|
|
4050
|
+
if (!slateBlock)
|
|
4051
|
+
throw new Error("Unable to convert block to Slate value");
|
|
4052
|
+
Transforms.setNodes(action.editor, slateBlock, {
|
|
4029
4053
|
at: location
|
|
4030
4054
|
});
|
|
4031
4055
|
}, blockUnsetBehaviorActionImplementation = ({
|
|
4056
|
+
context,
|
|
4032
4057
|
action
|
|
4033
4058
|
}) => {
|
|
4034
4059
|
const location = toSlateRange({
|
|
@@ -4041,7 +4066,53 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4041
4066
|
offset: 0
|
|
4042
4067
|
}
|
|
4043
4068
|
}, action.editor);
|
|
4044
|
-
|
|
4069
|
+
if (!location)
|
|
4070
|
+
throw new Error(`Unable to convert ${JSON.stringify(action.at)} into a Slate Range`);
|
|
4071
|
+
const block = Editor.node(action.editor, location, {
|
|
4072
|
+
depth: 1
|
|
4073
|
+
})?.[0];
|
|
4074
|
+
if (!block)
|
|
4075
|
+
throw new Error(`Unable to find block at ${JSON.stringify(action.at)}`);
|
|
4076
|
+
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
|
|
4077
|
+
if (!parsedBlock)
|
|
4078
|
+
throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
|
|
4079
|
+
if (isTextBlock(context.schema, parsedBlock)) {
|
|
4080
|
+
const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock = parseBlock({
|
|
4081
|
+
context,
|
|
4082
|
+
block: omit(parsedBlock, propsToRemove),
|
|
4083
|
+
options: {
|
|
4084
|
+
refreshKeys: !1
|
|
4085
|
+
}
|
|
4086
|
+
});
|
|
4087
|
+
if (!updatedTextBlock)
|
|
4088
|
+
throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
|
|
4089
|
+
const propsToSet = {};
|
|
4090
|
+
for (const prop of propsToRemove)
|
|
4091
|
+
prop in updatedTextBlock ? propsToSet[prop] = updatedTextBlock[prop] : propsToSet[prop] = void 0;
|
|
4092
|
+
Transforms.setNodes(action.editor, propsToSet, {
|
|
4093
|
+
at: location
|
|
4094
|
+
});
|
|
4095
|
+
return;
|
|
4096
|
+
}
|
|
4097
|
+
const updatedBlockObject = parseBlock({
|
|
4098
|
+
context,
|
|
4099
|
+
block: omit(parsedBlock, action.props.filter((prop) => prop !== "_type")),
|
|
4100
|
+
options: {
|
|
4101
|
+
refreshKeys: !1
|
|
4102
|
+
}
|
|
4103
|
+
});
|
|
4104
|
+
if (!updatedBlockObject)
|
|
4105
|
+
throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
|
|
4106
|
+
const {
|
|
4107
|
+
_type,
|
|
4108
|
+
_key,
|
|
4109
|
+
...props
|
|
4110
|
+
} = updatedBlockObject;
|
|
4111
|
+
Transforms.setNodes(action.editor, {
|
|
4112
|
+
_type,
|
|
4113
|
+
_key,
|
|
4114
|
+
value: props
|
|
4115
|
+
}, {
|
|
4045
4116
|
at: location
|
|
4046
4117
|
});
|
|
4047
4118
|
}, dataTransferSetActionImplementation = ({
|
|
@@ -4221,48 +4292,6 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4221
4292
|
editor: action.editor,
|
|
4222
4293
|
schema: context.schema
|
|
4223
4294
|
});
|
|
4224
|
-
}, textBlockSetActionImplementation = ({
|
|
4225
|
-
action
|
|
4226
|
-
}) => {
|
|
4227
|
-
const at = toSlateRange({
|
|
4228
|
-
anchor: {
|
|
4229
|
-
path: action.at,
|
|
4230
|
-
offset: 0
|
|
4231
|
-
},
|
|
4232
|
-
focus: {
|
|
4233
|
-
path: action.at,
|
|
4234
|
-
offset: 0
|
|
4235
|
-
}
|
|
4236
|
-
}, action.editor);
|
|
4237
|
-
Transforms.setNodes(action.editor, {
|
|
4238
|
-
...action.style ? {
|
|
4239
|
-
style: action.style
|
|
4240
|
-
} : {},
|
|
4241
|
-
...action.listItem ? {
|
|
4242
|
-
listItem: action.listItem
|
|
4243
|
-
} : {},
|
|
4244
|
-
...action.level ? {
|
|
4245
|
-
level: action.level
|
|
4246
|
-
} : {}
|
|
4247
|
-
}, {
|
|
4248
|
-
at
|
|
4249
|
-
});
|
|
4250
|
-
}, textBlockUnsetActionImplementation = ({
|
|
4251
|
-
action
|
|
4252
|
-
}) => {
|
|
4253
|
-
const at = toSlateRange({
|
|
4254
|
-
anchor: {
|
|
4255
|
-
path: action.at,
|
|
4256
|
-
offset: 0
|
|
4257
|
-
},
|
|
4258
|
-
focus: {
|
|
4259
|
-
path: action.at,
|
|
4260
|
-
offset: 0
|
|
4261
|
-
}
|
|
4262
|
-
}, action.editor);
|
|
4263
|
-
Transforms.unsetNodes(action.editor, action.props, {
|
|
4264
|
-
at
|
|
4265
|
-
});
|
|
4266
4295
|
}, behaviorActionImplementations = {
|
|
4267
4296
|
"annotation.add": addAnnotationActionImplementation,
|
|
4268
4297
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
@@ -4468,9 +4497,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4468
4497
|
},
|
|
4469
4498
|
"style.toggle": toggleStyleActionImplementation,
|
|
4470
4499
|
"style.add": addStyleActionImplementation,
|
|
4471
|
-
"style.remove": removeStyleActionImplementation
|
|
4472
|
-
"text block.set": textBlockSetActionImplementation,
|
|
4473
|
-
"text block.unset": textBlockUnsetActionImplementation
|
|
4500
|
+
"style.remove": removeStyleActionImplementation
|
|
4474
4501
|
};
|
|
4475
4502
|
function performAction({
|
|
4476
4503
|
context,
|
|
@@ -4792,25 +4819,13 @@ function performDefaultAction({
|
|
|
4792
4819
|
});
|
|
4793
4820
|
break;
|
|
4794
4821
|
}
|
|
4795
|
-
|
|
4822
|
+
default: {
|
|
4796
4823
|
behaviorActionImplementations["style.toggle"]({
|
|
4797
4824
|
context,
|
|
4798
4825
|
action
|
|
4799
4826
|
});
|
|
4800
4827
|
break;
|
|
4801
4828
|
}
|
|
4802
|
-
case "text block.set": {
|
|
4803
|
-
behaviorActionImplementations["text block.set"]({
|
|
4804
|
-
context,
|
|
4805
|
-
action
|
|
4806
|
-
});
|
|
4807
|
-
break;
|
|
4808
|
-
}
|
|
4809
|
-
default:
|
|
4810
|
-
behaviorActionImplementations["text block.unset"]({
|
|
4811
|
-
context,
|
|
4812
|
-
action
|
|
4813
|
-
});
|
|
4814
4829
|
}
|
|
4815
4830
|
}
|
|
4816
4831
|
function createWithEventListeners(editorActor, subscriptions) {
|
|
@@ -5241,10 +5256,10 @@ function setPatch(editor, patch) {
|
|
|
5241
5256
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5242
5257
|
if (!block)
|
|
5243
5258
|
return debug$7("Block not found"), !1;
|
|
5244
|
-
const
|
|
5245
|
-
if (
|
|
5259
|
+
const isTextBlock2 = editor.isTextBlock(block);
|
|
5260
|
+
if (isTextBlock2 && patch.path.length > 1 && patch.path[1] !== "children")
|
|
5246
5261
|
return debug$7("Ignoring setting void value"), !1;
|
|
5247
|
-
if (debugState(editor, "before"),
|
|
5262
|
+
if (debugState(editor, "before"), isTextBlock2 && child && childPath) {
|
|
5248
5263
|
if (Text.isText(value) && Text.isText(child)) {
|
|
5249
5264
|
const newText = child.text;
|
|
5250
5265
|
value.text !== newText && (debug$7("Setting text property"), editor.apply({
|