@stll/folio-core 0.71.1 → 0.72.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.
Files changed (31) hide show
  1. package/README.md +2 -2
  2. package/dist/compat/eigenpal.d.ts +1 -2
  3. package/dist/compat/eigenpal.js +1 -2
  4. package/dist/controller/canonicalYjsRoom.d.ts +1 -1
  5. package/dist/controller/headerFooterEditorManager.d.ts +11 -7
  6. package/dist/controller/headerFooterEditorManager.js +39 -151
  7. package/dist/controller/hiddenEditorManager.d.ts +2 -37
  8. package/dist/controller/hiddenEditorManager.js +100 -293
  9. package/dist/controller/noteEditorManager.d.ts +3 -10
  10. package/dist/controller/noteEditorManager.js +33 -206
  11. package/dist/index.d.ts +1 -2
  12. package/dist/index.js +1 -2
  13. package/dist/managers/DocumentLoaderManager.d.ts +0 -4
  14. package/dist/managers/DocumentLoaderManager.js +4 -12
  15. package/dist/prosemirror/numberingAttr.d.ts +1 -2
  16. package/dist/prosemirror/numberingAttr.js +1 -2
  17. package/dist/prosemirror/outlineLevelAttr.d.ts +1 -2
  18. package/dist/prosemirror/outlineLevelAttr.js +1 -2
  19. package/dist/server.d.ts +1 -4
  20. package/dist/server.js +1 -4
  21. package/package.json +1 -3
  22. package/dist/controller/collaborationModules.d.ts +0 -3
  23. package/dist/controller/collaborationModules.js +0 -14
  24. package/dist/docx/server/materializeYjsDocx.d.ts +0 -30
  25. package/dist/docx/server/materializeYjsDocx.js +0 -96
  26. package/dist/docx/server/migrateYjsAttrSchema.d.ts +0 -53
  27. package/dist/docx/server/migrateYjsAttrSchema.js +0 -111
  28. package/dist/prosemirror/plugins/derivedFields.d.ts +0 -8
  29. package/dist/prosemirror/plugins/derivedFields.js +0 -52
  30. package/dist/prosemirror/yjsDocumentMetadata.d.ts +0 -89
  31. package/dist/prosemirror/yjsDocumentMetadata.js +0 -697
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/folio-core",
3
- "version": "0.71.1",
3
+ "version": "0.72.0",
4
4
  "description": "Headless, framework-neutral core of folio: the OOXML (.docx) parser, document model, ProseMirror integration, and page-layout engine. No React.",
5
5
  "keywords": [
6
6
  "document-model",
@@ -198,7 +198,6 @@
198
198
  "prosemirror-tables": "^1.8.5",
199
199
  "prosemirror-transform": "^1.12.5",
200
200
  "prosemirror-view": "^1.42.9",
201
- "y-prosemirror": "^1.3.7",
202
201
  "y-protocols": "^1.0.6",
203
202
  "yjs": "^13.6.33"
204
203
  },
@@ -214,7 +213,6 @@
214
213
  "prosemirror-tables": "^1.8.5",
215
214
  "prosemirror-transform": "^1.12.2",
216
215
  "prosemirror-view": "^1.42.6",
217
- "y-prosemirror": "^1.3.7",
218
216
  "y-protocols": "^1.0.6",
219
217
  "yjs": "^13.6.33"
220
218
  },
@@ -1,3 +0,0 @@
1
- import { CollaborationModules } from "./hiddenEditorManager.js";
2
- /** Lazily load and cache the optional collaboration runtime shared by adapters. */
3
- export declare const loadCollaborationModules: () => Promise<CollaborationModules>;
@@ -1,14 +0,0 @@
1
- // src/controller/collaborationModules.ts
2
- let collaborationModulesPromise = null;
3
- /** Lazily load and cache the optional collaboration runtime shared by adapters. */
4
- const loadCollaborationModules = () => {
5
- collaborationModulesPromise ??= Promise.all([import("y-prosemirror"), import("yjs")]).then(([yProseMirror, yjs]) => ({
6
- yProseMirror,
7
- yjs
8
- })).catch((error) => {
9
- collaborationModulesPromise = null;
10
- throw error;
11
- });
12
- return collaborationModulesPromise;
13
- };
14
- export { loadCollaborationModules };
@@ -1,30 +0,0 @@
1
- import { TaggedErrorClass } from "better-result";
2
- declare const FolioYjsDocxMaterializationErrorBase: TaggedErrorClass<"FolioYjsDocxMaterializationError">;
3
- /** Yjs fragment that stores Folio's canonical ProseMirror document. */
4
- export declare const FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME = "prosemirror";
5
- /** Maximum accepted size of a complete Yjs collaboration state update. */
6
- export declare const FOLIO_YJS_UPDATE_MAX_BYTES: number;
7
- /** Stable failure codes returned by server-side Yjs-to-DOCX materialization. */
8
- export declare const FOLIO_YJS_DOCX_MATERIALIZATION_ERROR_CODES: readonly ["empty_update", "invalid_update", "missing_document", "source_mismatch", "stale_attr_schema", "update_too_large"];
9
- /** Failure code for a rejected Yjs-to-DOCX materialization request. */
10
- export type FolioYjsDocxMaterializationErrorCode = (typeof FOLIO_YJS_DOCX_MATERIALIZATION_ERROR_CODES)[number];
11
- /** Typed failure raised when a collaboration snapshot cannot be materialized. */
12
- export declare class FolioYjsDocxMaterializationError extends FolioYjsDocxMaterializationErrorBase<{
13
- code: FolioYjsDocxMaterializationErrorCode;
14
- message: string;
15
- cause?: unknown;
16
- }> {}
17
- /** Inputs for materializing a complete Yjs state update into a DOCX package. */
18
- export type MaterializeYjsDocxOptions = {
19
- /** Original DOCX whose package parts and non-body stories must be preserved. */
20
- sourceDocx: ArrayBuffer | Uint8Array;
21
- /** Complete Yjs state update containing Folio's ProseMirror fragment. */
22
- yjsUpdate: Uint8Array;
23
- };
24
- /**
25
- * Materialize a complete Folio Yjs state update into a DOCX while preserving
26
- * package parts from the source document. This is the server-side equivalent
27
- * of the browser editor's full save path for the main document story.
28
- */
29
- export declare const materializeYjsDocx: ({ sourceDocx, yjsUpdate }: MaterializeYjsDocxOptions) => Promise<ArrayBuffer>;
30
- export {};
@@ -1,96 +0,0 @@
1
- import { fromProseDoc } from "../../prosemirror/conversion/fromProseDoc.js";
2
- import { schema } from "../../prosemirror/schema/index.js";
3
- import { FolioYjsNoteReferenceSchemaError, FolioYjsNumberingSourceSchemaError, FolioYjsRangeAnchorSchemaError, applyAttrSchemaMigrations, readYjsAttrSchemaVersion, readYjsParagraphSourceContract, withParagraphSourceContract } from "../../prosemirror/yjsDocumentMetadata.js";
4
- import { ParagraphPropertySourceValidationError } from "../paragraphPropertySource.js";
5
- import { parseDocx } from "../parser.js";
6
- import { repackDocx } from "../rezip.js";
7
- import { Result, TaggedError } from "better-result";
8
- import { initProseMirrorDoc } from "y-prosemirror";
9
- import * as Y from "yjs";
10
- // src/docx/server/materializeYjsDocx.ts
11
- const FolioYjsDocxMaterializationErrorBase = TaggedError("FolioYjsDocxMaterializationError");
12
- /** Yjs fragment that stores Folio's canonical ProseMirror document. */
13
- const FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME = "prosemirror";
14
- /** Maximum accepted size of a complete Yjs collaboration state update. */
15
- const FOLIO_YJS_UPDATE_MAX_BYTES = 10485760;
16
- /** Stable failure codes returned by server-side Yjs-to-DOCX materialization. */
17
- const FOLIO_YJS_DOCX_MATERIALIZATION_ERROR_CODES = [
18
- "empty_update",
19
- "invalid_update",
20
- "missing_document",
21
- "source_mismatch",
22
- "stale_attr_schema",
23
- "update_too_large"
24
- ];
25
- /** Typed failure raised when a collaboration snapshot cannot be materialized. */
26
- var FolioYjsDocxMaterializationError = class extends FolioYjsDocxMaterializationErrorBase {};
27
- const readProseMirrorDocument = (yjsUpdate) => {
28
- if (yjsUpdate.byteLength === 0) throw new FolioYjsDocxMaterializationError({
29
- code: "empty_update",
30
- message: "Cannot materialize DOCX from an empty Yjs update."
31
- });
32
- if (yjsUpdate.byteLength > 10485760) throw new FolioYjsDocxMaterializationError({
33
- code: "update_too_large",
34
- message: "Yjs update exceeds the DOCX materialization limit."
35
- });
36
- const ydoc = new Y.Doc();
37
- const parsed = Result.try({
38
- try: () => {
39
- Y.applyUpdate(ydoc, yjsUpdate);
40
- const fragment = ydoc.getXmlFragment(FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME);
41
- if (fragment.length === 0) throw new FolioYjsDocxMaterializationError({
42
- code: "missing_document",
43
- message: "Yjs update does not contain a Folio document."
44
- });
45
- const attrSchemaVersion = readYjsAttrSchemaVersion(ydoc);
46
- if (attrSchemaVersion.isErr()) throw new FolioYjsDocxMaterializationError({
47
- cause: attrSchemaVersion.error,
48
- code: "stale_attr_schema",
49
- message: attrSchemaVersion.error.message
50
- });
51
- applyAttrSchemaMigrations(ydoc, fragment, attrSchemaVersion.value);
52
- const contract = readYjsParagraphSourceContract(ydoc);
53
- if (!contract) throw new FolioYjsDocxMaterializationError({
54
- code: "source_mismatch",
55
- message: "Yjs update does not identify its paragraph-property source document."
56
- });
57
- return withParagraphSourceContract(initProseMirrorDoc(fragment, schema).doc, contract);
58
- },
59
- catch: (cause) => {
60
- if (cause instanceof FolioYjsDocxMaterializationError) return cause;
61
- if (cause instanceof FolioYjsNoteReferenceSchemaError || cause instanceof FolioYjsNumberingSourceSchemaError || cause instanceof FolioYjsRangeAnchorSchemaError) return new FolioYjsDocxMaterializationError({
62
- code: "stale_attr_schema",
63
- message: cause.message,
64
- cause
65
- });
66
- return new FolioYjsDocxMaterializationError({
67
- code: "invalid_update",
68
- message: "Yjs update is not a valid Folio collaboration snapshot.",
69
- cause
70
- });
71
- }
72
- });
73
- ydoc.destroy();
74
- if (parsed.isOk()) return parsed.value;
75
- throw parsed.error;
76
- };
77
- /**
78
- * Materialize a complete Folio Yjs state update into a DOCX while preserving
79
- * package parts from the source document. This is the server-side equivalent
80
- * of the browser editor's full save path for the main document story.
81
- */
82
- const materializeYjsDocx = async ({ sourceDocx, yjsUpdate }) => {
83
- const proseMirrorDocument = readProseMirrorDocument(yjsUpdate);
84
- const baseDocument = await parseDocx(sourceDocx, { preloadFonts: false });
85
- const converted = Result.try({
86
- try: () => fromProseDoc(proseMirrorDocument, baseDocument, { stylesheetSource: { type: "package" } }),
87
- catch: (cause) => cause instanceof ParagraphPropertySourceValidationError ? new FolioYjsDocxMaterializationError({
88
- code: "source_mismatch",
89
- message: "The collaboration snapshot belongs to a different source document.",
90
- cause
91
- }) : cause
92
- });
93
- if (converted.isErr()) throw converted.error;
94
- return await repackDocx(converted.value);
95
- };
96
- export { FOLIO_YJS_DOCX_MATERIALIZATION_ERROR_CODES, FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME, FOLIO_YJS_UPDATE_MAX_BYTES, FolioYjsDocxMaterializationError, materializeYjsDocx };
@@ -1,53 +0,0 @@
1
- import { FolioYjsAttrSchemaVersion } from "../../prosemirror/yjsDocumentMetadata.js";
2
- import { Result, TaggedErrorClass } from "better-result";
3
- declare const FolioYjsSnapshotMigrationErrorBase: TaggedErrorClass<"FolioYjsSnapshotMigrationError">;
4
- /** Stable failure codes returned by an offline snapshot migration. */
5
- export declare const FOLIO_YJS_SNAPSHOT_MIGRATION_ERROR_CODES: readonly ["invalid_update", "unsupported_version", "update_too_large"];
6
- /** Failure code for a snapshot that could not be migrated. */
7
- export type FolioYjsSnapshotMigrationErrorCode = (typeof FOLIO_YJS_SNAPSHOT_MIGRATION_ERROR_CODES)[number];
8
- /** Typed failure raised when a collaboration snapshot cannot be migrated. */
9
- export declare class FolioYjsSnapshotMigrationError extends FolioYjsSnapshotMigrationErrorBase<{
10
- code: FolioYjsSnapshotMigrationErrorCode;
11
- message: string;
12
- cause?: unknown;
13
- }> {}
14
- /** What an offline migration did to one snapshot. */
15
- export type FolioYjsSnapshotMigrationResult = {
16
- /** The complete state update to store in place of the input. */
17
- update: Uint8Array;
18
- /** The attr-schema version the input was written under. */
19
- fromVersion: FolioYjsAttrSchemaVersion;
20
- /** The attr-schema version the output carries. */
21
- toVersion: FolioYjsAttrSchemaVersion;
22
- /** Paragraphs whose attrs the migration rewrote. */
23
- paragraphsRewritten: number;
24
- };
25
- /**
26
- * Carry a stored collaboration snapshot forward to the attr schema this build
27
- * writes, without a ProseMirror schema and without rebuilding a single node.
28
- *
29
- * A Yjs XML element's attributes are ordinary CRDT map entries holding JSON, so
30
- * {@link applyAttrSchemaMigrations} rewrites values in the fragment directly.
31
- * Nothing here can trip y-prosemirror's node rebuild, which deletes an element
32
- * it fails to construct. The function is pure and offline: no network, no
33
- * DOCX, no editor.
34
- *
35
- * A snapshot already at the current version is returned byte for byte, so a
36
- * host may run this over its whole corpus repeatedly.
37
- *
38
- * **The contract a reseed must respect.** This function never reseeds and never
39
- * touches the paragraph-source contract: it preserves whichever source binding
40
- * the snapshot already carries. A reseed does the opposite, and Folio holds it
41
- * to one rule: *the DOCX handed to the seeding editor must be the same bytes
42
- * the host will later pass to `materializeYjsDocx` as that room's source*.
43
- * The contract is a digest of those bytes, so seeding from one document while
44
- * recording another as the room's source makes every later save fail with
45
- * `source_mismatch`. The reverse mistake is worse and Folio cannot see it: a
46
- * host that reseeds from the document a room was *created* from, rather than
47
- * from the latest content it published, produces a perfectly well-formed
48
- * snapshot whose collaborative history has been replaced by an older document.
49
- * Rebind the recorded source in the same statement that clears the seed, or do
50
- * not clear it.
51
- */
52
- export declare const migrateFolioYjsSnapshot: (update: Uint8Array) => Result<FolioYjsSnapshotMigrationResult, FolioYjsSnapshotMigrationError>;
53
- export {};
@@ -1,111 +0,0 @@
1
- import { FolioYjsNoteReferenceSchemaError, FolioYjsNumberingSourceSchemaError, FolioYjsRangeAnchorSchemaError, applyAttrSchemaMigrations, readYjsAttrSchemaVersion } from "../../prosemirror/yjsDocumentMetadata.js";
2
- import { FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME } from "./materializeYjsDocx.js";
3
- import { Result, TaggedError } from "better-result";
4
- import * as Y from "yjs";
5
- // src/docx/server/migrateYjsAttrSchema.ts
6
- const FolioYjsSnapshotMigrationErrorBase = TaggedError("FolioYjsSnapshotMigrationError");
7
- /** Stable failure codes returned by an offline snapshot migration. */
8
- const FOLIO_YJS_SNAPSHOT_MIGRATION_ERROR_CODES = [
9
- "invalid_update",
10
- "unsupported_version",
11
- "update_too_large"
12
- ];
13
- /** Typed failure raised when a collaboration snapshot cannot be migrated. */
14
- var FolioYjsSnapshotMigrationError = class extends FolioYjsSnapshotMigrationErrorBase {};
15
- /**
16
- * Carry a stored collaboration snapshot forward to the attr schema this build
17
- * writes, without a ProseMirror schema and without rebuilding a single node.
18
- *
19
- * A Yjs XML element's attributes are ordinary CRDT map entries holding JSON, so
20
- * {@link applyAttrSchemaMigrations} rewrites values in the fragment directly.
21
- * Nothing here can trip y-prosemirror's node rebuild, which deletes an element
22
- * it fails to construct. The function is pure and offline: no network, no
23
- * DOCX, no editor.
24
- *
25
- * A snapshot already at the current version is returned byte for byte, so a
26
- * host may run this over its whole corpus repeatedly.
27
- *
28
- * **The contract a reseed must respect.** This function never reseeds and never
29
- * touches the paragraph-source contract: it preserves whichever source binding
30
- * the snapshot already carries. A reseed does the opposite, and Folio holds it
31
- * to one rule: *the DOCX handed to the seeding editor must be the same bytes
32
- * the host will later pass to `materializeYjsDocx` as that room's source*.
33
- * The contract is a digest of those bytes, so seeding from one document while
34
- * recording another as the room's source makes every later save fail with
35
- * `source_mismatch`. The reverse mistake is worse and Folio cannot see it: a
36
- * host that reseeds from the document a room was *created* from, rather than
37
- * from the latest content it published, produces a perfectly well-formed
38
- * snapshot whose collaborative history has been replaced by an older document.
39
- * Rebind the recorded source in the same statement that clears the seed, or do
40
- * not clear it.
41
- */
42
- const migrateFolioYjsSnapshot = (update) => {
43
- if (update.byteLength === 0) return Result.err(new FolioYjsSnapshotMigrationError({
44
- code: "invalid_update",
45
- message: "Cannot migrate an empty Yjs update."
46
- }));
47
- if (update.byteLength > 10485760) return Result.err(new FolioYjsSnapshotMigrationError({
48
- code: "update_too_large",
49
- message: "Yjs update exceeds the snapshot migration limit."
50
- }));
51
- const ydoc = new Y.Doc();
52
- const applied = Result.try({
53
- try: () => {
54
- Y.applyUpdate(ydoc, update);
55
- },
56
- catch: (cause) => new FolioYjsSnapshotMigrationError({
57
- cause,
58
- code: "invalid_update",
59
- message: "Yjs update is not a valid Folio collaboration snapshot."
60
- })
61
- });
62
- if (applied.isErr()) {
63
- ydoc.destroy();
64
- return Result.err(applied.error);
65
- }
66
- const read = readYjsAttrSchemaVersion(ydoc);
67
- if (read.isErr()) {
68
- ydoc.destroy();
69
- return Result.err(new FolioYjsSnapshotMigrationError({
70
- cause: read.error,
71
- code: "unsupported_version",
72
- message: read.error.message
73
- }));
74
- }
75
- const fromVersion = read.value;
76
- const migratedAttrs = Result.try({
77
- try: () => applyAttrSchemaMigrations(ydoc, ydoc.getXmlFragment(FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME), fromVersion),
78
- catch: (cause) => new FolioYjsSnapshotMigrationError({
79
- cause,
80
- code: "unsupported_version",
81
- message: cause instanceof FolioYjsNoteReferenceSchemaError || cause instanceof FolioYjsNumberingSourceSchemaError || cause instanceof FolioYjsRangeAnchorSchemaError ? cause.message : "Cannot migrate the collaboration attribute schema."
82
- })
83
- });
84
- if (migratedAttrs.isErr()) {
85
- ydoc.destroy();
86
- return Result.err(migratedAttrs.error);
87
- }
88
- if (fromVersion === 15) {
89
- ydoc.destroy();
90
- return Result.ok({
91
- fromVersion,
92
- paragraphsRewritten: 0,
93
- toVersion: 15,
94
- update
95
- });
96
- }
97
- const paragraphsRewritten = migratedAttrs.value;
98
- const migrated = Y.encodeStateAsUpdate(ydoc);
99
- ydoc.destroy();
100
- if (migrated.byteLength > 10485760) return Result.err(new FolioYjsSnapshotMigrationError({
101
- code: "update_too_large",
102
- message: "The migrated Yjs update exceeds the snapshot size limit."
103
- }));
104
- return Result.ok({
105
- fromVersion,
106
- paragraphsRewritten,
107
- toVersion: 15,
108
- update: migrated
109
- });
110
- };
111
- export { FOLIO_YJS_SNAPSHOT_MIGRATION_ERROR_CODES, FolioYjsSnapshotMigrationError, migrateFolioYjsSnapshot };
@@ -1,8 +0,0 @@
1
- import { FolioDerivedFields } from "../../types/fields.js";
2
- import { Plugin } from "prosemirror-state";
3
- /**
4
- * The default session's derived fields: after each transaction that changes
5
- * the document, the owned fields outside tracked deletions show the texts the
6
- * host derives for them, in the same transaction as the edit.
7
- */
8
- export declare const createDerivedFieldsPlugin: (getDerivedFields: () => FolioDerivedFields | undefined) => Plugin;
@@ -1,52 +0,0 @@
1
- import { panic } from "better-result";
2
- import { Plugin, PluginKey, Transaction } from "prosemirror-state";
3
- import { isHistoryTransaction } from "prosemirror-history";
4
- // src/prosemirror/plugins/derivedFields.ts
5
- const REMOVAL_MARKS = /* @__PURE__ */ new Set(["deletion", "moveFrom"]);
6
- /** The y-prosemirror binding's meta key; its peer derived the texts it syncs. */
7
- const Y_SYNC_META = "y-sync$";
8
- /**
9
- * A local edit, not an undo or redo (which restores fields as they stood) or
10
- * a room update, judged by the transaction that started the dispatch.
11
- */
12
- const derivesFields = (transaction) => {
13
- if (!transaction.docChanged) return false;
14
- const appendedTo = transaction.getMeta("appendedTransaction");
15
- const root = appendedTo instanceof Transaction ? appendedTo : transaction;
16
- return !isHistoryTransaction(root) && root.getMeta(Y_SYNC_META) === void 0;
17
- };
18
- /**
19
- * The default session's derived fields: after each transaction that changes
20
- * the document, the owned fields outside tracked deletions show the texts the
21
- * host derives for them, in the same transaction as the edit.
22
- */
23
- const createDerivedFieldsPlugin = (getDerivedFields) => new Plugin({
24
- key: new PluginKey("folioDerivedFields"),
25
- appendTransaction(transactions, _previous, state) {
26
- const derived = getDerivedFields();
27
- if (derived === void 0 || !transactions.some(derivesFields)) return null;
28
- const owned = [];
29
- const instructions = [];
30
- state.doc.descendants((node, position) => {
31
- if (node.type.name !== "field") return true;
32
- const { instruction, displayText } = node.attrs;
33
- if (typeof instruction !== "string" || typeof displayText !== "string" || !derived.owns(instruction) || node.marks.some((mark) => REMOVAL_MARKS.has(mark.type.name))) return false;
34
- owned.push({
35
- position,
36
- displayText
37
- });
38
- instructions.push(instruction);
39
- return false;
40
- });
41
- if (owned.length === 0) return null;
42
- const texts = derived.displayTexts(instructions);
43
- if (texts.length !== owned.length) panic(`derivedFields.displayTexts returned ${texts.length} texts for ${owned.length} fields.`);
44
- const transaction = state.tr;
45
- for (const [index, { position, displayText }] of owned.entries()) {
46
- const text = texts[index];
47
- if (text !== void 0 && text !== displayText) transaction.setNodeAttribute(position, "displayText", text);
48
- }
49
- return transaction.docChanged ? transaction : null;
50
- }
51
- });
52
- export { createDerivedFieldsPlugin };
@@ -1,89 +0,0 @@
1
- import { Result, TaggedErrorClass } from "better-result";
2
- import { Node } from "prosemirror-model";
3
- import * as Y from "yjs";
4
- declare const FolioYjsAttrSchemaVersionErrorBase: TaggedErrorClass<"FolioYjsAttrSchemaVersionError">;
5
- /**
6
- * Carry a snapshot written under `version` forward to the next version,
7
- * rewriting the fragment in place and answering how many paragraphs changed.
8
- */
9
- type AttrSchemaMigrationStep = (fragment: Y.XmlFragment) => number;
10
- /** Every attr-schema version this build reads, oldest first, with no gaps. */
11
- declare const FOLIO_YJS_ATTR_SCHEMA_VERSIONS: readonly [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
12
- /** An attr-schema version this build can read. */
13
- export type FolioYjsAttrSchemaVersion = (typeof FOLIO_YJS_ATTR_SCHEMA_VERSIONS)[number];
14
- /**
15
- * The attr-schema version this build writes. Derived against the migration map
16
- * so the constant and the map cannot disagree.
17
- */
18
- export declare const FOLIO_YJS_ATTR_SCHEMA_VERSION: 15;
19
- declare const FolioYjsRangeAnchorSchemaErrorBase: TaggedErrorClass<"FolioYjsRangeAnchorSchemaError">;
20
- /** A stored point anchor must retain a valid, ordered source-marker pair. */
21
- export declare class FolioYjsRangeAnchorSchemaError extends FolioYjsRangeAnchorSchemaErrorBase<{
22
- message: string;
23
- schemaVersion: FolioYjsAttrSchemaVersion;
24
- }> {}
25
- declare const FolioYjsNoteReferenceSchemaErrorBase: TaggedErrorClass<"FolioYjsNoteReferenceSchemaError">;
26
- export declare class FolioYjsNoteReferenceSchemaError extends FolioYjsNoteReferenceSchemaErrorBase<{
27
- message: string;
28
- schemaVersion: FolioYjsAttrSchemaVersion;
29
- requiredSchemaVersion: FolioYjsAttrSchemaVersion;
30
- }> {}
31
- declare const FolioYjsNumberingSourceSchemaErrorBase: TaggedErrorClass<"FolioYjsNumberingSourceSchemaError">;
32
- export declare class FolioYjsNumberingSourceSchemaError extends FolioYjsNumberingSourceSchemaErrorBase<{
33
- message: string;
34
- schemaVersion: FolioYjsAttrSchemaVersion;
35
- requiredSchemaVersion: FolioYjsAttrSchemaVersion;
36
- }> {}
37
- /**
38
- * The steps that carry a snapshot written under `fromVersion` up to
39
- * {@link FOLIO_YJS_ATTR_SCHEMA_VERSION}, in order. Empty when the snapshot is
40
- * already current.
41
- */
42
- export declare const attrSchemaMigrationSteps: (fromVersion: FolioYjsAttrSchemaVersion) => readonly AttrSchemaMigrationStep[];
43
- /**
44
- * Carry a fragment this build is about to read or write up to the attr shape
45
- * this build writes, and stamp the marker.
46
- *
47
- * Every entry point that hands a fragment to `initProseMirrorDoc` calls this,
48
- * for two reasons that are the same reason. A step that rewrites values has to
49
- * run before a node is built from them, or the build reads the old shape as
50
- * the new one. And the marker has to say what the fragment may now hold before
51
- * the first edit writes an attr of this build's shape into it, because an
52
- * older build reading an unmarked snapshot drops what it does not know without
53
- * a trace.
54
- *
55
- * Returns how many elements the steps rewrote.
56
- */
57
- export declare const applyAttrSchemaMigrations: (ydoc: Y.Doc, fragment: Y.XmlFragment, fromVersion: FolioYjsAttrSchemaVersion) => number;
58
- /** Raised when a snapshot's attr-schema marker is ahead of the running code. */
59
- export declare class FolioYjsAttrSchemaVersionError extends FolioYjsAttrSchemaVersionErrorBase<{
60
- message: string;
61
- /** The marker exactly as stored, so the host can log what it refused. */
62
- marker: unknown;
63
- /** The newest attr-schema version this build understands. */
64
- supportedVersion: FolioYjsAttrSchemaVersion;
65
- }> {}
66
- /**
67
- * The attr-schema version a collaboration document was written under.
68
- *
69
- * An absent marker is version 0: every snapshot predates the marker, so no
70
- * backfill is needed to classify one. An older version loads, because
71
- * {@link attrSchemaMigrationSteps} says what it means. A marker this
72
- * build does not know is a snapshot written by newer code, and reading it would
73
- * be a silent misread: ProseMirror copies unknown attr values into the node
74
- * verbatim and drops unknown keys without a trace. It fails instead.
75
- */
76
- export declare const readYjsAttrSchemaVersion: (ydoc: Y.Doc) => Result<FolioYjsAttrSchemaVersion, FolioYjsAttrSchemaVersionError>;
77
- export declare const proseDocumentParagraphSourceContract: (document: Node) => string | null;
78
- /** Stamp the attr-schema version of the build that wrote the current fragment. */
79
- export declare const writeYjsAttrSchemaVersion: (ydoc: Y.Doc) => void;
80
- /**
81
- * Write both metadata bindings for a freshly seeded collaboration document.
82
- * The attr-schema version is written unconditionally; the paragraph-source
83
- * contract only when the seeding document carries one, because a document
84
- * built in memory rather than parsed from a package has no source to bind to.
85
- */
86
- export declare const writeYjsDocumentMetadata: (ydoc: Y.Doc, document: Node) => void;
87
- export declare const readYjsParagraphSourceContract: (ydoc: Y.Doc) => string | null;
88
- export declare const withParagraphSourceContract: (document: Node, contract: string) => Node;
89
- export {};