@articollab/prosemirror 0.0.0-stage → 0.12.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,442 @@
1
+ import { Mark } from "prosemirror-model";
2
+ /** The nodes and marks of `prosemirror-schema-basic` with `prosemirror-schema-list`'s lists. */
3
+ export const basicMapping = Object.freeze({
4
+ paragraph: "paragraph",
5
+ marks: Object.freeze({
6
+ bold: Object.freeze({ mark: "strong" }),
7
+ italic: Object.freeze({ mark: "em" }),
8
+ code: Object.freeze({ mark: "code" }),
9
+ link: Object.freeze({
10
+ mark: "link",
11
+ value: (mark) => String(mark.attrs.href),
12
+ attrs: (value) => ({ href: typeof value === "string" ? value : JSON.stringify(value) }),
13
+ }),
14
+ }),
15
+ heading: Object.freeze({ node: "heading", levels: Object.freeze([1, 2, 3, 4, 5, 6]) }),
16
+ codeBlock: Object.freeze({ node: "code_block" }),
17
+ blockquote: Object.freeze({ node: "blockquote" }),
18
+ lists: Object.freeze({ item: "list_item", bullet: "bullet_list", ordered: "ordered_list" }),
19
+ lineBreak: Object.freeze({ node: "hard_break" }),
20
+ });
21
+ const NONE = Object.freeze({});
22
+ const EMPTY_LINE = Object.freeze({ runs: Object.freeze([]), attributes: NONE });
23
+ /** Whether two JSON values are equal; object key order does not matter. */
24
+ export function sameJson(a, b) {
25
+ if (a === b)
26
+ return true;
27
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null || Array.isArray(a) !== Array.isArray(b))
28
+ return false;
29
+ const left = Object.entries(a), right = new Map(Object.entries(b));
30
+ return left.length === right.size && left.every(([key, value]) => right.has(key) && sameJson(value, right.get(key)));
31
+ }
32
+ function sorted(attributes) {
33
+ return Object.freeze(Object.fromEntries(Object.entries(attributes).toSorted(([a], [b]) => (a < b ? -1 : 1))));
34
+ }
35
+ /** The code points of a string, as Text counts them. */
36
+ function codePointLength(text) {
37
+ let count = 0;
38
+ for (const _ of text)
39
+ count++;
40
+ return count;
41
+ }
42
+ /** A line's text. */
43
+ function lineText(line) {
44
+ return line.runs.map(({ text }) => text).join("");
45
+ }
46
+ /** A line's length in Text elements. */
47
+ export function lineLength(line) {
48
+ let length = 0;
49
+ for (const { text } of line.runs)
50
+ length += codePointLength(text);
51
+ return length;
52
+ }
53
+ /** The Text lines of `count` elements from `index`, which must start and end at line boundaries. */
54
+ export function textLines(body, index, count) {
55
+ const ranged = index !== undefined;
56
+ const delta = ranged ? body.toDelta(index, count) : body.toDelta();
57
+ const blocks = [...(ranged ? body.blocks(index, count) : body.blocks())];
58
+ // A range ending just after a line break also holds the empty start of the next line, which
59
+ // blocks() leaves out: a paragraph starts within a range only before its last element.
60
+ if (ranged && delta.at(-1)?.insert.endsWith("\n") === true)
61
+ blocks.push(...body.blocks(index + delta.reduce((sum, run) => sum + codePointLength(run.insert), 0), 0));
62
+ const lines = blocks.map(({ attributes }) => ({ runs: [], attributes: sorted({ ...attributes }) }));
63
+ let line = 0;
64
+ for (const { insert, attributes } of delta) {
65
+ insert.split("\n").forEach((part, position) => {
66
+ if (position > 0)
67
+ line++;
68
+ if (part !== "")
69
+ lines[line]?.runs.push({ text: part, marks: attributes === undefined ? NONE : sorted({ ...attributes }) });
70
+ });
71
+ }
72
+ return lines.map((each) => ({ runs: mergeRuns(each.runs), attributes: each.attributes }));
73
+ }
74
+ function mergeRuns(runs) {
75
+ const merged = [];
76
+ for (const run of runs) {
77
+ const last = merged.at(-1);
78
+ if (last !== undefined && sameJson(last.marks, run.marks))
79
+ merged[merged.length - 1] = { text: last.text + run.text, marks: run.marks };
80
+ else
81
+ merged.push(run);
82
+ }
83
+ return merged;
84
+ }
85
+ /** The last index whose value is at most `target` in an ascending array, or 0. */
86
+ function lastAtMost(values, target) {
87
+ let low = 0, high = values.length - 1;
88
+ while (low < high) {
89
+ const middle = (low + high + 1) >>> 1;
90
+ if (values[middle] <= target)
91
+ low = middle;
92
+ else
93
+ high = middle - 1;
94
+ }
95
+ return low;
96
+ }
97
+ /**
98
+ * Converts between a Text's lines and ProseMirror nodes for one mapping. The nodes are always in one
99
+ * standard shape: consecutive quoted lines are one quote, consecutive code lines one code block
100
+ * without marks, list lines nested lists with one paragraph per item, and a list item never a
101
+ * heading. A line's list depth is its `indent`, but at most one deeper than the line before.
102
+ */
103
+ export class TextShape {
104
+ schema;
105
+ mapping;
106
+ cache = new WeakMap();
107
+ layouts = new WeakMap();
108
+ constructor(schema, mapping) {
109
+ this.schema = schema;
110
+ this.mapping = mapping;
111
+ // Fail at once for a mapping the schema cannot hold.
112
+ this.node(mapping.doc ?? "doc");
113
+ this.node(mapping.paragraph);
114
+ if (mapping.heading !== undefined)
115
+ this.node(mapping.heading.node);
116
+ if (mapping.codeBlock !== undefined)
117
+ this.node(mapping.codeBlock.node);
118
+ if (mapping.blockquote !== undefined)
119
+ this.node(mapping.blockquote.node);
120
+ if (mapping.lists !== undefined)
121
+ for (const name of [mapping.lists.item, mapping.lists.bullet, mapping.lists.ordered])
122
+ this.node(name);
123
+ if (mapping.lineBreak !== undefined)
124
+ this.node(mapping.lineBreak.node);
125
+ for (const [key, { mark }] of Object.entries(mapping.marks)) {
126
+ if (schema.marks[mark] === undefined)
127
+ throw new TypeError(`The schema has no ${mark} mark for ${key}`);
128
+ }
129
+ }
130
+ node(name) {
131
+ const type = this.schema.nodes[name];
132
+ if (type === undefined)
133
+ throw new TypeError(`The schema has no ${name} node`);
134
+ return type;
135
+ }
136
+ /** The Text mark and paragraph attribute keys this mapping writes. */
137
+ keys() {
138
+ const { heading, codeBlock, blockquote, lists } = this.mapping;
139
+ return {
140
+ marks: Object.keys(this.mapping.marks),
141
+ blocks: [...(heading ? ["heading"] : []), ...(codeBlock ? ["code"] : []), ...(blockquote ? ["quote"] : []),
142
+ ...(lists ? ["list", "indent"] : [])],
143
+ };
144
+ }
145
+ /**
146
+ * Whether two values of a paragraph attribute show the same: for `code` without a language
147
+ * attribute, any two values make a code block.
148
+ */
149
+ sameAttribute(key, a, b) {
150
+ if (key === "code" && this.mapping.codeBlock?.language === undefined && a != null && b != null)
151
+ return true;
152
+ return sameJson(a ?? null, b ?? null);
153
+ }
154
+ // Lines to nodes.
155
+ marksFor(marks) {
156
+ const result = [];
157
+ for (const [key, { mark, attrs }] of Object.entries(this.mapping.marks)) {
158
+ const value = marks[key];
159
+ if (value === undefined)
160
+ continue;
161
+ result.push(this.schema.marks[mark].create(attrs === undefined ? null : attrs(value)));
162
+ }
163
+ return Mark.setFrom(result);
164
+ }
165
+ inline(line) {
166
+ return line.runs.filter(({ text }) => text !== "").map(({ text, marks }) => this.schema.text(text, this.marksFor(marks)));
167
+ }
168
+ textblock(line, inList) {
169
+ const { heading } = this.mapping;
170
+ const level = line.attributes.heading;
171
+ if (!inList && heading !== undefined && typeof level === "number" && heading.levels.includes(level)) {
172
+ return this.node(heading.node).create({ level }, this.inline(line));
173
+ }
174
+ return this.node(this.mapping.paragraph).create(null, this.inline(line));
175
+ }
176
+ buildLists(lines) {
177
+ const lists = this.mapping.lists;
178
+ const depths = [];
179
+ for (const [index, line] of lines.entries()) {
180
+ const indent = typeof line.attributes.indent === "number" ? line.attributes.indent : 0;
181
+ depths.push(index === 0 ? 0 : Math.min(indent, depths[index - 1] + 1, lists.maxIndent ?? Infinity));
182
+ }
183
+ const level = (start, depth) => {
184
+ const result = [];
185
+ let position = start;
186
+ while (position < lines.length && depths[position] === depth) {
187
+ const kind = lines[position].attributes.list;
188
+ const type = this.node(kind === "ordered" ? lists.ordered : lists.bullet);
189
+ const items = [];
190
+ while (position < lines.length && depths[position] === depth && lines[position].attributes.list === kind) {
191
+ const children = [this.textblock(lines[position], true)];
192
+ position++;
193
+ if (position < lines.length && depths[position] > depth) {
194
+ const [nested, next] = level(position, depth + 1);
195
+ children.push(...nested);
196
+ position = next;
197
+ }
198
+ items.push(this.node(lists.item).create(null, children));
199
+ }
200
+ result.push(type.create(null, items));
201
+ }
202
+ return [result, position];
203
+ };
204
+ return level(0, 0)[0];
205
+ }
206
+ buildBlocks(lines, inQuote) {
207
+ const { codeBlock, blockquote, lists } = this.mapping;
208
+ const blocks = [];
209
+ const runEnd = (start, test) => {
210
+ let end = start;
211
+ while (end < lines.length && test(lines[end]))
212
+ end++;
213
+ return end;
214
+ };
215
+ const quoted = (line) => blockquote !== undefined && !inQuote && line.attributes.quote === true;
216
+ const coded = (line) => codeBlock !== undefined && line.attributes.code != null;
217
+ // Lines of one code block: the same language, when the mapping stores one.
218
+ const language = (line) => (codeBlock?.language === undefined || typeof line.attributes.code !== "string" ? true : line.attributes.code);
219
+ const listed = (line) => lists !== undefined && (line.attributes.list === "bullet" || line.attributes.list === "ordered");
220
+ for (let index = 0; index < lines.length;) {
221
+ const line = lines[index];
222
+ if (quoted(line)) {
223
+ const end = runEnd(index, quoted);
224
+ blocks.push(this.node(blockquote.node).create(null, this.buildBlocks(lines.slice(index, end), true)));
225
+ index = end;
226
+ }
227
+ else if (coded(line)) {
228
+ const value = language(line);
229
+ const end = runEnd(index, (next) => coded(next) && !quoted(next) && language(next) === value);
230
+ const code = lines.slice(index, end).map(lineText).join("\n");
231
+ const attrs = codeBlock.language === undefined ? null : { [codeBlock.language]: value === true ? null : value };
232
+ blocks.push(this.node(codeBlock.node).create(attrs, code === "" ? [] : [this.schema.text(code)]));
233
+ index = end;
234
+ }
235
+ else if (listed(line)) {
236
+ const end = runEnd(index, (next) => listed(next) && !coded(next) && !quoted(next));
237
+ blocks.push(...this.buildLists(lines.slice(index, end)));
238
+ index = end;
239
+ }
240
+ else {
241
+ blocks.push(this.textblock(line, false));
242
+ index++;
243
+ }
244
+ }
245
+ return blocks;
246
+ }
247
+ /** The top-level nodes for some lines, in the standard shape. */
248
+ nodes(lines) {
249
+ return this.buildBlocks(lines, false);
250
+ }
251
+ /** The document for some lines, in the standard shape; no lines make one empty paragraph. */
252
+ doc(lines) {
253
+ return this.node(this.mapping.doc ?? "doc").create(null, this.nodes(lines.length === 0 ? [EMPTY_LINE] : lines));
254
+ }
255
+ // Nodes to lines.
256
+ textMarks(node) {
257
+ const marks = {};
258
+ for (const mark of node.marks) {
259
+ for (const [key, { mark: name, value }] of Object.entries(this.mapping.marks)) {
260
+ if (mark.type.name === name)
261
+ marks[key] = value === undefined ? true : value(mark);
262
+ }
263
+ }
264
+ return sorted(marks);
265
+ }
266
+ /** Collects the lines under `parent`, whose content starts at position `offset`, and where each line's text starts. */
267
+ walk(parent, offset, context, lines, starts) {
268
+ const { heading, codeBlock, blockquote, lists, lineBreak } = this.mapping;
269
+ parent.forEach((node, childOffset) => {
270
+ const position = offset + childOffset;
271
+ const name = node.type.name;
272
+ const attributes = {};
273
+ if (context.quote)
274
+ attributes.quote = true;
275
+ if (blockquote !== undefined && name === blockquote.node) {
276
+ this.walk(node, position + 1, { ...context, quote: true }, lines, starts);
277
+ }
278
+ else if (lists !== undefined && (name === lists.bullet || name === lists.ordered)) {
279
+ const depth = context.list === undefined ? 0 : Math.min(context.depth + 1, lists.maxIndent ?? Infinity);
280
+ const list = name === lists.ordered ? "ordered" : "bullet";
281
+ node.forEach((item, itemOffset) => { this.walk(item, position + 1 + itemOffset + 1, { quote: context.quote, list, depth }, lines, starts); });
282
+ }
283
+ else if (codeBlock !== undefined && name === codeBlock.node) {
284
+ let start = position + 1;
285
+ const language = codeBlock.language === undefined ? undefined : node.attrs[codeBlock.language];
286
+ const code = typeof language === "string" && language !== "" ? language : true;
287
+ for (const part of node.textContent.split("\n")) {
288
+ lines.push({ runs: part === "" ? [] : [{ text: part, marks: NONE }], attributes: sorted({ ...attributes, code }) });
289
+ starts.push(start);
290
+ start += part.length + 1;
291
+ }
292
+ }
293
+ else if (node.isTextblock) {
294
+ if (context.list !== undefined) {
295
+ attributes.list = context.list;
296
+ if (context.depth > 0)
297
+ attributes.indent = context.depth;
298
+ }
299
+ else if (heading !== undefined && name === heading.node) {
300
+ const levels = heading.levels, level = Number(node.attrs.level);
301
+ attributes.heading = levels.includes(level) ? level : (level < Math.min(...levels) ? Math.min(...levels) : Math.max(...levels));
302
+ }
303
+ // A line break typed into the text, as insertText("a\nb") makes, or a line break node starts
304
+ // another line like it.
305
+ let runs = [], start = position + 1;
306
+ const own = sorted(attributes);
307
+ node.forEach((child, at) => {
308
+ if (lineBreak !== undefined && child.type.name === lineBreak.node) {
309
+ lines.push({ runs, attributes: own });
310
+ starts.push(start);
311
+ runs = [];
312
+ start = position + 1 + at + child.nodeSize;
313
+ return;
314
+ }
315
+ if (!child.isText)
316
+ return;
317
+ const marks = this.textMarks(child);
318
+ for (const [index, part] of (child.text ?? "").split("\n").entries()) {
319
+ if (index > 0) {
320
+ lines.push({ runs, attributes: own });
321
+ starts.push(start);
322
+ runs = [];
323
+ start = position + 1 + at + (child.text ?? "").split("\n").slice(0, index).join("\n").length + 1;
324
+ }
325
+ if (part === "")
326
+ continue;
327
+ const last = runs.at(-1);
328
+ if (last !== undefined && sameJson(last.marks, marks))
329
+ runs[runs.length - 1] = { text: last.text + part, marks };
330
+ else
331
+ runs.push({ text: part, marks });
332
+ }
333
+ });
334
+ lines.push({ runs, attributes: own });
335
+ starts.push(start);
336
+ }
337
+ else {
338
+ this.walk(node, position + 1, context, lines, starts);
339
+ }
340
+ });
341
+ }
342
+ /**
343
+ * The lines of one top-level node, and where each line's text starts, counted from the node's own
344
+ * start. Cached: ProseMirror nodes never change.
345
+ */
346
+ nodeInfo(node) {
347
+ let info = this.cache.get(node);
348
+ if (info === undefined) {
349
+ const lines = [], starts = [];
350
+ this.walk(this.node(this.mapping.doc ?? "doc").create(null, node), 0, { quote: false, depth: 0 }, lines, starts);
351
+ const lengths = lines.map(lineLength);
352
+ const length = lengths.reduce((sum, each) => sum + each, 0) + Math.max(0, lines.length - 1);
353
+ info = Object.freeze({ lines: Object.freeze(lines), starts: Object.freeze(starts), lengths: Object.freeze(lengths), length });
354
+ this.cache.set(node, info);
355
+ }
356
+ return info;
357
+ }
358
+ /**
359
+ * Where each top-level node starts, in Text elements and positions. Linear in the number of
360
+ * top-level nodes, not in the text: each node's length is cached.
361
+ */
362
+ layout(doc) {
363
+ let layout = this.layouts.get(doc);
364
+ if (layout === undefined) {
365
+ const elements = [], positions = [], lined = [];
366
+ let element = 0;
367
+ doc.forEach((node, position, index) => {
368
+ const info = this.nodeInfo(node);
369
+ // A line break separates this node's first line from the line before.
370
+ const start = info.lines.length > 0 && lined.length > 0 ? element + 1 : element;
371
+ elements.push(start);
372
+ positions.push(position);
373
+ if (info.lines.length === 0)
374
+ return;
375
+ lined.push(index);
376
+ element = start + info.length;
377
+ });
378
+ layout = Object.freeze({ elements: Object.freeze(elements), positions: Object.freeze(positions), lined: Object.freeze(lined), length: element });
379
+ this.layouts.set(doc, layout);
380
+ }
381
+ return layout;
382
+ }
383
+ /** The child index of the node with lines that holds Text element gap `element`. */
384
+ childAtElement(doc, element) {
385
+ const layout = this.layout(doc);
386
+ const starts = layout.lined.map((index) => layout.elements[index]);
387
+ return layout.lined[lastAtMost(starts, element)] ?? 0;
388
+ }
389
+ /** The document position of Text element gap `element`. */
390
+ positionAt(doc, element) {
391
+ const layout = this.layout(doc);
392
+ if (layout.lined.length === 0)
393
+ return 0;
394
+ const child = this.childAtElement(doc, element);
395
+ const info = this.nodeInfo(doc.child(child));
396
+ let offset = element - layout.elements[child], line = 0;
397
+ while (line < info.lines.length - 1 && offset > info.lengths[line]) {
398
+ offset -= info.lengths[line] + 1;
399
+ line++;
400
+ }
401
+ offset = Math.max(0, Math.min(offset, info.lengths[line]));
402
+ let units = 0, seen = 0;
403
+ for (const point of lineText(info.lines[line])) {
404
+ if (seen++ === offset)
405
+ break;
406
+ units += point.length;
407
+ }
408
+ return layout.positions[child] + info.starts[line] + units;
409
+ }
410
+ /** The Text element gap nearest document position `position`; between blocks, the end of the line before. */
411
+ elementAt(doc, position) {
412
+ const layout = this.layout(doc);
413
+ if (layout.lined.length === 0)
414
+ return 0;
415
+ const lined = layout.lined.map((index) => layout.positions[index]);
416
+ const at = lastAtMost(lined, position);
417
+ const child = layout.lined[at];
418
+ const info = this.nodeInfo(doc.child(child));
419
+ const relative = position - layout.positions[child];
420
+ // Before the node's first text, as between two blocks: the end of the line before.
421
+ if (relative < info.starts[0] && at > 0)
422
+ return layout.elements[child] - 1;
423
+ const line = lastAtMost(info.starts, relative);
424
+ let element = layout.elements[child];
425
+ for (let before = 0; before < line; before++)
426
+ element += info.lengths[before] + 1;
427
+ const text = lineText(info.lines[line]);
428
+ const units = Math.max(0, Math.min(text.length, relative - info.starts[line]));
429
+ return element + codePointLength(text.slice(0, units));
430
+ }
431
+ /** The lines of one top-level node. */
432
+ nodeLines(node) {
433
+ return this.nodeInfo(node).lines;
434
+ }
435
+ /** The lines of a document: every top-level node's, and one empty line for a document with none. */
436
+ lines(doc) {
437
+ const lines = [];
438
+ doc.forEach((node) => { lines.push(...this.nodeLines(node)); });
439
+ return lines.length === 0 ? [EMPTY_LINE] : lines;
440
+ }
441
+ }
442
+ //# sourceMappingURL=mapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapping.js","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAqD,MAAM,mBAAmB,CAAC;AA6C5F,gGAAgG;AAChG,MAAM,CAAC,MAAM,YAAY,GAAgB,MAAM,CAAC,MAAM,CAAC;IACrD,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QACvC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACrC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACrC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;YAClB,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,CAAC,IAAU,EAAa,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC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C,KAAK,CAAC;IACnD,CAAC;CACF"}
package/dist/sync.d.ts ADDED
@@ -0,0 +1,166 @@
1
+ import { Node, type Schema } from "prosemirror-model";
2
+ import { Plugin, type Command, type EditorState, type Transaction } from "prosemirror-state";
3
+ import type { EditorView } from "prosemirror-view";
4
+ import type { ClientDocument, Cursor, JsonValue, SchemaShape, TextChangeEvent, TextSchema, UndoManager } from "@articollab/core";
5
+ import { TextShape, type Attributes, type TextMapping } from "./mapping.ts";
6
+ /** A selection as two cursors; `from === to` is a caret. */
7
+ export interface CursorSelection {
8
+ readonly from: Cursor;
9
+ readonly to: Cursor;
10
+ }
11
+ /** The part of a Text the binding reads and writes. */
12
+ interface SyncedText {
13
+ readonly length: number;
14
+ insert(index: number, value: string): void;
15
+ delete(index: number, count?: number): void;
16
+ format(index: number, count: number, key: string, value: JsonValue | null): void;
17
+ formatBlocks(index: number, count: number, key: string, value: JsonValue | null): void;
18
+ toDelta(index?: number, count?: number): readonly {
19
+ readonly insert: string;
20
+ readonly attributes?: Attributes;
21
+ }[];
22
+ blocks(index?: number, count?: number): readonly {
23
+ readonly index: number;
24
+ readonly length: number;
25
+ readonly attributes: Attributes;
26
+ }[];
27
+ cursorAt(index: number, bind?: "left" | "right"): Cursor;
28
+ cursorIndex(cursor: Cursor): number | undefined;
29
+ observe(listener: (event: TextChangeEvent) => void): () => void;
30
+ }
31
+ /** The document a binding writes through: its Text, transactions and replay state. */
32
+ interface SyncedDocument {
33
+ readonly state: Readonly<Record<string, unknown>>;
34
+ transact(callback: () => void): void;
35
+ readonly replayConflict: unknown;
36
+ }
37
+ export interface TextSyncOptions {
38
+ /** Which nodes and marks stand for the Text's lines; `basicMapping` by default. */
39
+ readonly mapping?: TextMapping;
40
+ /** Ends an undo step around a confirmed input method composition, so it is a step of its own. */
41
+ readonly history?: UndoManager;
42
+ /** Whether local edits may be written now; an edit is refused while it returns false. */
43
+ readonly canEdit?: () => boolean;
44
+ /** Called with an error that stopped the binding; local edits are refused from then on. */
45
+ readonly onError?: (error: unknown) => void;
46
+ /** Called with the text of a composition that could not be written, for the user to copy. */
47
+ readonly onUnsentComposition?: (text: string) => void;
48
+ }
49
+ /** Paths of a schema whose collection is a Text. */
50
+ export type TextPath<S extends SchemaShape> = {
51
+ [K in keyof S & string]: S[K] extends TextSchema ? K : never;
52
+ }[keyof S & string];
53
+ /** The plugin's state: its binding, and whether the latest transaction came from the Text. */
54
+ interface SyncState {
55
+ readonly binding: TextBinding;
56
+ readonly fromText: boolean;
57
+ }
58
+ /** Keeps one editor and one Text in step; created when the plugin's view starts. */
59
+ export declare class TextBinding {
60
+ readonly shape: TextShape;
61
+ private readonly text;
62
+ private readonly doc;
63
+ private readonly options;
64
+ private view;
65
+ private stop;
66
+ /** True while this binding writes, so its own changes are not applied back. */
67
+ private writing;
68
+ private failure;
69
+ /** The selection as cursors, kept current so a change from elsewhere can put it back on the same text. */
70
+ selection: CursorSelection | undefined;
71
+ private composition;
72
+ private ending;
73
+ constructor(doc: SyncedDocument, text: SyncedText, schema: Schema, options: TextSyncOptions);
74
+ get failed(): boolean;
75
+ get composing(): boolean;
76
+ /** Whether a composition that ended waits to be written. */
77
+ get finishing(): boolean;
78
+ /** Whether a local edit may be written now. */
79
+ canWrite(): boolean;
80
+ private fail;
81
+ attach(view: EditorView): void;
82
+ detach(): void;
83
+ /** The selection of `state` as cursors; its document must show the Text. */
84
+ cursorsOf(state: Pick<EditorState, "doc" | "selection">): CursorSelection;
85
+ /** A selection's current positions in `doc`, or undefined while an anchor is unknown here. */
86
+ resolve(cursors: CursorSelection, doc: Node): {
87
+ from: number;
88
+ to: number;
89
+ } | undefined;
90
+ /** Replaces the editor's document with `target`, keeping the selection on the same text. */
91
+ private show;
92
+ private restoreSelection;
93
+ /** Formats `want` from `offset` where the Text's marks there now, `have`, differ: one format per run. */
94
+ private formatRuns;
95
+ /** Writes `after` over the Text's `before` lines at element `offset`, in the current transaction. */
96
+ private writeLines;
97
+ /** The lines of children `[from, to)` of `doc`. */
98
+ private windowLines;
99
+ /** The Text element where children `[from, …)` of `doc` start: their first line's. */
100
+ private windowStart;
101
+ /** Writes the change from `before` to `after`, which shows `before` plus local edits, as one batch. */
102
+ write(before: Node, after: Node): void;
103
+ /** The standard shape of what changed from `before` to `after`, or undefined when already standard. */
104
+ standardize(before: Node, after: Node, tr: Transaction): Transaction | undefined;
105
+ /** After a local transaction: writes it to the Text. */
106
+ updated(view: EditorView, previous: EditorState): void;
107
+ private received;
108
+ /** Rebuilds just the top-level nodes an event touched, with one neighbor on each side. */
109
+ private apply;
110
+ /** Starts keeping edits in the editor: candidates are not written until the composition ends. */
111
+ startComposition(state: EditorState): void;
112
+ /** Marks the composition cancelled, as an Escape that ends it does. */
113
+ cancelComposition(): void;
114
+ /** Undoes a cancellation, as a key that keeps composing does. */
115
+ resumeComposition(): void;
116
+ /** Ends the composition once ProseMirror has read its final text. */
117
+ scheduleFinish(view: EditorView): void;
118
+ /**
119
+ * Writes the composition's text as one batch, unless it was cancelled, and shows the changes from
120
+ * elsewhere that waited. A composition that cannot be written goes to `onUnsentComposition`.
121
+ */
122
+ finishComposition(view: EditorView): void;
123
+ /**
124
+ * Writes a composition's replacement into a Text that changed since it started: elements deleted
125
+ * elsewhere stay deleted, and text inserted elsewhere stays. Returns where the inserted text
126
+ * starts, or undefined when the change is not inside the composition's paragraphs.
127
+ */
128
+ private rebase;
129
+ }
130
+ /**
131
+ * A ProseMirror plugin that keeps the editor and the Text at `path` in step. Local transactions are
132
+ * compared with the Text only where they changed the document, and written as one batch; changes
133
+ * from elsewhere rebuild only the top-level nodes they touched. The editor always shows the Text's
134
+ * standard shape. An input method composition is written once confirmed, and not at all when
135
+ * Escape cancels it.
136
+ */
137
+ export declare function textSync<S extends SchemaShape>(doc: ClientDocument<S>, path: TextPath<S>, options?: TextSyncOptions): Plugin<SyncState>;
138
+ /** The ProseMirror document showing a Text, in the mapping's standard shape. */
139
+ export declare function textToDoc(text: {
140
+ toDelta(): readonly {
141
+ readonly insert: string;
142
+ readonly attributes?: Attributes;
143
+ }[];
144
+ blocks(): readonly {
145
+ readonly attributes: Attributes;
146
+ }[];
147
+ }, schema: Schema, mapping?: TextMapping): Node;
148
+ /** The editor's selection as cursors, for sharing as presence; undefined without the `textSync` plugin. */
149
+ export declare function selectionCursors(state: EditorState): CursorSelection | undefined;
150
+ /** Another writer's selection in this editor's positions, or undefined while its text is unknown here. */
151
+ export declare function resolveSelection(state: EditorState, cursors: CursorSelection): {
152
+ from: number;
153
+ to: number;
154
+ } | undefined;
155
+ /** The binding of an editor with the `textSync` plugin. Internal, for the remote selections plugin. */
156
+ export declare function bindingOf(state: EditorState): TextBinding | undefined;
157
+ /** Whether an input method composition is open in the editor; commands and keys should wait for it. */
158
+ export declare function isComposing(view: EditorView): boolean;
159
+ /** Whether `tr` shows a change from the Text, which positions from cursors already match. */
160
+ export declare function isFromText(tr: Transaction): boolean;
161
+ /** A command that undoes this writer's latest change; false when there is nothing to undo or undo is not possible now. */
162
+ export declare function undo(history: UndoManager): Command;
163
+ /** A command that redoes the latest undone change. */
164
+ export declare function redo(history: UndoManager): Command;
165
+ export {};
166
+ //# sourceMappingURL=sync.d.ts.map