UNPKG

lib0

Version:

isomorphic utility functions

69 lines • 4.33 kB
/** * Stateful transformer that descends one level into a node's child *nodes* and applies a per-child * sub-transformer, chosen by `handler`. Attributes and text pass through untouched. Designed to be * applied recursively (see {@link children}). * * The per-child sub-transformer instances are kept in {@link ChildrenTransformer#childTs}, positionally * aligned to the parent's child list (children carry no stable id - identity is positional). `children` * never changes the child count at its own level, so side A and side B stay aligned position-for- * position and the same `childTs` indexes both directions. * * `childTs` is a sparse positional map kept as a delta: each transformed child is an `insert([t])` op * holding its sub-transformer; every other position (text runs, opted-out nodes) is a coalesced * `retain(n)` gap. A run of N text characters costs one retain op, not N array slots. It is walked with * a forward cursor in step with the change (see {@link ChildrenTransformer#transform}). Transformer * instances are carried by reference across rebuilds, so their per-instance state survives. * * @extends {Transformer<any,any>} */ export class ChildrenTransformer extends Transformer<any, any> { /** * @param {import('../../schema.js').Schema<delta.Delta<any>>} $in * @param {import('../../schema.js').Schema<delta.Delta<any>>} $out * @param {(child: delta.DeltaAny, $child: import('../../schema.js').Schema<delta.DeltaAny>) => Template | null} handler * picks the (schema-bound) template for a child node, or `null` to leave it untransformed. Evaluated * once, when the child is inserted, with the derived per-child schema. * @param {import('../../schema.js').Schema<delta.DeltaAny>} childSchema per-child-node schema each * sub-template is built against (derived from the parent's input schema; `$deltaAny` when not derivable). */ constructor($in: import("../../schema.js").Schema<delta.Delta<any>>, $out: import("../../schema.js").Schema<delta.Delta<any>>, handler: (child: delta.DeltaAny, $child: import("../../schema.js").Schema<delta.DeltaAny>) => Template | null, childSchema: import("../../schema.js").Schema<delta.DeltaAny>); handler: (child: delta.DeltaAny, $child: import("../../schema.js").Schema<delta.DeltaAny>) => Template | null; /** * Sparse positional map of sub-transformers: `insert([t])` at each transformed child, `retain(n)` * over gaps (text and opted-out nodes). * * @type {delta.DeltaBuilderAny} */ childTs: delta.DeltaBuilderAny; childSchema: import("../../schema.js").Schema<delta.DeltaAny>; /** * @param {delta.DeltaBuilderAny} d the change to map * @param {boolean} fwd `true` maps side A -> B (applying sub-transformers' `applyA`), `false` maps * side B -> A. `children` is 1:1 over children, so the same `childTs` indexes both directions. * @return {import('./core.js').TransformResultAny} */ transform(d: delta.DeltaBuilderAny, fwd: boolean): import("./core.js").TransformResultAny; } /** * Template for {@link ChildrenTransformer}. * * @template {delta.DeltaConf} [IN=any] * @extends {Template<IN, any>} */ export class Children<IN extends delta.DeltaConf = any> extends Template<IN, any> { /** * @param {import('../../schema.js').Schema<delta.Delta<IN>>} $d * @param {(child: delta.DeltaAny, $child: import('../../schema.js').Schema<delta.DeltaAny>) => Template | null} handler */ constructor($d: import("../../schema.js").Schema<delta.Delta<IN>>, handler: (child: delta.DeltaAny, $child: import("../../schema.js").Schema<delta.DeltaAny>) => Template | null); handler: (child: delta.DeltaAny, $child: import("../../schema.js").Schema<delta.DeltaAny>) => Template | null; /** * @type {import('../../schema.js').Schema<delta.DeltaAny>} */ childSchema: import("../../schema.js").Schema<delta.DeltaAny>; } export function children<IN extends delta.DeltaConf>($d: import("../../schema.js").Schema<delta.Delta<IN>>, handler: (child: delta.DeltaAny, $child: import("../../schema.js").Schema<delta.DeltaAny>) => Template | null): Children<IN>; import { Transformer } from './core.js'; import * as delta from '../delta.js'; import { Template } from './core.js'; //# sourceMappingURL=children.d.ts.map