@stll/folio-core 0.54.2 → 0.56.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 (267) hide show
  1. package/dist/ai-edits/apply.js +185 -33
  2. package/dist/ai-edits/headless.js +3 -2
  3. package/dist/ai-edits/types.d.ts +7 -1
  4. package/dist/compare/compare.js +1 -0
  5. package/dist/compare/content-types.d.ts +3 -15
  6. package/dist/compare/reproducible-package.d.ts +0 -17
  7. package/dist/compare/reproducible-package.js +12 -18
  8. package/dist/controller/canonicalClipboard.d.ts +23 -0
  9. package/dist/controller/canonicalClipboard.js +476 -0
  10. package/dist/controller/canonicalClipboardResources.d.ts +21 -0
  11. package/dist/controller/canonicalClipboardResources.js +382 -0
  12. package/dist/controller/canonicalComposition.d.ts +53 -0
  13. package/dist/controller/canonicalComposition.js +296 -0
  14. package/dist/controller/canonicalInlineProjection.d.ts +113 -0
  15. package/dist/controller/canonicalInlineProjection.js +393 -0
  16. package/dist/controller/canonicalInput.d.ts +54 -0
  17. package/dist/controller/canonicalInput.js +377 -0
  18. package/dist/controller/canonicalInputTimer.d.ts +7 -0
  19. package/dist/controller/canonicalInputTimer.js +11 -0
  20. package/dist/controller/canonicalOperations.d.ts +22 -0
  21. package/dist/controller/canonicalOperations.js +85 -0
  22. package/dist/controller/canonicalPublicOperations.d.ts +48 -0
  23. package/dist/controller/canonicalPublicOperations.js +556 -0
  24. package/dist/controller/canonicalReview.d.ts +12 -0
  25. package/dist/controller/canonicalReview.js +19 -0
  26. package/dist/controller/canonicalSession.d.ts +167 -0
  27. package/dist/controller/canonicalSession.js +1186 -0
  28. package/dist/controller/canonicalStoryEditor.d.ts +36 -0
  29. package/dist/controller/canonicalStoryEditor.js +87 -0
  30. package/dist/controller/canonicalStructure.d.ts +16 -0
  31. package/dist/controller/canonicalStructure.js +322 -0
  32. package/dist/controller/canonicalTocSelection.d.ts +11 -0
  33. package/dist/controller/canonicalTocSelection.js +43 -0
  34. package/dist/controller/folioEditor.d.ts +3 -10
  35. package/dist/controller/folioEditor.js +14 -4
  36. package/dist/controller/headerFooterEditorManager.d.ts +5 -0
  37. package/dist/controller/headerFooterEditorManager.js +72 -3
  38. package/dist/controller/hiddenEditorApi.d.ts +45 -0
  39. package/dist/controller/hiddenEditorApi.js +29 -8
  40. package/dist/controller/hiddenEditorManager.d.ts +13 -2
  41. package/dist/controller/hiddenEditorManager.js +639 -31
  42. package/dist/controller/layoutPipeline.d.ts +1 -1
  43. package/dist/controller/layoutPipeline.js +2 -0
  44. package/dist/controller/noteEditorManager.d.ts +5 -0
  45. package/dist/controller/noteEditorManager.js +114 -15
  46. package/dist/document-operations.d.ts +8 -1
  47. package/dist/document-operations.js +6 -4
  48. package/dist/docx/attributeRemainder.js +1 -0
  49. package/dist/docx/blockPlainText.d.ts +1 -1
  50. package/dist/docx/blockPlainText.js +11 -3
  51. package/dist/docx/canonicalResourceSave.d.ts +16 -0
  52. package/dist/docx/canonicalResourceSave.js +27 -0
  53. package/dist/docx/canonicalSave.d.ts +29 -0
  54. package/dist/docx/canonicalSave.js +101 -0
  55. package/dist/docx/canonicalSessionInput.d.ts +11 -0
  56. package/dist/docx/canonicalSessionInput.js +27 -0
  57. package/dist/docx/canonicalStoryRepack.d.ts +10 -0
  58. package/dist/docx/canonicalStoryRepack.js +74 -0
  59. package/dist/docx/contentTypeRegistry.d.ts +8 -0
  60. package/dist/docx/contentTypeRegistry.js +64 -0
  61. package/dist/docx/documentParser.d.ts +1 -13
  62. package/dist/docx/documentParser.js +1 -47
  63. package/dist/docx/ensureParaIds.d.ts +7 -1
  64. package/dist/docx/ensureParaIds.js +173 -215
  65. package/dist/docx/foldedListNumberFields.d.ts +85 -0
  66. package/dist/docx/foldedListNumberFields.js +267 -0
  67. package/dist/docx/footnoteParser.d.ts +1 -11
  68. package/dist/docx/footnoteParser.js +1 -16
  69. package/dist/docx/headerFooterParser.d.ts +1 -9
  70. package/dist/docx/headerFooterParser.js +1 -12
  71. package/dist/docx/headerFooterVerbatim.d.ts +39 -1
  72. package/dist/docx/headerFooterVerbatim.js +173 -2
  73. package/dist/docx/imageParser.d.ts +13 -1
  74. package/dist/docx/imageParser.js +20 -11
  75. package/dist/docx/metadataPrivacy.js +6 -1
  76. package/dist/docx/noteIds.d.ts +5 -0
  77. package/dist/docx/noteIds.js +6 -2
  78. package/dist/docx/noteReferenceMark.d.ts +3 -1
  79. package/dist/docx/noteReferenceMark.js +15 -14
  80. package/dist/docx/numberingParser.d.ts +3 -1
  81. package/dist/docx/numberingParser.js +17 -3
  82. package/dist/docx/packageParts.d.ts +3 -1
  83. package/dist/docx/packageParts.js +74 -19
  84. package/dist/docx/paragraphMarkPropertyPresence.d.ts +9 -0
  85. package/dist/docx/paragraphMarkPropertyPresence.js +21 -0
  86. package/dist/docx/paragraphParser.js +101 -53
  87. package/dist/docx/paragraphPropertySource.d.ts +15 -1
  88. package/dist/docx/paragraphPropertySource.js +77 -22
  89. package/dist/docx/parser.js +3 -1
  90. package/dist/docx/removeHeaderFooterParts.js +17 -6
  91. package/dist/docx/reviewHistoryNamespace.d.ts +4 -0
  92. package/dist/docx/reviewHistoryNamespace.js +4 -0
  93. package/dist/docx/reviewResolutionProvenance.d.ts +25 -0
  94. package/dist/docx/reviewResolutionProvenance.js +153 -0
  95. package/dist/docx/rezip.d.ts +54 -6
  96. package/dist/docx/rezip.js +835 -257
  97. package/dist/docx/runConsolidator.d.ts +2 -58
  98. package/dist/docx/runConsolidator.js +3 -175
  99. package/dist/docx/runParser.d.ts +2 -1
  100. package/dist/docx/runParser.js +156 -116
  101. package/dist/docx/saveDiagnostics.d.ts +22 -0
  102. package/dist/docx/saveDiagnostics.js +0 -0
  103. package/dist/docx/selectiveSave.d.ts +3 -1
  104. package/dist/docx/selectiveSave.js +36 -4
  105. package/dist/docx/selectiveXmlPatch.d.ts +16 -8
  106. package/dist/docx/selectiveXmlPatch.js +81 -7
  107. package/dist/docx/serializer/documentSerializer.d.ts +9 -2
  108. package/dist/docx/serializer/documentSerializer.js +29 -10
  109. package/dist/docx/serializer/headerFooterSerializer.d.ts +5 -1
  110. package/dist/docx/serializer/headerFooterSerializer.js +19 -11
  111. package/dist/docx/serializer/noteSerializer.d.ts +2 -2
  112. package/dist/docx/serializer/noteSerializer.js +24 -8
  113. package/dist/docx/serializer/paragraphSerializer.js +41 -4
  114. package/dist/docx/serializer/partNamespaces.js +2 -1
  115. package/dist/docx/serializer/runSerializer.js +3 -1
  116. package/dist/docx/server/applyDocxXmlPatchProposal.js +14 -9
  117. package/dist/docx/settingsHeaderFooterUpdate.d.ts +5 -0
  118. package/dist/docx/settingsHeaderFooterUpdate.js +90 -0
  119. package/dist/docx/settingsParser.d.ts +1 -2
  120. package/dist/docx/settingsParser.js +5 -6
  121. package/dist/docx/storyBlockReplay.d.ts +31 -0
  122. package/dist/docx/storyBlockReplay.js +471 -0
  123. package/dist/docx/storyPlainText.d.ts +20 -0
  124. package/dist/docx/storyPlainText.js +23 -0
  125. package/dist/docx/streamingXmlParser.d.ts +22 -1
  126. package/dist/docx/streamingXmlParser.js +49 -3
  127. package/dist/docx/structuralXmlPatch.js +18 -23
  128. package/dist/docx/styleParser.d.ts +5 -1
  129. package/dist/docx/styleParser.js +1 -1
  130. package/dist/docx/tableParser.d.ts +1 -8
  131. package/dist/docx/tableParser.js +1 -28
  132. package/dist/docx/textBoxParser.d.ts +1 -5
  133. package/dist/docx/textBoxParser.js +1 -20
  134. package/dist/docx/unzip.js +6 -1
  135. package/dist/docx/verbatimCapture.d.ts +3 -1
  136. package/dist/docx/verbatimCapture.js +49 -6
  137. package/dist/i18n/messages/ar.gen.d.ts +5 -0
  138. package/dist/i18n/messages/ar.gen.js +656 -0
  139. package/dist/i18n/messages/cs.gen.d.ts +5 -0
  140. package/dist/i18n/messages/cs.gen.js +656 -0
  141. package/dist/i18n/messages/de.gen.d.ts +5 -0
  142. package/dist/i18n/messages/de.gen.js +656 -0
  143. package/dist/i18n/messages/en.gen.d.ts +5 -0
  144. package/dist/i18n/messages/en.gen.js +656 -0
  145. package/dist/i18n/messages/es.gen.d.ts +5 -0
  146. package/dist/i18n/messages/es.gen.js +656 -0
  147. package/dist/i18n/messages/et.gen.d.ts +5 -0
  148. package/dist/i18n/messages/et.gen.js +656 -0
  149. package/dist/i18n/messages/fr.gen.d.ts +5 -0
  150. package/dist/i18n/messages/fr.gen.js +656 -0
  151. package/dist/i18n/messages/he.gen.d.ts +5 -0
  152. package/dist/i18n/messages/he.gen.js +656 -0
  153. package/dist/i18n/messages/hi.gen.d.ts +5 -0
  154. package/dist/i18n/messages/hi.gen.js +656 -0
  155. package/dist/i18n/messages/hu.gen.d.ts +5 -0
  156. package/dist/i18n/messages/hu.gen.js +656 -0
  157. package/dist/i18n/messages/locales.d.ts +5 -0
  158. package/dist/i18n/messages/locales.js +22 -0
  159. package/dist/i18n/messages/lt.gen.d.ts +5 -0
  160. package/dist/i18n/messages/lt.gen.js +656 -0
  161. package/dist/i18n/messages/lv.gen.d.ts +5 -0
  162. package/dist/i18n/messages/lv.gen.js +656 -0
  163. package/dist/i18n/messages/pl.gen.d.ts +5 -0
  164. package/dist/i18n/messages/pl.gen.js +656 -0
  165. package/dist/i18n/messages/pt-BR.gen.d.ts +5 -0
  166. package/dist/i18n/messages/pt-BR.gen.js +656 -0
  167. package/dist/i18n/messages/sk.gen.d.ts +5 -0
  168. package/dist/i18n/messages/sk.gen.js +656 -0
  169. package/dist/i18n/messages/tr.gen.d.ts +5 -0
  170. package/dist/i18n/messages/tr.gen.js +656 -0
  171. package/dist/i18n/messages/zh-CN.gen.d.ts +5 -0
  172. package/dist/i18n/messages/zh-CN.gen.js +656 -0
  173. package/dist/i18n/messages.d.ts +2 -3
  174. package/dist/i18n/messages.js +1 -19
  175. package/dist/internal/acceptedBlockProjection.d.ts +12 -0
  176. package/dist/internal/acceptedBlockProjection.js +45 -0
  177. package/dist/internal/noteMarkerAttrs.d.ts +8 -0
  178. package/dist/internal/noteMarkerAttrs.js +16 -0
  179. package/dist/internal/pageBreakRunSourceDescendantIndex.js +1 -0
  180. package/dist/internal/prosemirrorAttrBoundary.d.ts +21 -0
  181. package/dist/internal/prosemirrorAttrBoundary.js +50 -0
  182. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  183. package/dist/layout-bridge/convert/footnoteLayout.js +3 -3
  184. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  185. package/dist/layout-bridge/convert/headerFooterLayout.js +1 -0
  186. package/dist/layout-bridge/convert/noteReferences.d.ts +1 -3
  187. package/dist/layout-bridge/convert/noteReferences.js +1 -6
  188. package/dist/layout-bridge/convert/paragraphRuns.js +2 -4
  189. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +2 -2
  190. package/dist/layout-bridge/convert/toFlowBlocks.js +2 -2
  191. package/dist/managers/DocumentLoaderManager.d.ts +1 -0
  192. package/dist/managers/DocumentLoaderManager.js +9 -1
  193. package/dist/markdown/escape.d.ts +3 -1
  194. package/dist/markdown/escape.js +9 -2
  195. package/dist/markdown/renderBlock.js +20 -121
  196. package/dist/markdown/renderParagraph.js +13 -15
  197. package/dist/markdown/renderRuns.d.ts +7 -1
  198. package/dist/markdown/renderRuns.js +35 -15
  199. package/dist/markdown/renderTable.js +2 -0
  200. package/dist/markdown/types.d.ts +3 -9
  201. package/dist/prosemirror/attrs/index.d.ts +2 -12
  202. package/dist/prosemirror/attrs/index.js +22 -48
  203. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +2 -1
  204. package/dist/prosemirror/canonicalCommands.d.ts +121 -0
  205. package/dist/prosemirror/canonicalCommands.js +35 -0
  206. package/dist/prosemirror/canonicalSelectionRange.d.ts +9 -0
  207. package/dist/prosemirror/canonicalSelectionRange.js +15 -0
  208. package/dist/prosemirror/clipboardIntent.d.ts +7 -0
  209. package/dist/prosemirror/clipboardIntent.js +9 -0
  210. package/dist/prosemirror/commands/pageBreak.js +15 -1
  211. package/dist/prosemirror/commands/pastePlainText.js +2 -1
  212. package/dist/prosemirror/commentReferenceAttrs.d.ts +2 -1
  213. package/dist/prosemirror/conversion/fromProseDoc.js +91 -19
  214. package/dist/prosemirror/conversion/hyphenTextCarriers.d.ts +8 -0
  215. package/dist/prosemirror/conversion/hyphenTextCarriers.js +8 -0
  216. package/dist/prosemirror/conversion/listRenderingDefinition.d.ts +6 -0
  217. package/dist/prosemirror/conversion/listRenderingDefinition.js +97 -0
  218. package/dist/prosemirror/conversion/toProseDoc.d.ts +11 -4
  219. package/dist/prosemirror/conversion/toProseDoc.js +55 -14
  220. package/dist/prosemirror/executeEditorCommand.d.ts +11 -0
  221. package/dist/prosemirror/executeEditorCommand.js +26 -0
  222. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  223. package/dist/prosemirror/extensions/core/ParagraphExtension.js +88 -48
  224. package/dist/prosemirror/extensions/features/ListExtension.js +18 -5
  225. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +5 -2
  226. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +13 -1
  227. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +56 -28
  228. package/dist/prosemirror/extensions/marks/TextColorExtension.js +3 -2
  229. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -0
  230. package/dist/prosemirror/extensions/marks/markUtils.js +72 -8
  231. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.d.ts +6 -0
  232. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +36 -0
  233. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.js +4 -2
  234. package/dist/prosemirror/insertOperations.js +2 -1
  235. package/dist/prosemirror/listMarker.d.ts +1 -0
  236. package/dist/prosemirror/listMarker.js +16 -7
  237. package/dist/prosemirror/listNumbering.js +26 -5
  238. package/dist/prosemirror/listRenderingAttrs.d.ts +1 -0
  239. package/dist/prosemirror/listRenderingAttrs.js +3 -0
  240. package/dist/prosemirror/markupViewNotes.js +3 -2
  241. package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +2 -1
  242. package/dist/prosemirror/noteReferenceReview.js +5 -3
  243. package/dist/prosemirror/paragraphPropertyCarry.d.ts +7 -1
  244. package/dist/prosemirror/paragraphPropertyCarry.js +8 -3
  245. package/dist/prosemirror/plugins/suggestionMode.js +57 -7
  246. package/dist/prosemirror/rangeAnchorAttrs.d.ts +2 -1
  247. package/dist/prosemirror/runFormattingFromMarks.d.ts +4 -1
  248. package/dist/prosemirror/runFormattingFromMarks.js +15 -1
  249. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +2 -1
  250. package/dist/prosemirror/runFormattingInlineCarriers.js +4 -1
  251. package/dist/prosemirror/schema/marks.d.ts +2 -0
  252. package/dist/prosemirror/schema/nodes.d.ts +10 -2
  253. package/dist/prosemirror/textBoxAnchorAttrs.d.ts +2 -1
  254. package/dist/prosemirror/textInput.js +5 -1
  255. package/dist/prosemirror/trackedRevisionPath.js +2 -1
  256. package/dist/prosemirror/trackedRunInlineAtoms.d.ts +1 -0
  257. package/dist/prosemirror/trackedRunInlineAtoms.js +1 -0
  258. package/dist/prosemirror/validation.js +4 -0
  259. package/dist/types/canonicalCapabilities.d.ts +215 -0
  260. package/dist/types/canonicalCapabilities.js +212 -0
  261. package/dist/types/canonicalSave.d.ts +11 -0
  262. package/dist/types/canonicalSave.js +0 -0
  263. package/dist/types/content.d.ts +2 -2
  264. package/dist/types/docxSerialization.d.ts +14 -0
  265. package/dist/types/docxSerialization.js +7 -0
  266. package/dist/utils/createDocument.js +2 -2
  267. package/package.json +16 -4
@@ -0,0 +1,377 @@
1
+ import { handleEditorBeforeInput } from "../prosemirror/textInput.js";
2
+ import { createCanonicalComposition } from "./canonicalComposition.js";
3
+ import { deletionRange, isCanonicalJoinBoundary } from "./canonicalSession.js";
4
+ import { ReplaceStep } from "prosemirror-transform";
5
+ import { Selection, TextSelection } from "prosemirror-state";
6
+ //#region src/controller/canonicalInput.ts
7
+ const CANONICAL_COMPOSITION_INPUT_TYPES = [
8
+ "insertCompositionText",
9
+ "insertFromComposition",
10
+ "deleteCompositionText",
11
+ "deleteByComposition"
12
+ ];
13
+ /** Native changes require a preceding, classified input event at the same state. */
14
+ const createCanonicalInputBoundary = (options) => {
15
+ const composition = createCanonicalComposition({
16
+ begin: () => options.beginComposition?.() ?? true,
17
+ end: () => options.endComposition?.(),
18
+ replace: options.replace,
19
+ refuse: options.refuse
20
+ });
21
+ let proposal = { type: "idle" };
22
+ let authorizedInput = null;
23
+ let groupClosed = false;
24
+ const beginGesture = (lifecycle = "new") => {
25
+ if (lifecycle === "new") composition.forgetCompleted();
26
+ proposal = { type: "idle" };
27
+ authorizedInput = null;
28
+ groupClosed = false;
29
+ };
30
+ const closeGroup = () => {
31
+ if (groupClosed) return;
32
+ groupClosed = true;
33
+ options.breakUndoGroup?.();
34
+ };
35
+ const repaint = (view) => {
36
+ queueMicrotask(() => {
37
+ if (!view.isDestroyed) view.updateState(view.state);
38
+ });
39
+ };
40
+ const refuseEvent = (event, reason) => {
41
+ event.preventDefault();
42
+ closeGroup();
43
+ if (!composition.active && proposal.type !== "refused") options.refuse(reason);
44
+ if (!composition.active) proposal = { type: "refused" };
45
+ return true;
46
+ };
47
+ const refuseClipboardGesture = (event, reason) => {
48
+ event.preventDefault();
49
+ closeGroup();
50
+ options.refuse(reason);
51
+ return true;
52
+ };
53
+ const refuseNativeMutation = (view) => {
54
+ if (!composition.active && proposal.type !== "refused") {
55
+ options.refuse("Unclassified native text is unavailable in this session.");
56
+ proposal = { type: "refused" };
57
+ }
58
+ repaint(view);
59
+ };
60
+ const takeNativeProposal = (state, transaction) => {
61
+ const pending = proposal;
62
+ if (pending.type !== "replacement") return null;
63
+ proposal = { type: "idle" };
64
+ if (pending.state !== state || transaction.steps.length !== 1) return null;
65
+ const step = transaction.steps.at(0);
66
+ if (!(step instanceof ReplaceStep) || "structure" in step && step.structure === true || step.from !== pending.input.from || step.to !== pending.input.to) return null;
67
+ if (step.slice.openStart !== 0 || step.slice.openEnd !== 0) return null;
68
+ let text = "";
69
+ let plain = true;
70
+ step.slice.content.forEach((node) => {
71
+ if (!node.isText) plain = false;
72
+ text += node.text ?? "";
73
+ });
74
+ if (!plain || text !== pending.input.text) return null;
75
+ return state.tr.insertText(text, step.from, step.to).doc.eq(transaction.doc) ? pending.input : null;
76
+ };
77
+ return {
78
+ reset: () => {
79
+ proposal = { type: "idle" };
80
+ authorizedInput = null;
81
+ composition.reset();
82
+ },
83
+ get isComposing() {
84
+ return composition.active;
85
+ },
86
+ acceptComposition: composition.accept,
87
+ handleTextInput: (view, from, to, text) => {
88
+ if (composition.active || composition.pendingFinal) return false;
89
+ const pending = proposal;
90
+ if (authorizedInput?.view === view && authorizedInput.state === view.state) {
91
+ options.replace({
92
+ from,
93
+ to,
94
+ text,
95
+ semantic: "typing"
96
+ });
97
+ return true;
98
+ }
99
+ if (pending.type === "replacement" && pending.state === view.state && pending.input.from === from && pending.input.to === to && pending.input.text === text) {
100
+ proposal = { type: "idle" };
101
+ options.replace(pending.input);
102
+ return true;
103
+ }
104
+ refuseNativeMutation(view);
105
+ return true;
106
+ },
107
+ handleKeyDown: (view, event) => {
108
+ if (event.isComposing || event.keyCode === 229) return false;
109
+ beginGesture();
110
+ if (composition.active) {
111
+ if (event.key === "Escape") {
112
+ event.preventDefault();
113
+ composition.cancel(view);
114
+ return true;
115
+ }
116
+ if (event.metaKey || event.ctrlKey) {
117
+ event.preventDefault();
118
+ return true;
119
+ }
120
+ return false;
121
+ }
122
+ const modifier = event.metaKey || event.ctrlKey;
123
+ if (modifier || event.altKey || /^(?:Arrow|Home$|End$|Page|Escape$|Tab$)/u.test(event.key)) closeGroup();
124
+ if (modifier && event.key.toLowerCase() === "z") {
125
+ event.preventDefault();
126
+ if (event.shiftKey) options.redo();
127
+ else options.undo();
128
+ return true;
129
+ }
130
+ if (modifier && event.key.toLowerCase() === "y") {
131
+ event.preventDefault();
132
+ options.redo();
133
+ return true;
134
+ }
135
+ if (modifier && event.key.toLowerCase() === "a") {
136
+ event.preventDefault();
137
+ view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, Selection.atStart(view.state.doc).from, Selection.atEnd(view.state.doc).to)));
138
+ return true;
139
+ }
140
+ if (modifier && (event.key.toLowerCase() === "b" || event.key.toLowerCase() === "i" || event.key.toLowerCase() === "u") && options.command !== void 0) {
141
+ event.preventDefault();
142
+ switch (event.key.toLowerCase()) {
143
+ case "b":
144
+ options.command("toggleBold");
145
+ break;
146
+ case "i":
147
+ options.command("toggleItalic");
148
+ break;
149
+ case "u":
150
+ options.command("toggleUnderline");
151
+ break;
152
+ }
153
+ return true;
154
+ }
155
+ if (modifier && event.altKey && event.key.toLowerCase() === "v" && options.pastePlainText) {
156
+ event.preventDefault();
157
+ closeGroup();
158
+ options.pastePlainText(view);
159
+ return true;
160
+ }
161
+ if (event.key === "Enter") {
162
+ if (view.composing) return refuseEvent(event, "Paragraph structure edits are unavailable during composition.");
163
+ event.preventDefault();
164
+ closeGroup();
165
+ if (options.structure === void 0) return refuseEvent(event, "Paragraph structure edits are unavailable in this session.");
166
+ if (modifier) options.structure("pageBreak");
167
+ else options.structure(event.shiftKey ? "lineBreak" : "split");
168
+ return true;
169
+ }
170
+ if (event.key === "Tab" && !modifier && !event.altKey && options.structure !== void 0) {
171
+ event.preventDefault();
172
+ if (view.state.selection.$from.parent.attrs["numPr"]?.kind === "reference") options.structure(event.shiftKey ? "outdent" : "indent");
173
+ else if (!event.shiftKey) options.structure("tab");
174
+ return true;
175
+ }
176
+ if (event.key !== "Backspace" && event.key !== "Delete") return false;
177
+ event.preventDefault();
178
+ if (modifier || event.altKey || view.composing || composition.active) {
179
+ closeGroup();
180
+ if (!composition.active) options.refuse("Only plain character deletion is available in this session.");
181
+ return true;
182
+ }
183
+ if (view.state.selection.empty && options.structure !== void 0 && isCanonicalJoinBoundary(view.state, event.key === "Backspace" ? "backward" : "forward")) {
184
+ closeGroup();
185
+ options.structure(event.key === "Backspace" ? "joinBackward" : "joinForward");
186
+ return true;
187
+ }
188
+ const range = deletionRange(view.state, event.key === "Backspace" ? "backward" : "forward");
189
+ if (range.isErr()) {
190
+ closeGroup();
191
+ options.refuse(range.error.message);
192
+ } else options.replace({
193
+ ...range.value,
194
+ text: "",
195
+ semantic: event.key === "Backspace" ? "deleteBackward" : "deleteForward"
196
+ });
197
+ return true;
198
+ },
199
+ handleDOMEvents: {
200
+ keydown: (view, event) => {
201
+ if (event.isComposing || event.keyCode === 229) return true;
202
+ if (!composition.active || event.key !== "Escape") return false;
203
+ event.preventDefault();
204
+ composition.cancel(view);
205
+ return true;
206
+ },
207
+ compositionstart: (view) => {
208
+ beginGesture();
209
+ composition.start(view);
210
+ return false;
211
+ },
212
+ compositionend: (view) => {
213
+ composition.ended(view);
214
+ return false;
215
+ },
216
+ mousedown: (view) => {
217
+ composition.recover(view);
218
+ beginGesture();
219
+ closeGroup();
220
+ return false;
221
+ },
222
+ blur: (view) => {
223
+ composition.recover(view);
224
+ beginGesture();
225
+ closeGroup();
226
+ repaint(view);
227
+ return false;
228
+ },
229
+ beforeinput: (view, event) => {
230
+ beginGesture(event.inputType === "insertFromComposition" ? "compositionFinal" : "new");
231
+ if (event.isComposing || CANONICAL_COMPOSITION_INPUT_TYPES.some((inputType) => inputType === event.inputType)) {
232
+ if (composition.active) {
233
+ composition.authorizeNative(view);
234
+ return false;
235
+ }
236
+ if (event.inputType === "insertFromComposition" && composition.authorizeLateFinal(view, event.data)) return false;
237
+ return refuseEvent(event, "Composition has no captured canonical baseline.");
238
+ }
239
+ if (composition.active) {
240
+ const nativeFinal = view.composing && (event.inputType === "insertText" || event.inputType === "insertReplacementText");
241
+ const nativeStillComposing = view.composing;
242
+ const recovered = composition.recover(view);
243
+ composition.forgetCompleted();
244
+ proposal = { type: "idle" };
245
+ if (nativeFinal && (recovered.type === "refused" && nativeStillComposing || (recovered.type === "committed" || recovered.type === "refused") && recovered.text !== null && recovered.text === event.data)) {
246
+ event.preventDefault();
247
+ return true;
248
+ }
249
+ }
250
+ if (event.inputType === "insertText" || event.inputType === "insertReplacementText") {
251
+ if (event.cancelable) {
252
+ if (view.composing && event.inputType === "insertText" && event.data !== null) {
253
+ event.preventDefault();
254
+ proposal = { type: "idle" };
255
+ options.replace({
256
+ from: view.state.selection.from,
257
+ to: view.state.selection.to,
258
+ text: event.data,
259
+ semantic: "typing"
260
+ });
261
+ return true;
262
+ }
263
+ proposal = { type: "idle" };
264
+ authorizedInput = {
265
+ view,
266
+ state: view.state
267
+ };
268
+ try {
269
+ if (handleEditorBeforeInput(view, event)) return true;
270
+ return refuseEvent(event, "This native replacement cannot be addressed safely.");
271
+ } finally {
272
+ authorizedInput = null;
273
+ }
274
+ }
275
+ if (event.inputType !== "insertText" || event.data === null) return refuseEvent(event, "This native replacement cannot be addressed safely.");
276
+ proposal = {
277
+ type: "replacement",
278
+ state: view.state,
279
+ input: {
280
+ from: view.state.selection.from,
281
+ to: view.state.selection.to,
282
+ text: event.data,
283
+ semantic: "typing"
284
+ }
285
+ };
286
+ return false;
287
+ }
288
+ if ((event.inputType === "insertParagraph" || event.inputType === "insertLineBreak") && event.cancelable && options.structure !== void 0) {
289
+ event.preventDefault();
290
+ closeGroup();
291
+ options.structure(event.inputType === "insertParagraph" ? "split" : "lineBreak");
292
+ return true;
293
+ }
294
+ if (event.inputType === "deleteContentBackward" || event.inputType === "deleteContentForward") {
295
+ const selection = view.state.selection;
296
+ const backward = event.inputType === "deleteContentBackward";
297
+ if (event.cancelable && selection.empty && options.structure !== void 0 && isCanonicalJoinBoundary(view.state, backward ? "backward" : "forward")) {
298
+ event.preventDefault();
299
+ closeGroup();
300
+ options.structure(backward ? "joinBackward" : "joinForward");
301
+ return true;
302
+ }
303
+ const range = deletionRange(view.state, event.inputType === "deleteContentBackward" ? "backward" : "forward");
304
+ if (range.isErr()) return refuseEvent(event, range.error.message);
305
+ const input = {
306
+ ...range.value,
307
+ text: "",
308
+ semantic: event.inputType === "deleteContentBackward" ? "deleteBackward" : "deleteForward"
309
+ };
310
+ if (event.cancelable) {
311
+ event.preventDefault();
312
+ options.replace(input);
313
+ return true;
314
+ }
315
+ proposal = {
316
+ type: "replacement",
317
+ state: view.state,
318
+ input
319
+ };
320
+ return false;
321
+ }
322
+ if (event.inputType === "historyUndo" || event.inputType === "historyRedo") {
323
+ event.preventDefault();
324
+ if (event.inputType === "historyUndo") options.undo();
325
+ else options.redo();
326
+ return true;
327
+ }
328
+ return refuseEvent(event, `Input ${event.inputType} is unavailable in this session.`);
329
+ },
330
+ input: (view) => {
331
+ if (composition.active || composition.pendingFinal) {
332
+ composition.flushed(view);
333
+ return false;
334
+ }
335
+ const pending = proposal;
336
+ queueMicrotask(() => {
337
+ if (view.isDestroyed) return;
338
+ view.updateState(view.state);
339
+ if (proposal === pending && !composition.active) proposal = { type: "idle" };
340
+ });
341
+ return false;
342
+ },
343
+ paste: (_view, event) => {
344
+ beginGesture();
345
+ closeGroup();
346
+ if (composition.active) return refuseClipboardGesture(event, "Composition must finish before pasting.");
347
+ return false;
348
+ },
349
+ cut: (view, event) => {
350
+ beginGesture();
351
+ if (composition.active) return refuseClipboardGesture(event, "Composition must finish before cutting.");
352
+ if (options.cut !== void 0) {
353
+ closeGroup();
354
+ return options.cut(view, event);
355
+ }
356
+ return refuseEvent(event, "The canonical clipboard owner is unavailable.");
357
+ },
358
+ drop: (_view, event) => {
359
+ beginGesture();
360
+ closeGroup();
361
+ if (composition.active) return refuseClipboardGesture(event, "Composition must finish before dropping.");
362
+ return false;
363
+ }
364
+ },
365
+ /** Returns a classified intent only; the proposed PM document is never authoritative. */
366
+ takeNativeProposal,
367
+ refuseNativeMutation,
368
+ commitNativeProposal: (view, transaction) => {
369
+ const input = takeNativeProposal(view.state, transaction);
370
+ if (!input) return false;
371
+ options.replace(input);
372
+ return true;
373
+ }
374
+ };
375
+ };
376
+ //#endregion
377
+ export { CANONICAL_COMPOSITION_INPUT_TYPES, createCanonicalInputBoundary };
@@ -0,0 +1,7 @@
1
+ //#region src/controller/canonicalInputTimer.d.ts
2
+ /** Shared by timer producers and browser diagnostics, regardless of bundling. */
3
+ declare const CANONICAL_INPUT_TIMER_OWNER = "folio.canonical-input-timer";
4
+ /** Mark the scheduled wrapper, never the caller's potentially shared callback. */
5
+ declare const setCanonicalInputTimer: (callback: () => void, delay: number) => NodeJS.Timeout;
6
+ //#endregion
7
+ export { CANONICAL_INPUT_TIMER_OWNER, setCanonicalInputTimer };
@@ -0,0 +1,11 @@
1
+ //#region src/controller/canonicalInputTimer.ts
2
+ /** Shared by timer producers and browser diagnostics, regardless of bundling. */
3
+ const CANONICAL_INPUT_TIMER_OWNER = "folio.canonical-input-timer";
4
+ /** Mark the scheduled wrapper, never the caller's potentially shared callback. */
5
+ const setCanonicalInputTimer = (callback, delay) => {
6
+ const ownedCallback = () => callback();
7
+ Object.defineProperty(ownedCallback, Symbol.for(CANONICAL_INPUT_TIMER_OWNER), { value: true });
8
+ return setTimeout(ownedCallback, delay);
9
+ };
10
+ //#endregion
11
+ export { CANONICAL_INPUT_TIMER_OWNER, setCanonicalInputTimer };
@@ -0,0 +1,22 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { CreateHeaderFooterOp, DOCUMENT_OP_TYPES, DocumentOp, FormattingPatch, FormattingPatch as FormattingPatch$1, OpStory, RemoveHeaderFooterOp, SetSectionPropsOp, TextPosition } from "@stll/docx-core/ops";
3
+ //#region src/controller/canonicalOperations.d.ts
4
+ declare const canonicalFinalSectionIndex: (document: document_d_exports.Document) => number;
5
+ declare const withCanonicalParagraphIds: (content: document_d_exports.BlockContent[], document: document_d_exports.Document) => document_d_exports.BlockContent[];
6
+ type CreateCanonicalHeaderFooterOptions = {
7
+ document: document_d_exports.Document;
8
+ position: "header" | "footer";
9
+ referenceType: document_d_exports.HeaderFooterType;
10
+ sectionIndex?: number;
11
+ };
12
+ declare const createCanonicalHeaderFooterOperation: ({ document, position, referenceType, sectionIndex }: CreateCanonicalHeaderFooterOptions) => CreateHeaderFooterOp;
13
+ type RemoveCanonicalHeaderFooterOptions = {
14
+ document: document_d_exports.Document;
15
+ position: "header" | "footer";
16
+ rId: string;
17
+ };
18
+ /** Remove each explicit binding, leaving inherited sections to inherit the remaining parts. */
19
+ declare const removeCanonicalHeaderFooterOperations: ({ document, position, rId }: RemoveCanonicalHeaderFooterOptions) => RemoveHeaderFooterOp[];
20
+ declare const createCanonicalSectionPropertiesOperation: (document: document_d_exports.Document, patch: FormattingPatch$1<document_d_exports.SectionProperties>) => SetSectionPropsOp;
21
+ //#endregion
22
+ export { DOCUMENT_OP_TYPES, type DocumentOp, type FormattingPatch, type OpStory, type TextPosition, canonicalFinalSectionIndex, createCanonicalHeaderFooterOperation, createCanonicalSectionPropertiesOperation, removeCanonicalHeaderFooterOperations, withCanonicalParagraphIds };
@@ -0,0 +1,85 @@
1
+ import { visitDocxParagraphs } from "../docx/paragraphTraversal.js";
2
+ import { generateHexId, isValidHexId } from "../utils/hexId.js";
3
+ import { DOCUMENT_OP_TYPES, DOCUMENT_OP_TYPES as DOCUMENT_OP_TYPES$1 } from "@stll/docx-core/ops";
4
+ //#region src/controller/canonicalOperations.ts
5
+ /** Adapter command boundaries allocate identities; journaled operations remain deterministic. */
6
+ const canonicalFinalSectionIndex = (document) => document.package.document.content.filter((block) => block.type === "paragraph" && block.sectionProperties !== void 0).length;
7
+ const withCanonicalParagraphIds = (content, document) => {
8
+ const taken = /* @__PURE__ */ new Set();
9
+ const { document: documentBody, headers, footers, footnotes, endnotes } = document.package;
10
+ visitDocxParagraphs({
11
+ documentBody,
12
+ headers,
13
+ footers,
14
+ footnotes,
15
+ endnotes
16
+ }, (paragraph) => {
17
+ if (paragraph.paraId) taken.add(paragraph.paraId.toUpperCase());
18
+ });
19
+ const owned = structuredClone(content);
20
+ visitDocxParagraphs({ documentBody: { content: owned } }, (paragraph) => {
21
+ if (paragraph.paraId && isValidHexId(paragraph.paraId) && Number.parseInt(paragraph.paraId, 16) > 0 && Number.parseInt(paragraph.paraId, 16) < 2147483647 && !taken.has(paragraph.paraId.toUpperCase())) {
22
+ taken.add(paragraph.paraId.toUpperCase());
23
+ return;
24
+ }
25
+ let paraId = generateHexId();
26
+ while (taken.has(paraId)) paraId = generateHexId();
27
+ taken.add(paraId);
28
+ paragraph.paraId = paraId;
29
+ });
30
+ return owned;
31
+ };
32
+ const createCanonicalHeaderFooterOperation = ({ document, position, referenceType, sectionIndex = canonicalFinalSectionIndex(document) }) => {
33
+ const occupied = /* @__PURE__ */ new Set([
34
+ ...document.package.headers?.keys() ?? [],
35
+ ...document.package.footers?.keys() ?? [],
36
+ ...document.package.relationships?.keys() ?? []
37
+ ]);
38
+ const base = `rId_new_${position}_${referenceType}`;
39
+ let rId = base;
40
+ let suffix = 2;
41
+ while (occupied.has(rId)) rId = `${base}_${suffix++}`;
42
+ return {
43
+ type: DOCUMENT_OP_TYPES$1.CREATE_HEADER_FOOTER,
44
+ sectionIndex,
45
+ story: {
46
+ kind: position,
47
+ rId
48
+ },
49
+ referenceType,
50
+ content: withCanonicalParagraphIds([{
51
+ type: "paragraph",
52
+ content: []
53
+ }], document)
54
+ };
55
+ };
56
+ /** Remove each explicit binding, leaving inherited sections to inherit the remaining parts. */
57
+ const removeCanonicalHeaderFooterOperations = ({ document, position, rId }) => {
58
+ const properties = [];
59
+ for (const block of document.package.document.content) if (block.type === "paragraph" && block.sectionProperties) properties.push(block.sectionProperties);
60
+ properties.push(document.package.document.finalSectionProperties ?? {});
61
+ const operations = [];
62
+ for (const [sectionIndex, section] of properties.entries()) {
63
+ const references = position === "header" ? section.headerReferences : section.footerReferences;
64
+ for (const reference of references ?? []) {
65
+ if (reference.rId !== rId) continue;
66
+ operations.push({
67
+ type: DOCUMENT_OP_TYPES$1.REMOVE_HEADER_FOOTER,
68
+ sectionIndex,
69
+ story: {
70
+ kind: position,
71
+ rId
72
+ },
73
+ referenceType: reference.type
74
+ });
75
+ }
76
+ }
77
+ return operations;
78
+ };
79
+ const createCanonicalSectionPropertiesOperation = (document, patch) => ({
80
+ type: DOCUMENT_OP_TYPES$1.SET_SECTION_PROPS,
81
+ sectionIndex: canonicalFinalSectionIndex(document),
82
+ patch
83
+ });
84
+ //#endregion
85
+ export { DOCUMENT_OP_TYPES, canonicalFinalSectionIndex, createCanonicalHeaderFooterOperation, createCanonicalSectionPropertiesOperation, removeCanonicalHeaderFooterOperations, withCanonicalParagraphIds };
@@ -0,0 +1,48 @@
1
+ import { ApplyFolioDocumentOperationsOptions, FolioDocumentOperationResult, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult } from "../document-operations.js";
2
+ import { CanonicalCommit, CanonicalSession } from "./canonicalSession.js";
3
+ import { EditorState } from "prosemirror-state";
4
+ import { OpStory } from "@stll/docx-core/ops";
5
+ //#region src/controller/canonicalPublicOperations.d.ts
6
+ /** A new public kind cannot bypass a canonical compiler/refusal decision. */
7
+ declare const CANONICAL_PUBLIC_OPERATION_DISPOSITIONS: {
8
+ readonly replaceInBlock: "compile";
9
+ readonly replaceRange: "compile";
10
+ readonly replaceBlock: "compile";
11
+ readonly splitBlock: "compile";
12
+ readonly formatRange: "compile";
13
+ readonly mergeBlockWithNext: "compile";
14
+ readonly setBlockParagraphProperties: "publicOps.unsupportedInline";
15
+ readonly insertAfterBlock: "publicOps.unsupportedInline";
16
+ readonly insertBeforeBlock: "publicOps.unsupportedInline";
17
+ readonly deleteBlock: "publicOps.unsupportedInline";
18
+ readonly commentOnBlock: "publicOps.comments";
19
+ readonly commentOnRange: "publicOps.comments";
20
+ readonly insertTable: "publicOps.tableProjection";
21
+ readonly insertSignatureTable: "publicOps.tableProjection";
22
+ readonly deleteTable: "publicOps.tableProjection";
23
+ readonly insertTableRow: "publicOps.tableProjection";
24
+ readonly deleteTableRow: "publicOps.tableProjection";
25
+ readonly insertTableColumn: "publicOps.tableProjection";
26
+ readonly deleteTableColumn: "publicOps.tableProjection";
27
+ readonly mergeTableCells: "publicOps.tableProjection";
28
+ readonly splitTableCell: "publicOps.tableProjection";
29
+ };
30
+ type CanonicalPublicOperationOptions = Omit<ApplyFolioDocumentOperationsOptions, "view" | "createUndoHandle" | "createCommentId">;
31
+ type CanonicalPublicOperationsOptions = {
32
+ session: CanonicalSession;
33
+ getState: (story: OpStory) => EditorState | null;
34
+ publish: (commit: CanonicalCommit) => boolean;
35
+ };
36
+ /** Handles address isolated journal groups; no second document or PM history is retained. */
37
+ declare class CanonicalPublicOperations {
38
+ private readonly options;
39
+ private readonly handles;
40
+ private nextHandle;
41
+ private readonly handleNamespace;
42
+ constructor(options: CanonicalPublicOperationsOptions);
43
+ apply(options: CanonicalPublicOperationOptions): FolioDocumentOperationResult;
44
+ undo(handle: FolioDocumentOperationUndoHandle): FolioDocumentOperationUndoResult;
45
+ private resolve;
46
+ }
47
+ //#endregion
48
+ export { CANONICAL_PUBLIC_OPERATION_DISPOSITIONS, CanonicalPublicOperationOptions, CanonicalPublicOperations };