lib0
Version:
isomorphic utility functions
89 lines • 4.08 kB
TypeScript
/**
* Stateful transformer that inlines child nodes whose name is in the configured `names` set. Side A
* is the structured representation (inline nodes present, e.g. `<p>some<>text</></p>`), side B is the
* inlined representation (inline nodes flattened, e.g. `<p>sometext</p>`).
*
* The state the user calls "offsets and inline node length" is the segment layout {@link Seg} stored
* in `segs`: a coalesced run-length view of the structured side where each inline node is one
* structured position expanding to `inlineLen` inlined positions, and every other position (root text
* and opaque non-inlined nodes) is a pass-through run. It is kept current incrementally - every mapped
* change is folded into `segs` by {@link applySegsChange} rather than re-derived from scratch.
*
* @extends {Transformer<any,any>}
*/
export class InlineTransformer extends Transformer<any, any> {
/**
* @param {import('../../schema.js').Schema<delta.Delta<any>>} $in
* @param {import('../../schema.js').Schema<delta.Delta<any>>} $out
* @param {Array<string|null>} names the node names to inline (`null` selects anonymous nodes)
*/
constructor($in: import("../../schema.js").Schema<delta.Delta<any>>, $out: import("../../schema.js").Schema<delta.Delta<any>>, names: Array<string | null>);
/**
* @type {Array<string|null>}
*/
names: Array<string | null>;
/**
* The segment layout of the structured side, maintained incrementally (see {@link applySegsChange}).
*
* @type {Array<Seg>}
*/
segs: Array<Seg>;
/**
* Whether the structured side has ever contained a direct inline-node child. Monotonic: once a
* change introduces an inline node it stays set (even if that node is later deleted), which only
* costs a missed fast-path, never correctness.
*
* @type {boolean}
*/
hasInline: boolean;
}
/**
* Template for {@link InlineTransformer}. Typed loosely: the inlined output shape depends on the
* runtime `names` and document content, so the OUT side is `any`.
*
* @template {delta.DeltaConf} [IN=any]
* @extends {Template<IN, any>}
*/
export class Inline<IN extends delta.DeltaConf = any> extends Template<IN, any> {
/**
* @param {import('../../schema.js').Schema<delta.Delta<IN>>} $d
* @param {Array<string|null>} names the node names to inline (`null` selects anonymous nodes)
*/
constructor($d: import("../../schema.js").Schema<delta.Delta<IN>>, names: Array<string | null>);
names: (string | null)[];
}
export function inline<IN extends delta.DeltaConf>($d: import("../../schema.js").Schema<delta.Delta<IN>>, names: Array<string | null>): Inline<IN>;
export function inlineNullNodes<IN extends delta.DeltaConf>($d: import("../../schema.js").Schema<delta.Delta<IN>>): Inline<IN>;
/**
* The (unexported) delta {@link import ('../delta.js').createMark Mark} type, referenced here for the
* local mark-bucketing annotations.
*/
export type Mark = ReturnType<typeof delta.createMark>;
import { Transformer } from './core.js';
/**
* The (unexported) delta {@link import('../delta.js').createMark Mark} type, referenced here for the
* local mark-bucketing annotations.
*
* @typedef {ReturnType<typeof delta.createMark>} Mark
*/
/**
* One entry of the segment layout maintained by {@link InlineTransformer}. A segment is either a
* coalesced run of pass-through positions (root text + opaque non-inlined nodes - same length in both
* coordinate spaces) or a single inline node (1 structured position that expands to `inlineLen`
* inlined positions).
*/
declare class Seg {
/**
* @param {boolean} isInline whether this seg is an inline node (its children are spliced into the parent)
* @param {number} structLen
* @param {number} inlineLen
*/
constructor(isInline: boolean, structLen: number, inlineLen: number);
isInline: boolean;
structLen: number;
inlineLen: number;
}
import * as delta from '../delta.js';
import { Template } from './core.js';
export {};
//# sourceMappingURL=inline.d.ts.map