@stll/folio-core 0.71.1 → 0.73.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 (213) hide show
  1. package/README.md +14 -8
  2. package/dist/ai-edits/apply.d.ts +6 -114
  3. package/dist/ai-edits/apply.js +9 -131
  4. package/dist/ai-edits/applyTypes.d.ts +85 -0
  5. package/dist/ai-edits/applyTypes.js +24 -0
  6. package/dist/ai-edits/clean-text.d.ts +7 -1
  7. package/dist/ai-edits/clean-text.js +23 -2
  8. package/dist/ai-edits/finalSectionReview.d.ts +1 -1
  9. package/dist/ai-edits/headless.d.ts +29 -147
  10. package/dist/ai-edits/headless.js +213 -1634
  11. package/dist/ai-edits/index.d.ts +3 -3
  12. package/dist/ai-edits/index.js +2 -3
  13. package/dist/ai-edits/pending-suggestions.d.ts +14 -4
  14. package/dist/ai-edits/pending-suggestions.js +183 -90
  15. package/dist/ai-edits/result-validation.js +1 -1
  16. package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
  17. package/dist/ai-edits/snapshot.js +8 -3
  18. package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
  19. package/dist/ai-edits/table-cell-mutations.js +1 -1
  20. package/dist/ai-edits/table-geometry.d.ts +1 -1
  21. package/dist/ai-edits/table-geometry.js +1 -1
  22. package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
  23. package/dist/ai-edits/table-row-column-mutations.js +1 -1
  24. package/dist/ai-edits/tableNodes.d.ts +38 -0
  25. package/dist/ai-edits/tableNodes.js +86 -0
  26. package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
  27. package/dist/ai-edits/undefinedReferences.d.ts +7 -0
  28. package/dist/canonical/batchCommentReferences.js +1 -0
  29. package/dist/canonical/canonicalInlineProjection.js +1 -1
  30. package/dist/canonical/canonicalPublicOperations.js +228 -64
  31. package/dist/canonical/canonicalSession.d.ts +9 -1
  32. package/dist/canonical/canonicalSession.js +95 -15
  33. package/dist/compare/compare.d.ts +1 -1
  34. package/dist/compare/inline-atoms-model.d.ts +1 -1
  35. package/dist/compare/inline-atoms.d.ts +2 -2
  36. package/dist/compare/inline-provenance-model.d.ts +1 -1
  37. package/dist/compare/inline-provenance.d.ts +2 -2
  38. package/dist/compat/eigenpal.d.ts +3 -4
  39. package/dist/compat/eigenpal.js +2 -4
  40. package/dist/controller/canonicalClipboard.d.ts +13 -3
  41. package/dist/controller/canonicalClipboard.js +185 -49
  42. package/dist/controller/canonicalClipboardResources.d.ts +9 -1
  43. package/dist/controller/canonicalClipboardResources.js +22 -2
  44. package/dist/controller/canonicalReview.d.ts +1 -1
  45. package/dist/controller/canonicalReview.js +1 -1
  46. package/dist/controller/canonicalStructure.js +1 -1
  47. package/dist/controller/canonicalWatermark.d.ts +10 -0
  48. package/dist/controller/canonicalWatermark.js +37 -0
  49. package/dist/controller/canonicalYjsRoom.d.ts +1 -1
  50. package/dist/controller/headerFooterEditorManager.d.ts +11 -7
  51. package/dist/controller/headerFooterEditorManager.js +39 -151
  52. package/dist/controller/hiddenEditorApi.d.ts +1 -1
  53. package/dist/controller/hiddenEditorManager.d.ts +6 -40
  54. package/dist/controller/hiddenEditorManager.js +173 -306
  55. package/dist/controller/noteEditorManager.d.ts +3 -10
  56. package/dist/controller/noteEditorManager.js +33 -206
  57. package/dist/document-operations-apply.d.ts +15 -0
  58. package/dist/document-operations-apply.js +280 -0
  59. package/dist/document-operations.d.ts +1 -14
  60. package/dist/document-operations.js +2 -279
  61. package/dist/docx/modelValidation.js +1 -1
  62. package/dist/docx/paragraphParser.js +2 -2
  63. package/dist/docx/paragraphPropertySource.d.ts +1 -1
  64. package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
  65. package/dist/docx/reviewResolutionProvenance.js +32 -9
  66. package/dist/docx/revisionIdNormalization.js +30 -7
  67. package/dist/docx/rezip.js +1 -1
  68. package/dist/docx/serializer/borderSerializer.js +1 -1
  69. package/dist/docx/serializer/commentSerializer.js +1 -1
  70. package/dist/docx/serializer/documentSerializer.js +1 -1
  71. package/dist/docx/serializer/paragraphSerializer.js +3 -3
  72. package/dist/docx/serializer/runSerializer.js +1 -1
  73. package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
  74. package/dist/docx/serializer/tableSerializer.js +5 -37
  75. package/dist/docx/serializer/textFormattingSerializer.js +1 -1
  76. package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
  77. package/dist/docx/server/templatePlan/apply.d.ts +15 -0
  78. package/dist/docx/server/templatePlan/apply.js +600 -0
  79. package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
  80. package/dist/docx/server/templatePlan/blocks.js +355 -0
  81. package/dist/docx/server/templatePlan/builders.d.ts +72 -0
  82. package/dist/docx/server/templatePlan/builders.js +237 -0
  83. package/dist/docx/server/templatePlan/emit.d.ts +118 -0
  84. package/dist/docx/server/templatePlan/emit.js +466 -0
  85. package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
  86. package/dist/docx/server/templatePlan/emphasis.js +173 -0
  87. package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
  88. package/dist/docx/server/templatePlan/inspect.js +177 -0
  89. package/dist/docx/server/templatePlan/labels.d.ts +36 -0
  90. package/dist/docx/server/templatePlan/labels.js +126 -0
  91. package/dist/docx/server/templatePlan/package.d.ts +34 -0
  92. package/dist/docx/server/templatePlan/package.js +99 -0
  93. package/dist/docx/server/templatePlan/plan.d.ts +143 -0
  94. package/dist/docx/server/templatePlan/plan.js +841 -0
  95. package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
  96. package/dist/docx/server/templatePlan/planShape.js +161 -0
  97. package/dist/docx/server/templatePlan/resources.d.ts +41 -0
  98. package/dist/docx/server/templatePlan/resources.js +136 -0
  99. package/dist/docx/server/templatePlan/story.d.ts +128 -0
  100. package/dist/docx/server/templatePlan/story.js +440 -0
  101. package/dist/docx/server/templatePlan/types.d.ts +406 -0
  102. package/dist/docx/server/templatePlan/types.js +28 -0
  103. package/dist/docx/server/templatePlan/verify.d.ts +40 -0
  104. package/dist/docx/server/templatePlan/verify.js +968 -0
  105. package/dist/docx/server/templatePlan/xml.d.ts +69 -0
  106. package/dist/docx/server/templatePlan/xml.js +119 -0
  107. package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
  108. package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
  109. package/dist/docx/storyBlockReplay.js +1 -1
  110. package/dist/docx/structuralXmlPatch.js +9 -1
  111. package/dist/docx/tableGridXml.d.ts +30 -0
  112. package/dist/docx/tableGridXml.js +54 -0
  113. package/dist/docx/tableParser.js +7 -0
  114. package/dist/docx/xmlParser.js +1 -1
  115. package/dist/index.d.ts +3 -4
  116. package/dist/index.js +2 -4
  117. package/dist/internal/paragraphFormattingSerialization.js +1 -1
  118. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  119. package/dist/managers/ContextMenuManager.js +2 -1
  120. package/dist/managers/DocumentLoaderManager.d.ts +0 -4
  121. package/dist/managers/DocumentLoaderManager.js +4 -12
  122. package/dist/managers/editorShortcuts.d.ts +1 -1
  123. package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
  124. package/dist/prosemirror/canonicalCommands.d.ts +1 -1
  125. package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
  126. package/dist/prosemirror/canonicalTableCommands.js +2 -2
  127. package/dist/prosemirror/commands/comments.js +3 -3
  128. package/dist/prosemirror/commands/contentControls.d.ts +1 -1
  129. package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
  130. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  131. package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
  132. package/dist/prosemirror/commands/sectionBreak.js +1 -1
  133. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
  134. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
  135. package/dist/prosemirror/commentRecords.d.ts +1 -1
  136. package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
  137. package/dist/prosemirror/conversion/fromProseDoc.js +1 -1
  138. package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
  139. package/dist/prosemirror/documentStructureCounts.js +76 -0
  140. package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
  141. package/dist/prosemirror/extensions/StarterKit.d.ts +1 -1
  142. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +1 -7
  143. package/dist/prosemirror/extensions/core/HistoryExtension.js +5 -13
  144. package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
  145. package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
  146. package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
  147. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
  148. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +2 -35
  149. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +4 -142
  150. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +3 -87
  151. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +7 -162
  152. package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
  153. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
  154. package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
  155. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
  156. package/dist/prosemirror/extensions/nodes/TableExtension.js +2 -2
  157. package/dist/prosemirror/extensions/types.d.ts +1 -1
  158. package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
  159. package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
  160. package/dist/prosemirror/index.d.ts +1 -1
  161. package/dist/prosemirror/index.js +1 -1
  162. package/dist/prosemirror/insertionGaps.d.ts +1 -1
  163. package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
  164. package/dist/prosemirror/listNumbering.d.ts +1 -1
  165. package/dist/prosemirror/lockedControls.d.ts +1 -1
  166. package/dist/prosemirror/markupViewProjection.d.ts +1 -1
  167. package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
  168. package/dist/prosemirror/noteReferenceReview.js +1 -1
  169. package/dist/prosemirror/numberingAttr.d.ts +1 -2
  170. package/dist/prosemirror/numberingAttr.js +1 -2
  171. package/dist/prosemirror/outlineLevelAttr.d.ts +1 -2
  172. package/dist/prosemirror/outlineLevelAttr.js +1 -2
  173. package/dist/prosemirror/paraIds.d.ts +46 -0
  174. package/dist/prosemirror/paraIds.js +152 -0
  175. package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
  176. package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
  177. package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
  178. package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
  179. package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
  180. package/dist/prosemirror/pastedCommentCopies.js +1 -1
  181. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
  182. package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
  183. package/dist/prosemirror/plugins/suggestionMode.d.ts +1 -1
  184. package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
  185. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
  186. package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
  187. package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
  188. package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
  189. package/dist/prosemirror/replacedAnnotations.js +16 -1
  190. package/dist/prosemirror/revisionCarriers.d.ts +1 -1
  191. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
  192. package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
  193. package/dist/prosemirror/selectionBounds.d.ts +10 -0
  194. package/dist/prosemirror/selectionBounds.js +22 -0
  195. package/dist/prosemirror/storyListNumbering.d.ts +1 -1
  196. package/dist/prosemirror/tableCellPaste.d.ts +1 -1
  197. package/dist/prosemirror/tableGridMutation.d.ts +1 -1
  198. package/dist/prosemirror/textInput.d.ts +1 -1
  199. package/dist/server.d.ts +7 -5
  200. package/dist/server.js +6 -4
  201. package/dist/types/canonicalCapabilities.d.ts +8 -41
  202. package/dist/types/canonicalCapabilities.js +6 -34
  203. package/package.json +4 -6
  204. package/dist/controller/collaborationModules.d.ts +0 -3
  205. package/dist/controller/collaborationModules.js +0 -14
  206. package/dist/docx/server/materializeYjsDocx.d.ts +0 -30
  207. package/dist/docx/server/materializeYjsDocx.js +0 -96
  208. package/dist/docx/server/migrateYjsAttrSchema.d.ts +0 -53
  209. package/dist/docx/server/migrateYjsAttrSchema.js +0 -111
  210. package/dist/prosemirror/plugins/derivedFields.d.ts +0 -8
  211. package/dist/prosemirror/plugins/derivedFields.js +0 -52
  212. package/dist/prosemirror/yjsDocumentMetadata.d.ts +0 -89
  213. package/dist/prosemirror/yjsDocumentMetadata.js +0 -697
@@ -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 {};