@stll/folio-core 0.68.0 → 0.69.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 (177) hide show
  1. package/dist/ai-edits/headless.js +2 -2
  2. package/dist/ai-edits/newListNumbering.d.ts +14 -1
  3. package/dist/ai-edits/newListNumbering.js +24 -1
  4. package/dist/ai-edits/pending-suggestions.js +2 -2
  5. package/dist/controller/canonicalClipboard.js +2 -2
  6. package/dist/controller/canonicalComposition.js +34 -5
  7. package/dist/controller/canonicalInput.js +4 -6
  8. package/dist/controller/canonicalLockGuard.d.ts +17 -2
  9. package/dist/controller/canonicalLockGuard.js +46 -1
  10. package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
  11. package/dist/controller/canonicalProjectionBlocks.js +75 -0
  12. package/dist/controller/canonicalPublicOperations.js +476 -100
  13. package/dist/controller/canonicalSeedContent.d.ts +12 -0
  14. package/dist/controller/canonicalSeedContent.js +131 -0
  15. package/dist/controller/canonicalSession.d.ts +53 -21
  16. package/dist/controller/canonicalSession.js +489 -210
  17. package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
  18. package/dist/controller/canonicalSourceNormalization.js +148 -0
  19. package/dist/controller/canonicalStoryEditor.d.ts +1 -1
  20. package/dist/controller/canonicalStoryEditor.js +16 -12
  21. package/dist/controller/folioEditor.js +3 -0
  22. package/dist/controller/headerFooterEditorManager.d.ts +5 -0
  23. package/dist/controller/headerFooterEditorManager.js +7 -2
  24. package/dist/controller/hiddenEditorApi.d.ts +11 -2
  25. package/dist/controller/hiddenEditorApi.js +3 -0
  26. package/dist/controller/hiddenEditorManager.d.ts +7 -0
  27. package/dist/controller/hiddenEditorManager.js +66 -11
  28. package/dist/controller/layoutPipeline.js +2 -1
  29. package/dist/controller/layoutSession.d.ts +3 -0
  30. package/dist/controller/layoutSession.js +3 -1
  31. package/dist/controller/noteEditorManager.d.ts +5 -0
  32. package/dist/controller/noteEditorManager.js +7 -2
  33. package/dist/display-list/dom/renderDisplayListToDom.js +9 -7
  34. package/dist/document-operations.d.ts +1 -1
  35. package/dist/docx/canonicalSave.js +7 -2
  36. package/dist/docx/commentAnchorIndex.d.ts +19 -0
  37. package/dist/docx/commentAnchorIndex.js +55 -1
  38. package/dist/docx/containerChildren.js +1 -1
  39. package/dist/docx/contentTypeRegistry.js +1 -1
  40. package/dist/docx/hostCommentThreads.d.ts +11 -1
  41. package/dist/docx/hostCommentThreads.js +25 -2
  42. package/dist/docx/listModelNormalization.js +4 -5
  43. package/dist/docx/listNumberingInstances.d.ts +1 -1
  44. package/dist/docx/listNumberingInstances.js +2 -2
  45. package/dist/docx/numberingIds.d.ts +6 -0
  46. package/dist/docx/numberingIds.js +6 -1
  47. package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
  48. package/dist/docx/numberingReferenceNormalization.js +12 -2
  49. package/dist/docx/paragraphPropertySource.d.ts +22 -0
  50. package/dist/docx/paragraphPropertySource.js +85 -16
  51. package/dist/docx/parser.js +2 -0
  52. package/dist/docx/removeHeaderFooterParts.js +1 -1
  53. package/dist/docx/reviewResolutionProvenance.js +72 -19
  54. package/dist/docx/serializer/documentSerializer.js +2 -1
  55. package/dist/docx/serializer/partNamespaces.d.ts +1 -1
  56. package/dist/docx/serializer/partNamespaces.js +1 -1
  57. package/dist/docx/server/build.d.ts +1 -1
  58. package/dist/docx/storyBlockReplay.js +15 -2
  59. package/dist/docx/structuralXmlPatch.js +25 -4
  60. package/dist/docx/xmlParser.d.ts +1 -1
  61. package/dist/docx/xmlParser.js +2 -3
  62. package/dist/i18n/messages/ar.gen.js +1 -0
  63. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  64. package/dist/i18n/messages/catalogs.gen.js +17 -0
  65. package/dist/i18n/messages/cs.gen.js +1 -0
  66. package/dist/i18n/messages/de.gen.js +1 -0
  67. package/dist/i18n/messages/en.gen.js +1 -0
  68. package/dist/i18n/messages/es.gen.js +1 -0
  69. package/dist/i18n/messages/et.gen.js +1 -0
  70. package/dist/i18n/messages/fr.gen.js +1 -0
  71. package/dist/i18n/messages/he.gen.js +1 -0
  72. package/dist/i18n/messages/hi.gen.js +1 -0
  73. package/dist/i18n/messages/hu.gen.js +1 -0
  74. package/dist/i18n/messages/lt.gen.js +1 -0
  75. package/dist/i18n/messages/lv.gen.js +1 -0
  76. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  77. package/dist/i18n/messages/pl.gen.js +1 -0
  78. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  79. package/dist/i18n/messages/sk.gen.js +1 -0
  80. package/dist/i18n/messages/tr.gen.js +1 -0
  81. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  82. package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
  83. package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
  84. package/dist/internal/subtreeHolds.d.ts +12 -0
  85. package/dist/internal/subtreeHolds.js +25 -0
  86. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  87. package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
  88. package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
  89. package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
  90. package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
  91. package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
  92. package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
  93. package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
  94. package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
  95. package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
  96. package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
  97. package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
  98. package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
  99. package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
  100. package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
  101. package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
  102. package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
  103. package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
  104. package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
  105. package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
  106. package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
  107. package/dist/layout-bridge/dom/textStreamDom.js +3 -2
  108. package/dist/layout-bridge/headerFooterLayout.js +12 -11
  109. package/dist/layout-bridge/tableInsertHover.js +2 -1
  110. package/dist/layout-engine/measure/cache.d.ts +2 -0
  111. package/dist/layout-engine/measure/cache.js +6 -1
  112. package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
  113. package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
  114. package/dist/layout-engine/types.d.ts +6 -0
  115. package/dist/layout-painter/imageLayout.js +2 -1
  116. package/dist/layout-painter/pageShellStyles.d.ts +10 -0
  117. package/dist/layout-painter/pageShellStyles.js +32 -0
  118. package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
  119. package/dist/layout-painter/reconcileRenderedContent.js +117 -0
  120. package/dist/layout-painter/renderFragment.js +4 -6
  121. package/dist/layout-painter/renderImage.js +2 -2
  122. package/dist/layout-painter/renderPage.js +8 -29
  123. package/dist/layout-painter/renderParagraph.js +3 -3
  124. package/dist/layout-painter/renderTable.js +9 -12
  125. package/dist/layout-painter/renderTextBox.js +2 -2
  126. package/dist/layout-painter/sdtBoundary.js +3 -2
  127. package/dist/paged-layout/blockGeometry.js +3 -2
  128. package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
  129. package/dist/paged-layout/editorScrollRoot.js +10 -1
  130. package/dist/paged-layout/rangeProjection.js +5 -4
  131. package/dist/paged-layout/scrollToPmPosition.js +3 -3
  132. package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
  133. package/dist/paged-layout/selectionViewportRect.js +8 -2
  134. package/dist/prosemirror/attrs/index.js +1 -0
  135. package/dist/prosemirror/commands/comments.d.ts +5 -2
  136. package/dist/prosemirror/commands/comments.js +88 -8
  137. package/dist/prosemirror/commentRecords.d.ts +137 -0
  138. package/dist/prosemirror/commentRecords.js +400 -0
  139. package/dist/prosemirror/conversion/fromProseDoc.js +9 -3
  140. package/dist/prosemirror/conversion/index.d.ts +1 -1
  141. package/dist/prosemirror/conversion/toProseDoc.d.ts +13 -4
  142. package/dist/prosemirror/conversion/toProseDoc.js +126 -38
  143. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +22 -0
  144. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
  145. package/dist/prosemirror/extensions/marks/CommentExtension.js +3 -1
  146. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
  147. package/dist/prosemirror/index.d.ts +1 -1
  148. package/dist/prosemirror/nativeSelection.d.ts +33 -0
  149. package/dist/prosemirror/nativeSelection.js +74 -0
  150. package/dist/prosemirror/numberedRefFields.d.ts +2 -0
  151. package/dist/prosemirror/numberedRefFields.js +16 -5
  152. package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
  153. package/dist/prosemirror/paragraphMarkJoin.js +155 -16
  154. package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
  155. package/dist/prosemirror/plugins/documentNumbering.js +33 -14
  156. package/dist/prosemirror/plugins/suggestionMode.js +13 -1
  157. package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
  158. package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
  159. package/dist/prosemirror/schema/marks.d.ts +7 -1
  160. package/dist/prosemirror/storyListNumbering.js +7 -2
  161. package/dist/prosemirror/tableResize.d.ts +10 -9
  162. package/dist/prosemirror/tableResize.js +60 -49
  163. package/dist/prosemirror/textInput.d.ts +30 -1
  164. package/dist/prosemirror/textInput.js +144 -17
  165. package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
  166. package/dist/prosemirror/validation.d.ts +19 -0
  167. package/dist/prosemirror/validation.js +78 -5
  168. package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
  169. package/dist/render-dom/RenderedDomContext.js +7 -6
  170. package/dist/types/canonicalCapabilities.d.ts +12 -11
  171. package/dist/types/canonicalCapabilities.js +12 -13
  172. package/dist/utils/findMatchView.js +4 -3
  173. package/dist/utils/formatToStyle.d.ts +1 -1
  174. package/dist/utils/mergeDocumentContent.js +2 -2
  175. package/dist/utils/paintedPositions.d.ts +60 -0
  176. package/dist/utils/paintedPositions.js +101 -0
  177. package/package.json +2 -3
@@ -0,0 +1,21 @@
1
+ import { OpStory } from "@stll/docx-core/ops";
2
+ import { BlockContent, Document } from "@stll/docx-core";
3
+ /** A story the session reads in its own form, with the blocks it was read with. */
4
+ type NormalizedStory = {
5
+ story: OpStory;
6
+ source: readonly BlockContent[];
7
+ };
8
+ /** A normalized story, with what it held when the session opened. */
9
+ export type CanonicalSourceRestore = NormalizedStory & {
10
+ opened: string;
11
+ };
12
+ /** The document in the session's own spelling, with every story it changed. */
13
+ export declare const normalizeCanonicalSource: (document: Document) => {
14
+ document: Document;
15
+ normalized: NormalizedStory[];
16
+ };
17
+ /** What each normalized story holds in the document the session opens. */
18
+ export declare const canonicalSourceRestores: (document: Document, normalized: readonly NormalizedStory[]) => CanonicalSourceRestore[];
19
+ /** The document with every story that still holds what it opened with given back as read. */
20
+ export declare const withUneditedSourceRestored: (document: Document, restores: readonly CanonicalSourceRestore[]) => Document;
21
+ export {};
@@ -0,0 +1,148 @@
1
+ import { canonicalJson } from "../utils/canonicalJson.js";
2
+ import { panic } from "better-result";
3
+ import { OP_STORIES, documentStories, findStoryBody, packageParagraphIds, replaceStoryBody, withBodyContent } from "@stll/docx-core/ops";
4
+ // src/controller/canonicalSourceNormalization.ts
5
+ /**
6
+ * Source spellings the canonical session reads in its own form, and gives back
7
+ * as read while their story is unedited.
8
+ *
9
+ * Two spellings carry a meaning the session models another way:
10
+ *
11
+ * - A literal tab character in `w:t`, which a reader shows as a tab: the
12
+ * session's model spells a tab as `w:tab`, so the text is split around it.
13
+ * - A story with no blocks (a header or a footer holding nothing): a story
14
+ * ends with a paragraph, the one a caret goes in, so the session gives it an
15
+ * empty one.
16
+ *
17
+ * Both are the session's model only. Each normalized story keeps the blocks it
18
+ * was read with, and a save of that story while it still holds what the
19
+ * session opened with writes those blocks, so the part keeps its source bytes.
20
+ * A story the user edits saves as edited, in the session's spelling.
21
+ */
22
+ const TAB = " ";
23
+ /** The run content with each literal tab in its text spelled as a tab element. */
24
+ const tabSpelledContent = (content) => {
25
+ const out = [];
26
+ for (const item of content) {
27
+ if (item.type !== "text" || !item.text.includes(TAB)) {
28
+ out.push(item);
29
+ continue;
30
+ }
31
+ item.text.split(TAB).forEach((part, index) => {
32
+ if (index > 0) out.push({ type: "tab" });
33
+ if (part !== "") out.push({
34
+ ...item,
35
+ text: part
36
+ });
37
+ });
38
+ }
39
+ return out;
40
+ };
41
+ const withTabElements = (run) => run.content.some((item) => item.type === "text" && item.text.includes(TAB)) ? {
42
+ ...run,
43
+ content: tabSpelledContent(run.content)
44
+ } : run;
45
+ const isPlainRecord = (value) => {
46
+ const prototype = Object.getPrototypeOf(value);
47
+ return prototype === Object.prototype || prototype === null;
48
+ };
49
+ /**
50
+ * `value` with every run's literal tabs spelled as tab elements, rebuilding
51
+ * only what changes. A run sits at any depth of inline content (inside a
52
+ * revision, a link, a field result, a content control), so the walk goes
53
+ * through every plain record and array and leaves everything else as it is.
54
+ */
55
+ const withRunTabElements = (value) => {
56
+ if (typeof value !== "object" || value === null) return value;
57
+ if (Array.isArray(value)) {
58
+ let changed = false;
59
+ const mapped = value.map((item) => {
60
+ const next = withRunTabElements(item);
61
+ if (next !== item) changed = true;
62
+ return next;
63
+ });
64
+ return changed ? mapped : value;
65
+ }
66
+ if (!isPlainRecord(value)) return value;
67
+ const changes = /* @__PURE__ */ new Map();
68
+ for (const [key, child] of Object.entries(value)) {
69
+ const mapped = withRunTabElements(child);
70
+ if (mapped !== child) changes.set(key, mapped);
71
+ }
72
+ let next = changes.size === 0 ? value : {
73
+ ...value,
74
+ ...Object.fromEntries(changes)
75
+ };
76
+ if (next["type"] === "run" && Array.isArray(next["content"])) next = withTabElements(next);
77
+ return next === value ? value : next;
78
+ };
79
+ /** The first id not in `used`, spelled as eight uppercase hex digits. */
80
+ const freshParaId = (used) => {
81
+ for (let candidate = 1; candidate < 2147483648; candidate += 1) {
82
+ const id = candidate.toString(16).toUpperCase().padStart(8, "0");
83
+ if (!used.has(id)) {
84
+ used.add(id);
85
+ return id;
86
+ }
87
+ }
88
+ return panic("Every paragraph id is in use.");
89
+ };
90
+ const isSeparatorNote = (document, story) => {
91
+ if (story === OP_STORIES.MAIN) return false;
92
+ if (story.kind !== "footnote" && story.kind !== "endnote") return false;
93
+ const note = (story.kind === "footnote" ? document.package.footnotes : document.package.endnotes)?.find(({ id }) => id === story.id);
94
+ return note?.noteType !== void 0 && note.noteType !== "normal";
95
+ };
96
+ /** The document in the session's own spelling, with every story it changed. */
97
+ const normalizeCanonicalSource = (document) => {
98
+ let current = document;
99
+ const normalized = [];
100
+ const used = new Set(packageParagraphIds(document.package).map((id) => id.toUpperCase()));
101
+ for (const story of documentStories(document)) {
102
+ const body = findStoryBody(current, story);
103
+ if (body === void 0) continue;
104
+ let content = withRunTabElements(body.content);
105
+ if (content.length === 0 && !isSeparatorNote(document, story)) content = [{
106
+ type: "paragraph",
107
+ paraId: freshParaId(used),
108
+ content: []
109
+ }];
110
+ if (content === body.content) continue;
111
+ normalized.push({
112
+ story,
113
+ source: body.content
114
+ });
115
+ current = replaceStoryBody({
116
+ document: current,
117
+ story,
118
+ body: withBodyContent(body, [...content])
119
+ });
120
+ }
121
+ return {
122
+ document: current,
123
+ normalized
124
+ };
125
+ };
126
+ /** What each normalized story holds in the document the session opens. */
127
+ const canonicalSourceRestores = (document, normalized) => normalized.flatMap((entry) => {
128
+ const body = findStoryBody(document, entry.story);
129
+ return body === void 0 ? [] : [{
130
+ ...entry,
131
+ opened: canonicalJson(body.content)
132
+ }];
133
+ });
134
+ /** The document with every story that still holds what it opened with given back as read. */
135
+ const withUneditedSourceRestored = (document, restores) => {
136
+ let current = document;
137
+ for (const { story, source, opened } of restores) {
138
+ const body = findStoryBody(current, story);
139
+ if (body === void 0 || canonicalJson(body.content) !== opened) continue;
140
+ current = replaceStoryBody({
141
+ document: current,
142
+ story,
143
+ body: withBodyContent(body, [...source])
144
+ });
145
+ }
146
+ return current;
147
+ };
148
+ export { canonicalSourceRestores, normalizeCanonicalSource, withUneditedSourceRestored };
@@ -1,8 +1,8 @@
1
1
  import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
2
2
  import { HiddenEditorApi } from "./hiddenEditorApi.js";
3
3
  import { Transaction } from "prosemirror-state";
4
- import { EditorView } from "prosemirror-view";
5
4
  import { OpStory } from "@stll/docx-core/ops";
5
+ import { EditorView } from "prosemirror-view";
6
6
  type CanonicalStoryEditorOptions = {
7
7
  story: OpStory;
8
8
  getView: () => EditorView;
@@ -1,7 +1,7 @@
1
+ import { adoptNativeSelection, isCompositionKeyDown } from "../prosemirror/nativeSelection.js";
1
2
  import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
2
3
  import { createCanonicalInputBoundary } from "./canonicalInput.js";
3
4
  import { CanonicalSessionError } from "./canonicalSession.js";
4
- import { AllSelection, TextSelection } from "prosemirror-state";
5
5
  // src/controller/canonicalStoryEditor.ts
6
6
  /** Secondary views compile classified native input into the shared Document journal. */
7
7
  const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal, onSelectionChange }) => {
@@ -26,15 +26,7 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal
26
26
  return accepted;
27
27
  };
28
28
  const syncNativeSelection = (view) => {
29
- if (boundary.isComposing || view.composing) return;
30
- const selection = view.dom.ownerDocument.getSelection();
31
- if (!selection?.anchorNode || !selection.focusNode || !view.dom.contains(selection.anchorNode) || !view.dom.contains(selection.focusNode)) return;
32
- const anchor = view.posAtDOM(selection.anchorNode, selection.anchorOffset);
33
- const head = view.posAtDOM(selection.focusNode, selection.focusOffset);
34
- if (view.state.selection instanceof AllSelection && Math.min(anchor, head) === 0 && Math.max(anchor, head) === view.state.doc.content.size) return;
35
- if (anchor === view.state.selection.anchor && head === view.state.selection.head) return;
36
- if (!view.state.doc.resolve(anchor).parent.inlineContent || !view.state.doc.resolve(head).parent.inlineContent) return;
37
- view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, anchor, head)));
29
+ if (!boundary.isComposing) adoptNativeSelection(view);
38
30
  };
39
31
  const boundary = createCanonicalInputBoundary({
40
32
  breakUndoGroup: () => {
@@ -60,6 +52,10 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal
60
52
  dispatch: (transaction) => {
61
53
  if (!enabled()) return false;
62
54
  const view = getView();
55
+ getApi()?.noteCanonicalStoryView({
56
+ story,
57
+ view
58
+ });
63
59
  if (transaction.docChanged) {
64
60
  if (boundary.acceptComposition(view, transaction)) return true;
65
61
  if (!boundary.commitNativeProposal(view, transaction)) boundary.refuseNativeMutation(view);
@@ -82,7 +78,11 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal
82
78
  handleTextInput: (view, from, to, text) => enabled() && boundary.handleTextInput(view, from, to, text),
83
79
  handleKeyPress: (view, event) => enabled() && boundary.handleKeyPress(view, event),
84
80
  handleDOMEvents: {
85
- keydown: (view, event) => enabled() && boundary.handleDOMEvents.keydown(view, event),
81
+ keydown: (view, event) => {
82
+ if (!enabled()) return false;
83
+ if (!isCompositionKeyDown(event)) syncNativeSelection(view);
84
+ return boundary.handleDOMEvents.keydown(view, event);
85
+ },
86
86
  keyup: (view, event) => {
87
87
  if (enabled() && /^(?:Arrow|Home$|End$|Page)/u.test(event.key)) syncNativeSelection(view);
88
88
  return false;
@@ -91,7 +91,11 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal
91
91
  if (enabled()) syncNativeSelection(view);
92
92
  return false;
93
93
  },
94
- beforeinput: (view, event) => enabled() && boundary.handleDOMEvents.beforeinput(view, event),
94
+ beforeinput: (view, event) => {
95
+ if (!enabled()) return false;
96
+ if (!event.isComposing) syncNativeSelection(view);
97
+ return boundary.handleDOMEvents.beforeinput(view, event);
98
+ },
95
99
  mousedown: (view) => enabled() && boundary.handleDOMEvents.mousedown(view),
96
100
  compositionstart: (view) => enabled() && boundary.handleDOMEvents.compositionstart(view),
97
101
  compositionend: (view, event) => enabled() && boundary.handleDOMEvents.compositionend(view, event),
@@ -29,6 +29,9 @@ const createFolioEditor = (deps) => {
29
29
  getCanonicalStorySelection: (story) => deps.getEditorApi()?.getCanonicalStorySelection(story) ?? null,
30
30
  getCanonicalStoryProjection: (story) => deps.getEditorApi()?.getCanonicalStoryProjection(story) ?? null,
31
31
  replaceCanonicalStoryText: (options) => deps.getEditorApi()?.replaceCanonicalStoryText(options) ?? false,
32
+ noteCanonicalStoryView: (options) => {
33
+ deps.getEditorApi()?.noteCanonicalStoryView(options);
34
+ },
32
35
  isCanonicalSaveCurrent: (version) => deps.getEditorApi()?.isCanonicalSaveCurrent(version) ?? false,
33
36
  captureCanonicalSave: () => deps.getEditorApi()?.captureCanonicalSave() ?? null,
34
37
  applyCanonicalDocumentOperations: (options) => deps.getEditorApi()?.applyCanonicalDocumentOperations(options) ?? null,
@@ -19,6 +19,11 @@ export type HeaderFooterEditorManagerDeps = {
19
19
  getDocument: () => document_d_exports.Document | null;
20
20
  getReadOnly?: (() => boolean) | undefined;
21
21
  getCanonicalApi?: (() => HiddenEditorApi | null) | undefined;
22
+ /**
23
+ * The canonical session's own document, read without a copy (see
24
+ * `HiddenEditorManager.readCanonicalDocument`); null outside a session.
25
+ */
26
+ readCanonicalDocument: () => document_d_exports.Document | null;
22
27
  getExperimentalSession?: (() => "canonical" | undefined) | undefined;
23
28
  onSessionRefusal?: ((reason: string, ground: CanonicalRefusalGround, error?: Error) => void) | undefined;
24
29
  getHost: () => HTMLElement | null;
@@ -6,6 +6,7 @@ import { ExtensionManager } from "../prosemirror/extensions/ExtensionManager.js"
6
6
  import { createStarterKit } from "../prosemirror/extensions/StarterKit.js";
7
7
  import { ensureBaseDirectionInState } from "../prosemirror/extensions/features/AutoBidiDetectionExtension.js";
8
8
  import { ensureParaIdsInState } from "../prosemirror/extensions/features/ParaIdAllocatorExtension.js";
9
+ import { createNativeSelectionRefreshPlugin } from "../prosemirror/nativeSelection.js";
9
10
  import { noteReferenceTransactionIssue } from "../prosemirror/noteReferenceOccurrences.js";
10
11
  import { createDocumentNumberingPlugin } from "../prosemirror/plugins/documentNumbering.js";
11
12
  import { createDocumentStyleContextPlugin, createDocumentStylesPlugin } from "../prosemirror/plugins/documentStyles.js";
@@ -80,7 +81,7 @@ const createHeaderFooterEditorManager = (deps) => {
80
81
  for (const part of mounted.values()) destroyMounted(part);
81
82
  mounted.clear();
82
83
  };
83
- const getOwnedDocument = () => usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting) ? deps.getCanonicalApi?.()?.getCanonicalDocument() ?? null : deps.getDocument();
84
+ const getOwnedDocument = () => usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting) ? deps.readCanonicalDocument() : deps.getDocument();
84
85
  const sync = () => {
85
86
  const host = deps.getHost();
86
87
  if (!host) return;
@@ -184,7 +185,11 @@ const createHeaderFooterEditorManager = (deps) => {
184
185
  editable: () => !(deps.getReadOnly?.() ?? false),
185
186
  state: canonicalProjection ? EditorState.create({
186
187
  doc: canonicalProjection,
187
- plugins: [createDocumentNumberingPlugin(numbering), createDocumentStyleContextPlugin(styles)]
188
+ plugins: [
189
+ createDocumentNumberingPlugin(numbering),
190
+ createDocumentStyleContextPlugin(styles),
191
+ createNativeSelectionRefreshPlugin()
192
+ ]
188
193
  }) : buildInitialState(headerFooter, styles, theme, numbering, manager),
189
194
  dispatchTransaction(transaction) {
190
195
  if ((deps.getReadOnly?.() ?? false) && transaction.docChanged) return;
@@ -9,8 +9,8 @@ import { CanonicalCommentRequest, CanonicalCommentResult } from "../types/canoni
9
9
  import { CanonicalSectionPropertiesResult } from "../types/canonicalSections.js";
10
10
  import { Node } from "prosemirror-model";
11
11
  import { Command, EditorState, Transaction } from "prosemirror-state";
12
- import { EditorView } from "prosemirror-view";
13
12
  import { DocumentOp, FormattingPatch, OpStory } from "@stll/docx-core/ops";
13
+ import { EditorView } from "prosemirror-view";
14
14
  type CanonicalStoryHistoryOptions = {
15
15
  view: EditorView;
16
16
  story: OpStory;
@@ -61,6 +61,15 @@ export type HiddenEditorApi = {
61
61
  } | null;
62
62
  getCanonicalStoryProjection: (story: OpStory) => Node | null;
63
63
  replaceCanonicalStoryText: (options: CanonicalStoryTextOptions) => boolean;
64
+ /**
65
+ * The editor a person is working in for `story`: public operations on that
66
+ * story read its state, so its selection maps through them, and publish to
67
+ * it. A later view for the story replaces it; a destroyed one is ignored.
68
+ */
69
+ noteCanonicalStoryView: (options: {
70
+ story: OpStory;
71
+ view: EditorView;
72
+ }) => void;
64
73
  applyCanonicalDocumentOperations: (options: CanonicalPublicOperationOptions) => FolioDocumentOperationResult | null;
65
74
  undoCanonicalDocumentOperations: (handle: FolioDocumentOperationUndoHandle) => FolioDocumentOperationUndoResult | null;
66
75
  /** Focus the hidden editor */
@@ -103,7 +112,7 @@ export type HiddenEditorApiDeps = {
103
112
  resolveCanonicalSuggestion?: HiddenEditorApi["resolveCanonicalSuggestion"];
104
113
  executeCanonicalCommand?: (command: Command) => boolean | undefined;
105
114
  getCanonicalHistory?: () => Pick<HiddenEditorApi, "undo" | "redo" | "canUndo" | "canRedo"> | null;
106
- canonicalOperations?: Pick<HiddenEditorApi, "updateCanonicalInputLifecycle" | "applyCanonicalOperations" | "applyCanonicalComment" | "applyCanonicalSectionProperties" | "getCanonicalStoryProjection" | "replaceCanonicalStoryText" | "applyCanonicalStoryHistory" | "getCanonicalStorySelection" | "applyCanonicalDocumentOperations" | "undoCanonicalDocumentOperations">;
115
+ canonicalOperations?: Pick<HiddenEditorApi, "updateCanonicalInputLifecycle" | "applyCanonicalOperations" | "applyCanonicalComment" | "applyCanonicalSectionProperties" | "getCanonicalStoryProjection" | "replaceCanonicalStoryText" | "noteCanonicalStoryView" | "applyCanonicalStoryHistory" | "getCanonicalStorySelection" | "applyCanonicalDocumentOperations" | "undoCanonicalDocumentOperations">;
107
116
  isDestroying: () => boolean;
108
117
  ensureView: () => void;
109
118
  isViewRequested: () => boolean;
@@ -58,6 +58,9 @@ const createHiddenEditorApi = (deps) => {
58
58
  getCanonicalStorySelection: (story) => deps.canonicalOperations?.getCanonicalStorySelection(story) ?? null,
59
59
  getCanonicalStoryProjection: (story) => deps.canonicalOperations?.getCanonicalStoryProjection(story) ?? null,
60
60
  replaceCanonicalStoryText: (options) => deps.canonicalOperations?.replaceCanonicalStoryText(options) ?? false,
61
+ noteCanonicalStoryView: (options) => {
62
+ deps.canonicalOperations?.noteCanonicalStoryView(options);
63
+ },
61
64
  applyCanonicalDocumentOperations: (options) => deps.canonicalOperations?.applyCanonicalDocumentOperations(options) ?? null,
62
65
  undoCanonicalDocumentOperations: (handle) => deps.canonicalOperations?.undoCanonicalDocumentOperations(handle) ?? null,
63
66
  focus: () => {
@@ -119,6 +119,13 @@ export type HiddenEditorManager = {
119
119
  getView: () => EditorView | null;
120
120
  isInitialized: () => boolean;
121
121
  api: HiddenEditorApi;
122
+ /**
123
+ * The canonical session's own document, or null outside one, without the
124
+ * copy `api.getCanonicalDocument` makes for hosts. Each edit replaces it, so
125
+ * it stays as read; the editor's own story managers read it and never
126
+ * change it.
127
+ */
128
+ readCanonicalDocument: () => document_d_exports.Document | null;
122
129
  };
123
130
  export declare const createHiddenEditorManager: (deps: HiddenEditorManagerDeps) => HiddenEditorManager;
124
131
  export {};
@@ -4,6 +4,7 @@ import { isReadOnlyEditKey } from "../paged-layout/readOnlyEditAttempt.js";
4
4
  import { getCanonicalCommandIntents } from "../prosemirror/canonicalCommands.js";
5
5
  import { registerClipboardIntentHandler } from "../prosemirror/clipboardIntent.js";
6
6
  import { pasteWithoutFormatting } from "../prosemirror/commands/pastePlainText.js";
7
+ import { createCommentRecordsPlugin, isCommentRecordsSync } from "../prosemirror/commentRecords.js";
7
8
  import { createEmptyDoc, toProseDoc } from "../prosemirror/conversion/toProseDoc.js";
8
9
  import { registerEditorCommandOwner } from "../prosemirror/executeEditorCommand.js";
9
10
  import { ensureBaseDirectionInState } from "../prosemirror/extensions/features/AutoBidiDetectionExtension.js";
@@ -11,6 +12,7 @@ import { ensureParaIdsInDoc, ensureParaIdsInState } from "../prosemirror/extensi
11
12
  import { createParagraphChangeTrackerPlugin, markPackageChange } from "../prosemirror/extensions/features/ParagraphChangeTrackerExtension.js";
12
13
  import { toggleMarkForAllScripts, toggleUnderlineMark } from "../prosemirror/extensions/marks/markUtils.js";
13
14
  import { HyperlinkRemovalRefusal } from "../prosemirror/hyperlinkRemoval.js";
15
+ import { adoptNativeSelection, createNativeSelectionRefreshPlugin, isCompositionKeyDown } from "../prosemirror/nativeSelection.js";
14
16
  import { markNoteReferenceReplay, noteReferenceTransactionIssue } from "../prosemirror/noteReferenceOccurrences.js";
15
17
  import { createDocumentNumberingPlugin } from "../prosemirror/plugins/documentNumbering.js";
16
18
  import { createDocumentStyleContextPlugin, createDocumentStylesPlugin } from "../prosemirror/plugins/documentStyles.js";
@@ -30,7 +32,7 @@ import { createHiddenEditorApi } from "./hiddenEditorApi.js";
30
32
  import { handleReadOnlySelectionKeyDown } from "./readOnlySelection.js";
31
33
  import { Result, TaggedError, panic } from "better-result";
32
34
  import { CellSelection } from "prosemirror-tables";
33
- import { OP_STORIES, freshCommentId } from "@stll/docx-core/ops";
35
+ import { OP_STORIES, freshCommentId, sameStory } from "@stll/docx-core/ops";
34
36
  import { EditorState, Plugin } from "prosemirror-state";
35
37
  import { EditorView } from "prosemirror-view";
36
38
  // src/controller/hiddenEditorManager.ts
@@ -125,6 +127,7 @@ function createHiddenEditorState(options) {
125
127
  const styleResolverPlugin = createDocumentStylesPlugin(styles ?? document?.package.styles);
126
128
  const plugins = [
127
129
  createDocumentNumberingPlugin(document?.package.numbering),
130
+ createCommentRecordsPlugin(document?.package.document.comments ?? []),
128
131
  ...externalPlugins,
129
132
  ...manager?.getPlugins() ?? [createTextInputPlugin()],
130
133
  styleResolverPlugin
@@ -272,6 +275,7 @@ const createHiddenEditorManager = (deps) => {
272
275
  plugins: [
273
276
  createDocumentNumberingPlugin(session.document.package.numbering),
274
277
  createParagraphChangeTrackerPlugin(),
278
+ createNativeSelectionRefreshPlugin(),
275
279
  createDocumentStyleContextPlugin(deps.getStyles() ?? session.document.package.styles),
276
280
  ...[...deps.getExtensionManager()?.getPlugins() ?? [], ...deps.getExternalPlugins()].flatMap(({ props }) => props.transformPastedHTML === void 0 && props.transformPasted === void 0 && props.transformCopied === void 0 && props.clipboardTextSerializer === void 0 ? [] : [new Plugin({ props: {
277
281
  ...props.transformCopied === void 0 ? {} : { transformCopied: props.transformCopied },
@@ -615,7 +619,7 @@ const createHiddenEditorManager = (deps) => {
615
619
  editable: () => !deps.getReadOnly() && editorSession.type !== "refused",
616
620
  dispatchTransaction: (transaction) => {
617
621
  if (!view || isDestroying) return;
618
- if (deps.getReadOnly() && transaction.docChanged) {
622
+ if (deps.getReadOnly() && transaction.docChanged && !isCommentRecordsSync(transaction)) {
619
623
  deps.onReadOnlyEditAttempt();
620
624
  return;
621
625
  }
@@ -640,8 +644,8 @@ const createHiddenEditorManager = (deps) => {
640
644
  return;
641
645
  }
642
646
  view.updateState(applied.state);
643
- const docChanged = applied.transactions.some((appliedTransaction) => appliedTransaction.docChanged);
644
- const selectionChanged = applied.transactions.some((appliedTransaction) => appliedTransaction.selectionSet || appliedTransaction.docChanged);
647
+ const docChanged = applied.transactions.some((appliedTransaction) => appliedTransaction.docChanged && !isCommentRecordsSync(appliedTransaction));
648
+ const selectionChanged = applied.transactions.some((appliedTransaction) => appliedTransaction.selectionSet || appliedTransaction.docChanged && !isCommentRecordsSync(appliedTransaction));
645
649
  deps.onTransaction({
646
650
  transactions: applied.transactions,
647
651
  newState: applied.state,
@@ -726,7 +730,10 @@ const createHiddenEditorManager = (deps) => {
726
730
  },
727
731
  handleScrollToSelection: suppressHiddenEditorScrollToSelection,
728
732
  handleDOMEvents: {
729
- keydown: (pmView, event) => editorSession.type === "canonical" ? input.handleDOMEvents.keydown(pmView, event) : false,
733
+ keydown: (pmView, event) => {
734
+ if (!input.isComposing && !isCompositionKeyDown(event)) adoptNativeSelection(pmView);
735
+ return editorSession.type === "canonical" ? input.handleDOMEvents.keydown(pmView, event) : false;
736
+ },
730
737
  focus: () => false,
731
738
  blur: (pmView) => editorSession.type === "canonical" ? input.handleDOMEvents.blur(pmView) : false,
732
739
  ...createHiddenEditorClipboardHandlers(deps),
@@ -739,6 +746,7 @@ const createHiddenEditorManager = (deps) => {
739
746
  },
740
747
  cut: (pmView, event) => editorSession.type === "canonical" ? input.handleDOMEvents.cut(pmView, event) : createHiddenEditorClipboardHandlers(deps).cut(pmView, event),
741
748
  beforeinput: (_view, event) => {
749
+ if (!input.isComposing && !event.isComposing) adoptNativeSelection(_view);
742
750
  if (editorSession.type === "canonical" && !deps.getReadOnly()) return input.handleDOMEvents.beforeinput(_view, event);
743
751
  if (!deps.getReadOnly()) return false;
744
752
  deps.onReadOnlyEditAttempt();
@@ -818,8 +826,12 @@ const createHiddenEditorManager = (deps) => {
818
826
  }
819
827
  };
820
828
  const syncExternalDocument = () => {
821
- if (!view || isDestroying) return;
829
+ if (isDestroying) return;
822
830
  const canonicalRequested = usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting);
831
+ if (!view) {
832
+ if (canonicalRequested && deps.getDocument() !== null) ensureView();
833
+ return;
834
+ }
823
835
  const collaboration = deps.getCollaboration();
824
836
  const collaborationModules = deps.getCollaborationModules();
825
837
  if (collaboration && !collaborationModules && !canonicalRequested) return;
@@ -859,6 +871,13 @@ const createHiddenEditorManager = (deps) => {
859
871
  if (view.editable !== !readOnly) view.setProps({ editable: () => !deps.getReadOnly() });
860
872
  syncHiddenEditorAccessibility(view, readOnly);
861
873
  };
874
+ /**
875
+ * Publishes a commit to a secondary story: the body view takes the body
876
+ * projection the commit carries, and the story's open editor, if one is
877
+ * open, takes the story projection. With no story editor open, the commit
878
+ * is staged against the story's projection as it stood before the edit.
879
+ * Every path that edits a secondary story, editor or API, publishes here.
880
+ */
862
881
  const publishStoryCommit = (storyView, commit) => {
863
882
  if (!view || editorSession.type !== "canonical") return false;
864
883
  const session = editorSession.session;
@@ -883,7 +902,10 @@ const createHiddenEditorManager = (deps) => {
883
902
  return false;
884
903
  }
885
904
  const staged = publishCanonicalProjection({
886
- state: storyView.state,
905
+ state: storyView?.state ?? EditorState.create({
906
+ schema: view.state.schema,
907
+ doc: commit.transaction.before
908
+ }),
887
909
  commit,
888
910
  session
889
911
  });
@@ -891,7 +913,7 @@ const createHiddenEditorManager = (deps) => {
891
913
  refuse(staged.error.message, staged.error.ground);
892
914
  return false;
893
915
  }
894
- storyView.updateState(staged.value.state);
916
+ storyView?.updateState(staged.value.state);
895
917
  view.updateState(bodyStaged.value.state);
896
918
  deps.onTransaction({
897
919
  transactions: staged.value.transactions,
@@ -902,14 +924,38 @@ const createHiddenEditorManager = (deps) => {
902
924
  return true;
903
925
  };
904
926
  let publicOperations = null;
927
+ /** The editor last in use for each secondary story, as its editors report it. */
928
+ const storyViews = [];
929
+ /** The open editor of `story` showing its committed projection, if any. */
930
+ const openStoryView = (session, story) => {
931
+ const entry = storyViews.find((candidate) => sameStory(candidate.story, story));
932
+ if (!entry || entry.view.isDestroyed) return null;
933
+ const projected = session.projectStory(story);
934
+ return projected.isOk() && entry.view.state.doc.eq(projected.value.doc) ? entry.view : null;
935
+ };
905
936
  const getPublicOperations = () => {
906
937
  if (editorSession.type !== "canonical") return null;
907
938
  const session = editorSession.session;
908
939
  if (publicOperations?.session === session) return publicOperations.executor;
909
940
  const executor = new CanonicalPublicOperations({
910
941
  session,
911
- getState: (story) => story === OP_STORIES.MAIN && !deps.getReadOnly() && !isDestroying ? view?.state ?? null : null,
912
- publish: publishCommit
942
+ getState: (story) => {
943
+ if (!view || deps.getReadOnly() || isDestroying) return null;
944
+ if (story === OP_STORIES.MAIN) return view.state;
945
+ const open = openStoryView(session, story);
946
+ if (open) return open.state;
947
+ const projected = session.projectStory(story);
948
+ return projected.isErr() ? null : EditorState.create({
949
+ schema: view.state.schema,
950
+ doc: projected.value.doc
951
+ });
952
+ },
953
+ publish: (commit) => {
954
+ const story = commit.selection.anchor.story;
955
+ if (story === OP_STORIES.MAIN) return publishCommit(commit);
956
+ const open = storyViews.find((candidate) => sameStory(candidate.story, story))?.view;
957
+ return publishStoryCommit(open && !open.isDestroyed && open.state.doc.eq(commit.transaction.before) ? open : null, commit);
958
+ }
913
959
  });
914
960
  publicOperations = {
915
961
  session,
@@ -1146,7 +1192,6 @@ const createHiddenEditorManager = (deps) => {
1146
1192
  return publishCommit(prepared.value);
1147
1193
  },
1148
1194
  getCanonicalStoryProjection: (story) => {
1149
- if (usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting)) ensureView();
1150
1195
  if (editorSession.type !== "canonical" || editorSession.session.isComposing) return null;
1151
1196
  const result = editorSession.session.projectStory(story);
1152
1197
  if (result.isErr()) {
@@ -1155,6 +1200,15 @@ const createHiddenEditorManager = (deps) => {
1155
1200
  }
1156
1201
  return result.value.doc;
1157
1202
  },
1203
+ noteCanonicalStoryView: ({ story, view: storyView }) => {
1204
+ if (story === OP_STORIES.MAIN) return;
1205
+ const index = storyViews.findIndex((candidate) => sameStory(candidate.story, story));
1206
+ if (index >= 0) storyViews.splice(index, 1);
1207
+ storyViews.push({
1208
+ story,
1209
+ view: storyView
1210
+ });
1211
+ },
1158
1212
  replaceCanonicalStoryText: ({ view: storyView, story, intent }) => {
1159
1213
  if (!view || editorSession.type !== "canonical" || deps.getReadOnly()) return false;
1160
1214
  syncCanonicalMode();
@@ -1173,6 +1227,7 @@ const createHiddenEditorManager = (deps) => {
1173
1227
  ensureView,
1174
1228
  isViewRequested
1175
1229
  }),
1230
+ readCanonicalDocument: () => editorSession.type === "canonical" ? editorSession.session.document : null,
1176
1231
  isCanonicalComposing: () => editorSession.type === "canonical" && editorSession.session.isComposing
1177
1232
  };
1178
1233
  };
@@ -183,7 +183,8 @@ function runLayoutPipelineMeasured(deps, state, options) {
183
183
  pageContentHeight,
184
184
  fontAlternates,
185
185
  ...styles ? { styles } : {},
186
- ...document === null ? {} : { defaultSize: 10 }
186
+ ...document === null ? {} : { defaultSize: 10 },
187
+ paragraphBlocks: session.paragraphBlocks
187
188
  };
188
189
  if (_theme !== void 0) flowOpts.theme = _theme;
189
190
  if (defaultTabStop !== void 0) flowOpts.defaultTabStopTwips = defaultTabStop;
@@ -3,6 +3,7 @@ import { TemplatePreviewEntry, TemplatePreviewHiddenRange, TemplatePreviewValues
3
3
  import { DisplayMode } from "../managers/EditorModeManager.js";
4
4
  import { FlowBlock, Measure } from "../layout-engine/types.js";
5
5
  import { FontAlternates } from "../fonts/fontAlternates.js";
6
+ import { ParagraphBlockCache } from "../layout-bridge/convert/paragraphBlockCache.js";
6
7
  import { EditorState } from "prosemirror-state";
7
8
  export type LayoutArtifacts = {
8
9
  blocks: FlowBlock[];
@@ -46,5 +47,7 @@ export type LayoutSession = {
46
47
  lastPmDoc: EditorState["doc"] | null;
47
48
  lastMeasureInputs: LayoutMeasureInputs | null;
48
49
  lastTemplatePreview: LayoutTemplatePreview;
50
+ /** Body paragraph blocks kept from earlier layout runs, so an edit converts only what it changed. */
51
+ paragraphBlocks: ParagraphBlockCache;
49
52
  };
50
53
  export declare const createLayoutSession: () => LayoutSession;
@@ -1,3 +1,4 @@
1
+ import { ParagraphBlockCache } from "../layout-bridge/convert/paragraphBlockCache.js";
1
2
  // src/controller/layoutSession.ts
2
3
  const createLayoutSession = () => ({
3
4
  artifacts: null,
@@ -8,6 +9,7 @@ const createLayoutSession = () => ({
8
9
  entries: [],
9
10
  hidden: [],
10
11
  mode: "plain"
11
- }
12
+ },
13
+ paragraphBlocks: new ParagraphBlockCache()
12
14
  });
13
15
  export { createLayoutSession };
@@ -14,6 +14,11 @@ export type NoteEditorManagerDeps = {
14
14
  createView?: ((mountNode: HTMLElement, props: DirectEditorProps) => EditorView) | undefined;
15
15
  getDocument: () => document_d_exports.Document | null;
16
16
  getCanonicalApi?: (() => HiddenEditorApi | null) | undefined;
17
+ /**
18
+ * The canonical session's own document, read without a copy (see
19
+ * `HiddenEditorManager.readCanonicalDocument`); null outside a session.
20
+ */
21
+ readCanonicalDocument: () => document_d_exports.Document | null;
17
22
  getExperimentalSession?: (() => "canonical" | undefined) | undefined;
18
23
  onSessionRefusal?: ((reason: string, ground: CanonicalRefusalGround, error?: Error) => void) | undefined;
19
24
  getHost: () => HTMLElement | null;
@@ -7,6 +7,7 @@ import { ExtensionManager } from "../prosemirror/extensions/ExtensionManager.js"
7
7
  import { createStarterKit } from "../prosemirror/extensions/StarterKit.js";
8
8
  import { ensureBaseDirectionInState } from "../prosemirror/extensions/features/AutoBidiDetectionExtension.js";
9
9
  import { ensureParaIdsInState } from "../prosemirror/extensions/features/ParaIdAllocatorExtension.js";
10
+ import { createNativeSelectionRefreshPlugin } from "../prosemirror/nativeSelection.js";
10
11
  import { noteReferenceTransactionIssue } from "../prosemirror/noteReferenceOccurrences.js";
11
12
  import { createDocumentNumberingPlugin } from "../prosemirror/plugins/documentNumbering.js";
12
13
  import { createDocumentStyleContextPlugin, createDocumentStylesPlugin } from "../prosemirror/plugins/documentStyles.js";
@@ -89,7 +90,7 @@ const createNoteEditorManager = (deps) => {
89
90
  mounted.clear();
90
91
  active = null;
91
92
  };
92
- const getOwnedDocument = () => usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting) ? deps.getCanonicalApi?.()?.getCanonicalDocument() ?? null : deps.getDocument();
93
+ const getOwnedDocument = () => usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting) ? deps.readCanonicalDocument() : deps.getDocument();
93
94
  const sync = () => {
94
95
  const host = deps.getHost();
95
96
  if (!host) return;
@@ -200,7 +201,11 @@ const createNoteEditorManager = (deps) => {
200
201
  ...canonical.props,
201
202
  state: canonicalProjection ? EditorState.create({
202
203
  doc: canonicalProjection,
203
- plugins: [createDocumentNumberingPlugin(numbering), createDocumentStyleContextPlugin(styles)]
204
+ plugins: [
205
+ createDocumentNumberingPlugin(numbering),
206
+ createDocumentStyleContextPlugin(styles),
207
+ createNativeSelectionRefreshPlugin()
208
+ ]
204
209
  }) : buildInitialState(proseDocument, styles, numbering, manager, externalPlugins),
205
210
  dispatchTransaction(transaction) {
206
211
  if (canonical.dispatch(transaction)) return;