Skip to content

Commit

Permalink
fix(context): add child uuids to context of block
Browse files Browse the repository at this point in the history
  • Loading branch information
stdword committed Oct 10, 2024
1 parent fe9a2d9 commit 9568758
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 9568758

Please sign in to comment.