Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix invalid structure blocks #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@ const groupBlockContent = (blockMap: BlockMap) => {
let index = -1

Object.keys(blockMap).forEach((id) => {
blockMap[id].value.content?.forEach((blockId) => {
const blockType = blockMap[blockId]?.value?.type
const block = blockMap[id]
if (!block || !block.value || !block.value.content) {
// Skip this block if it's undefined or doesn't have the expected structure
return
}

block.value.content.forEach((blockId) => {
const contentBlock = blockMap[blockId]
if (!contentBlock || !contentBlock.value) {
// Skip this content block if it's undefined or doesn't have the expected structure
return
}

const blockType = contentBlock.value.type

if (blockType && blockType !== lastType) {
index++
Expand All @@ -32,10 +44,10 @@ const groupBlockContent = (blockMap: BlockMap) => {

export const getListNumber = (blockId: string, blockMap: BlockMap) => {
const groups = groupBlockContent(blockMap)
const group = groups.find((g) => g.includes(blockId))
const group = groups.find((g) => g && g.includes(blockId))

if (!group) {
return
return undefined
}

return group.indexOf(blockId) + 1
Expand Down