diff --git a/packages/core/src/helpers/defaultBlockAt.ts b/packages/core/src/helpers/defaultBlockAt.ts new file mode 100644 index 00000000..977cb798 --- /dev/null +++ b/packages/core/src/helpers/defaultBlockAt.ts @@ -0,0 +1,13 @@ +import { ContentMatch, NodeType } from 'prosemirror-model' + +export default function defaultBlockAt(match: ContentMatch): NodeType | null { + for (let i = 0; i < match.edgeCount; i += 1) { + const { type } = match.edge(i) + + if (type.isTextblock && !type.hasRequiredAttrs()) { + return type + } + } + + return null +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 8c622edc..38059236 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -23,6 +23,7 @@ export { default as textPasteRule } from './pasteRules/textPasteRule' export { default as callOrReturn } from './utilities/callOrReturn' export { default as mergeAttributes } from './utilities/mergeAttributes' +export { default as defaultBlockAt } from './helpers/defaultBlockAt' export { default as getExtensionField } from './helpers/getExtensionField' export { default as findChildren } from './helpers/findChildren' export { default as findChildrenInRange } from './helpers/findChildrenInRange'