lib0
Version:
isomorphic utility functions
92 lines • 4.51 kB
TypeScript
/**
* Stateful transformer that resolves `lib0:value` carrier *children* of a node: a `lib0:value` node
* (1 position) becomes an embed of its scalar value (1 position), and back. Count-preserving, so a
* single sparse positional map (`insert([1])` at carrier positions, coalesced `retain(n)` over
* gaps) indexes both directions - the same `childTs` technique as {@link import('./children.js')}.
*
* A standalone, *composable* one-level resolver (the `lib0:value` counterpart of
* {@link import('./inline.js').inline}`(['lib0:inline'])`): place it after any transformer that emits
* `lib0:value` carriers, or compose it with {@link import('./children.js').children} to descend into
* deeper levels. `project` lifts the carriers in its *own* structure, so `unwrapValue` is only needed
* for carriers emitted by a non-`project` transformer.
*
* Editing a resolved scalar from side B (the view) is not round-tripped in v1: a value *update*
* driven from side A (a `modify` on the carrier) maps to `delete(1).insert([newValue])`, but a side
* B `delete`+`insert` of the embed is treated structurally.
*
* @extends {Transformer<any,any>}
*/
export class UnwrapValueTransformer extends Transformer<any, any> {
/**
* @param {import('../../schema.js').Schema<delta.Delta<any>>} $in
* @param {import('../../schema.js').Schema<delta.Delta<any>>} $out
*/
constructor($in: import("../../schema.js").Schema<delta.Delta<any>>, $out: import("../../schema.js").Schema<delta.Delta<any>>);
/**
* Sparse positional map of carriers: `insert([1])` at each `lib0:value` child, `retain(n)` over
* gaps (text and pass-through nodes).
*
* @type {delta.DeltaBuilderAny}
*/
map: delta.DeltaBuilderAny;
/**
* @param {delta.DeltaBuilderAny} d the change to map
* @param {boolean} fwd `true` maps side A (carriers present) -> B (resolved), `false` maps back
* @return {import('./core.js').TransformResultAny}
*/
transform(d: delta.DeltaBuilderAny, fwd: boolean): import("./core.js").TransformResultAny;
}
/**
* A `lib0:value` carrier child lifts to its scalar `value` type; any other child passes through.
* Naked-param conditional, so it distributes over a children union.
*
* @template C
* @typedef {C extends delta.Delta<{ name: 'lib0:value', attrs: { value: infer V extends import('../../trait/fingerprint.js').Fingerprintable } }> ? V : C} UnwrapValueChild
*/
/**
* `unwrapValue`'s output conf: `IN` with every `lib0:value` carrier child replaced by its lifted
* scalar (see {@link UnwrapValueChild}); name/attrs/text unchanged.
*
* @template {delta.DeltaConf} IN
* @typedef {import('./core.js').ResolveOut<delta.DeltaConfOverwrite<IN, { children: UnwrapValueChild<delta.DeltaConfGetChildren<IN>> }>>} UnwrapValueOut
*/
/**
* Template for {@link UnwrapValueTransformer}.
*
* @template {delta.DeltaConf} [IN=any]
* @extends {Template<IN, UnwrapValueOut<IN>>}
*/
export class UnwrapValue<IN extends delta.DeltaConf = any> extends Template<IN, delta.DeltaConfOverwrite<delta.DeltaConfOverwrite<IN, {
children: UnwrapValueChild<IN extends {
children: infer Children;
} ? unknown extends Children ? any : Children : never> | UnwrapValueChild<IN extends {
recursiveChildren: true;
} ? delta.Delta<IN> : never>;
}>, {}>> {
/**
* @param {import('../../schema.js').Schema<delta.Delta<IN>>} $d
*/
constructor($d: import("../../schema.js").Schema<delta.Delta<IN>>);
}
export function unwrapValue<IN extends delta.DeltaConf>($d: import("../../schema.js").Schema<delta.Delta<IN>>): UnwrapValue<IN>;
/**
* A `lib0:value` carrier child lifts to its scalar `value` type; any other child passes through.
* Naked-param conditional, so it distributes over a children union.
*/
export type UnwrapValueChild<C> = C extends delta.Delta<{
name: "lib0:value";
attrs: {
value: infer V extends import("../../trait/fingerprint.js").Fingerprintable;
};
}> ? V : C;
/**
* `unwrapValue`'s output conf: `IN` with every `lib0:value` carrier child replaced by its lifted
* scalar (see {@link UnwrapValueChild}); name/attrs/text unchanged.
*/
export type UnwrapValueOut<IN extends delta.DeltaConf> = import("./core.js").ResolveOut<delta.DeltaConfOverwrite<IN, {
children: UnwrapValueChild<delta.DeltaConfGetChildren<IN>>;
}>>;
import { Transformer } from './core.js';
import * as delta from '../delta.js';
import { Template } from './core.js';
//# sourceMappingURL=value.d.ts.map