Filter pasted nodes

Just after posting here I found this old thread and came up with a solution that seems to work. Would be curious if that’s the correct approach.

// Must contain all allowed content node groups or types (for pasting into table)
const childNodeGroups = new Set(['list', 'image'])
const childNodeTypes = new Set(['paragraph', 'codeBlock'])

const supportedChildNode = (node) =>
	node.type.groups.some((group) => childNodeGroups.has(group))
	|| childNodeTypes.has(node.type.name)

// [...]

handlePaste: (view, _event, slice) => {
	if (!this.editor.isActive(this.type.name)) {
		return false
	}

	const { state } = view
	const { schema } = state

	const mapFragment = (fragment) => {
		Fragment.fromArray(
			fragment.content.map((node) => {
				if (!node.isText && !supportedChildNode(node)) {
					return node.textContent
						? schema.text(node.textContent, node.marks)
						: false
				} else if (node.content.childCount > 0) {
					return node.type.create(node.attrs, mapFragment(node.content))
				}
				return node
			}).filter((node) => node)
		)
	}

	slice.content = mapFragment(slice.content)
},