Skip to content

Commit

Permalink
feat: add defaultBlockAt helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kühn authored and Philipp Kühn committed Nov 23, 2021
1 parent fc5757a commit 403c147
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/core/src/helpers/defaultBlockAt.ts
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 403c147

Please sign in to comment.