API / @aionbuilders/nabu/extend

MegaBlock

Class Stability: stable Stable contract

A block that holds child blocks (a container): list, list item, toggle, region. It keeps its children in sync with the tree and delegates positions, word count and event handling to them.

Related guide: Extensions →

Import

TypeScript
import { MegaBlock } from '@aionbuilders/nabu/extend';

Extends Block

Constructor

TypeScript
new MegaBlock(nabu: Nabu, node: NabuNode)
Parameters of the constructor
ParameterTypeDescription
nabuNabun/a
nodeNabuNoden/a

Properties

children

TypeScript
children: Block[]

positions

TypeScript
positions: number

wordCount

TypeScript
wordCount: number

clipboardProps readonly

TypeScript
readonly clipboardProps: Record<string, any>

Props to include in the clipboard representation of this container block. Override in subclasses that carry structural props (e.g. List -> { listType }, ListItem -> { checked }, Toggle -> { collapsed }).

Methods

adoptChildren()

TypeScript
adoptChildren(children: Block[], index?: number | null): void
Parameters of adoptChildren
ParameterTypeDefaultDescription
childrenBlock[]n/an/a
indexoptionalnumber | nullnulln/a

beforeinput()

TypeScript
beforeinput(event: InputEvent): any
Parameters of beforeinput
ParameterTypeDescription
eventInputEventn/a

clipboardPropsFrom()

TypeScript
clipboardPropsFrom(firstChildIndex: number): Record<string, any>

Clipboard props when the copied slice starts at firstChildIndex (the children before it are NOT copied). Containers whose props depend on their first copied child (an ordered list's start) override this.

Parameters of clipboardPropsFrom
ParameterTypeDescription
firstChildIndexnumbern/a

resolveOffset()

TypeScript
resolveOffset(localOffset: number): { block: Block; offset: number } | null

Pure container: no own text, delegate entirely to children.

Parameters of resolveOffset
ParameterTypeDescription
localOffsetnumbern/a

serializeForClipboard()

TypeScript
serializeForClipboard(ctx?: object): PasteBlock | PasteBlock[] | null

Serializes the portion of this MegaBlock that falls within the given selection boundaries, recursively.

The context carries the selection boundary blocks that belong to THIS subtree (startBlock / endBlock, null = the selection extends past this block on that side, i.e. it is fully selected on that side). Document order of a block is: own text (hybrid blocks only), then its children. So:

  • own text is copied unless the selection starts inside a child; it is clipped to startFrom when this block IS the start boundary, and to endTo when it IS the end boundary;
  • children are copied unless the selection ends in the own text; only those between the child holding the start boundary and the child holding the end boundary (inclusive) are kept, each one recursively clipped. A pure container (no text) simply has no own-text part. Nothing here depends on a concrete block type.

With textOnly (the context of a TEXT selection: copy, cut, drag), a block that ISOLATES its text (isolatesSelection) is transparent to a selection that is not entirely inside it: its own text is not copied and its container is not created, its selected children are returned directly (an ARRAY, to be spliced in the list of its siblings). Without it (the structure of a whole block), the container is serialized as it is.

Parameters of serializeForClipboard
ParameterTypeDefaultDescription
ctxoptionalobject{}n/a
ctx.endBlockoptionalBlock | nullnulln/a
ctx.endTooptionalnumber | nullnulln/a
ctx.startBlockoptionalBlock | nullnulln/a
ctx.startFromoptionalnumber0n/a
ctx.textOnlyoptionalbooleanfalsen/a

updateChildren()

TypeScript
updateChildren(retyped?: Set<string>): void
Parameters of updateChildren
ParameterTypeDescription
retypedoptionalSet<string>

ids whose type just changed; without it, the type of every child is checked

Inherited

From Block behaviors, component, element, id, index, isIntermediate, isolatesSelection, isSelectionEnd, isSelectionStart, marksEnabled, nabu, next, node, parent, parents, pastesAsPlainText, placeholder, previous, selected, selection, serializers, splitsOnEnter, transformsEnabled, type, fromHTML, fromMarkdown, htmlRules, htmlSiblings, markdownRules, toHtml, toMarkdown, adoptsPastedTypes, hidesChildren, requiredParent, absorbs, acceptPaste, ascend, clearSelection, commit, consume, delete, destroy, dragRange, findBackward, findForward, findLastDescendant, focus, getAdjacentSiblings, getDOMPoint, insert, keydown, mergeWith, retype, serialize, split, transformTo, create, load

Source: src/lib/blocks/megablock.svelte.js:11