diff --git a/src/context.ts b/src/context.ts index b6786c5..367db6b 100644 --- a/src/context.ts +++ b/src/context.ts @@ -284,7 +284,7 @@ export class BlockContext extends Context { public prevBlock?: BlockContext | null public level?: number - public children?: ({} | BlockContext)[] + public children?: (string | BlockContext)[] public refs?: {id: number}[] static createFromEntity(block: BlockEntity, args: { @@ -322,12 +322,12 @@ export class BlockContext extends Context { obj.level = args.level ?? 0 const rootLevel: number = obj.level - obj.children = block.children ?? [] - if (obj.children.length > 0) { - if (Array.isArray(obj.children[0])) // non-tree mode: get only children count - obj.children = Array(obj.children.length).fill({}) + const children = block.children ?? [] + if (children.length > 0) { + if (Array.isArray(children[0])) // non-tree mode: fill only with UUIDs + obj.children = (children as [string, string][]).map(([_, uuid]) => uuid) else // tree mode - obj.children = obj.children.map( + obj.children = children.map( b => BlockContext.createFromEntity(b as BlockEntity, { level: rootLevel + 1, page: obj.page, diff --git a/src/logic.ts b/src/logic.ts index 877a4a3..48d6886 100644 --- a/src/logic.ts +++ b/src/logic.ts @@ -66,7 +66,7 @@ async function getCurrentContext( } let currentPage: PageEntity | null - const currentBlock = await logseq.Editor.getBlock(blockOrPageUUID) + const currentBlock = await logseq.Editor.getBlock(blockOrPageUUID, {includeChildren: true}) if (currentBlock) currentPage = await logseq.Editor.getPage(currentBlock.page.id) else { diff --git a/src/tags.ts b/src/tags.ts index e9cc9ac..7eee3bf 100644 --- a/src/tags.ts +++ b/src/tags.ts @@ -526,7 +526,7 @@ function blocks_uuid(context: C) { const isHeadTemplateBlock = context.template!.includingParent ? context.template!.block.id === context.self!.id - : (context.template!.block.children![0] as BlockEntity).id === context.self!.id + : (context.template!.block.children![0] as unknown as BlockEntity).id === context.self!.id const uuid = isHeadTemplateBlock ? context.currentBlock.uuid!