MegaBlock
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
import { MegaBlock } from '@aionbuilders/nabu/extend';Constructor
new MegaBlock(nabu: Nabu, node: NabuNode)| Parameter | Type | Description |
|---|---|---|
nabu | Nabu | n/a |
node | NabuNode | n/a |
Properties
children
children: Block[]positions
positions: numberwordCount
wordCount: numberclipboardProps readonly
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()
adoptChildren(children: Block[], index?: number | null): void| Parameter | Type | Default | Description |
|---|---|---|---|
children | Block[] | n/a | n/a |
indexoptional | number | null | null | n/a |
beforeinput()
beforeinput(event: InputEvent): any| Parameter | Type | Description |
|---|---|---|
event | InputEvent | n/a |
clipboardPropsFrom()
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.
| Parameter | Type | Description |
|---|---|---|
firstChildIndex | number | n/a |
resolveOffset()
resolveOffset(localOffset: number): { block: Block; offset: number } | nullPure container: no own text, delegate entirely to children.
| Parameter | Type | Description |
|---|---|---|
localOffset | number | n/a |
serializeForClipboard()
serializeForClipboard(ctx?: object): PasteBlock | PasteBlock[] | nullSerializes 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
startFromwhen this block IS the start boundary, and toendTowhen 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
ctxoptional | object | {} | n/a |
ctx.endBlockoptional | Block | null | null | n/a |
ctx.endTooptional | number | null | null | n/a |
ctx.startBlockoptional | Block | null | null | n/a |
ctx.startFromoptional | number | 0 | n/a |
ctx.textOnlyoptional | boolean | false | n/a |
updateChildren()
updateChildren(retyped?: Set<string>): void| Parameter | Type | Description |
|---|---|---|
retypedoptional | Set<string> | ids whose |
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