Skip to content

Commit 9568758

Browse files
committed
fix(context): add child uuids to context of block
1 parent fe9a2d9 commit 9568758

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/context.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export class BlockContext extends Context {
284284
public prevBlock?: BlockContext | null
285285
public level?: number
286286

287-
public children?: ({} | BlockContext)[]
287+
public children?: (string | BlockContext)[]
288288
public refs?: {id: number}[]
289289

290290
static createFromEntity(block: BlockEntity, args: {
@@ -322,12 +322,12 @@ export class BlockContext extends Context {
322322
obj.level = args.level ?? 0
323323
const rootLevel: number = obj.level
324324

325-
obj.children = block.children ?? []
326-
if (obj.children.length > 0) {
327-
if (Array.isArray(obj.children[0])) // non-tree mode: get only children count
328-
obj.children = Array(obj.children.length).fill({})
325+
const children = block.children ?? []
326+
if (children.length > 0) {
327+
if (Array.isArray(children[0])) // non-tree mode: fill only with UUIDs
328+
obj.children = (children as [string, string][]).map(([_, uuid]) => uuid)
329329
else // tree mode
330-
obj.children = obj.children.map(
330+
obj.children = children.map(
331331
b => BlockContext.createFromEntity(b as BlockEntity, {
332332
level: rootLevel + 1,
333333
page: obj.page,

src/logic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function getCurrentContext(
6666
}
6767

6868
let currentPage: PageEntity | null
69-
const currentBlock = await logseq.Editor.getBlock(blockOrPageUUID)
69+
const currentBlock = await logseq.Editor.getBlock(blockOrPageUUID, {includeChildren: true})
7070
if (currentBlock)
7171
currentPage = await logseq.Editor.getPage(currentBlock.page.id)
7272
else {

src/tags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ function blocks_uuid(context: C) {
526526

527527
const isHeadTemplateBlock = context.template!.includingParent
528528
? context.template!.block.id === context.self!.id
529-
: (context.template!.block.children![0] as BlockEntity).id === context.self!.id
529+
: (context.template!.block.children![0] as unknown as BlockEntity).id === context.self!.id
530530

531531
const uuid = isHeadTemplateBlock
532532
? context.currentBlock.uuid!

0 commit comments

Comments
 (0)