alinea
Version:
Headless git-based CMS
48 lines (47 loc) • 1.97 kB
TypeScript
import type { LinkResolver } from 'alinea/core/db/LinkResolver';
import * as Y from 'yjs';
import type { Label } from '../Label.js';
import type { Shape } from '../Shape.js';
import type { PostProcess } from '../pages/PostProcess.js';
import { RecordShape } from './RecordShape.js';
export interface ListRow {
_id: string;
_type: string;
_index: string;
}
export declare namespace ListRow {
const id = "_id";
const index = "_index";
const type = "_type";
}
export interface ListMutator<Row> {
replace(id: string, row: Row): void;
push(row: Omit<Row, '_id' | '_index'>, insertAt?: number): void;
remove(id: string): void;
move(oldIndex: number, newIndex: number): void;
read(id: string): Row | undefined;
}
export declare class ListShape<Row extends ListRow> implements Shape<Array<Row>, ListMutator<Row>> {
label: Label;
initialValue?: Array<Row> | undefined;
protected postProcess?: PostProcess<Array<Row>> | undefined;
shapes: Record<string, RecordShape>;
constructor(label: Label, shapes: Record<string, RecordShape>, initialValue?: Array<Row> | undefined, postProcess?: PostProcess<Array<Row>> | undefined);
create(): Row[];
toV1(value: any): Row[];
private normalizeRow;
toY(value: Array<Row>): Y.Map<unknown>;
fromY(map: Y.Map<any>): Array<Row>;
applyY(value: Row[], parent: Y.Map<any>, key: string): void;
init(parent: Y.Map<any>, key: string): void;
watch(parent: Y.Map<any>, key: string): (fun: () => void) => () => void;
mutator(parent: Y.Map<any>, key: string): {
replace: (id: string, row: Row) => void;
push: (row: Omit<Row, "_id" | "_index">, insertAt?: number) => void;
remove(id: string): void;
move: (oldIndex: number, newIndex: number) => void;
read: (id: string) => Row | undefined;
};
applyLinks(value: Array<Row>, loader: LinkResolver): Promise<void>;
searchableText(value: Array<Row>): string;
}