@beyondwork/docx-react-component 1.0.36 → 1.0.38

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 (107) hide show
  1. package/README.md +103 -13
  2. package/package.json +1 -1
  3. package/src/api/package-version.ts +13 -0
  4. package/src/api/public-types.ts +402 -1
  5. package/src/core/commands/index.ts +18 -1
  6. package/src/core/commands/section-layout-commands.ts +58 -0
  7. package/src/core/commands/table-grid.ts +431 -0
  8. package/src/core/commands/table-structure-commands.ts +815 -55
  9. package/src/core/selection/mapping.ts +6 -0
  10. package/src/io/docx-session.ts +24 -9
  11. package/src/io/export/build-app-properties-xml.ts +88 -0
  12. package/src/io/export/serialize-comments.ts +6 -1
  13. package/src/io/export/serialize-footnotes.ts +10 -9
  14. package/src/io/export/serialize-headers-footers.ts +11 -10
  15. package/src/io/export/serialize-main-document.ts +328 -50
  16. package/src/io/export/serialize-numbering.ts +114 -24
  17. package/src/io/export/serialize-tables.ts +87 -11
  18. package/src/io/export/table-properties-xml.ts +174 -20
  19. package/src/io/export/twip.ts +66 -0
  20. package/src/io/normalize/normalize-text.ts +20 -0
  21. package/src/io/ooxml/parse-footnotes.ts +62 -1
  22. package/src/io/ooxml/parse-headers-footers.ts +62 -1
  23. package/src/io/ooxml/parse-main-document.ts +158 -1
  24. package/src/io/ooxml/parse-tables.ts +249 -0
  25. package/src/legal/bookmarks.ts +78 -0
  26. package/src/model/canonical-document.ts +45 -0
  27. package/src/review/store/scope-tag-diff.ts +130 -0
  28. package/src/runtime/document-layout.ts +4 -2
  29. package/src/runtime/document-navigation.ts +2 -306
  30. package/src/runtime/document-runtime.ts +287 -11
  31. package/src/runtime/layout/default-page-format.ts +96 -0
  32. package/src/runtime/layout/docx-font-loader.ts +143 -0
  33. package/src/runtime/layout/index.ts +233 -0
  34. package/src/runtime/layout/inert-layout-facet.ts +59 -0
  35. package/src/runtime/layout/layout-engine-instance.ts +628 -0
  36. package/src/runtime/layout/layout-invalidation.ts +257 -0
  37. package/src/runtime/layout/layout-measurement-provider.ts +175 -0
  38. package/src/runtime/layout/margin-preset-catalog.ts +178 -0
  39. package/src/runtime/layout/measurement-backend-canvas.ts +307 -0
  40. package/src/runtime/layout/measurement-backend-empirical.ts +208 -0
  41. package/src/runtime/layout/page-format-catalog.ts +233 -0
  42. package/src/runtime/layout/page-fragment-mapper.ts +179 -0
  43. package/src/runtime/layout/page-graph.ts +452 -0
  44. package/src/runtime/layout/page-layout-snapshot-adapter.ts +70 -0
  45. package/src/runtime/layout/page-story-resolver.ts +195 -0
  46. package/src/runtime/layout/paginated-layout-engine.ts +921 -0
  47. package/src/runtime/layout/project-block-fragments.ts +91 -0
  48. package/src/runtime/layout/public-facet.ts +1398 -0
  49. package/src/runtime/layout/resolved-formatting-document.ts +317 -0
  50. package/src/runtime/layout/resolved-formatting-state.ts +430 -0
  51. package/src/runtime/layout/table-render-plan.ts +229 -0
  52. package/src/runtime/render/block-fragment-projection.ts +35 -0
  53. package/src/runtime/render/decoration-resolver.ts +189 -0
  54. package/src/runtime/render/index.ts +57 -0
  55. package/src/runtime/render/pending-op-delta-reader.ts +129 -0
  56. package/src/runtime/render/render-frame-types.ts +317 -0
  57. package/src/runtime/render/render-kernel.ts +755 -0
  58. package/src/runtime/scope-tag-registry.ts +95 -0
  59. package/src/runtime/surface-projection.ts +1 -0
  60. package/src/runtime/text-ack-range.ts +49 -0
  61. package/src/runtime/view-state.ts +67 -0
  62. package/src/runtime/workflow-markup.ts +1 -5
  63. package/src/runtime/workflow-rail-segments.ts +280 -0
  64. package/src/ui/WordReviewEditor.tsx +99 -15
  65. package/src/ui/editor-runtime-boundary.ts +10 -1
  66. package/src/ui/editor-shell-view.tsx +6 -0
  67. package/src/ui/editor-surface-controller.tsx +3 -0
  68. package/src/ui/headless/chrome-registry.ts +501 -0
  69. package/src/ui/headless/scoped-chrome-policy.ts +183 -0
  70. package/src/ui/headless/selection-tool-context.ts +2 -0
  71. package/src/ui/headless/selection-tool-resolver.ts +36 -17
  72. package/src/ui/headless/selection-tool-types.ts +10 -0
  73. package/src/ui-tailwind/chrome/chrome-preset-model.ts +23 -2
  74. package/src/ui-tailwind/chrome/role-action-sets.ts +74 -0
  75. package/src/ui-tailwind/chrome/tw-detach-handle.tsx +147 -0
  76. package/src/ui-tailwind/chrome/tw-selection-anchor-resolver.ts +163 -0
  77. package/src/ui-tailwind/chrome/tw-selection-tool-host.tsx +57 -92
  78. package/src/ui-tailwind/chrome/tw-selection-tool-placement.ts +149 -0
  79. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +15 -4
  80. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +274 -138
  81. package/src/ui-tailwind/chrome-overlay/chrome-overlay-projector.ts +90 -0
  82. package/src/ui-tailwind/chrome-overlay/index.ts +22 -0
  83. package/src/ui-tailwind/chrome-overlay/tw-chrome-overlay.tsx +86 -0
  84. package/src/ui-tailwind/chrome-overlay/tw-scope-rail-layer.tsx +178 -0
  85. package/src/ui-tailwind/chrome-overlay/tw-workspace-view-switcher.tsx +95 -0
  86. package/src/ui-tailwind/editor-surface/fast-text-edit-lane.ts +337 -0
  87. package/src/ui-tailwind/editor-surface/local-edit-session-state.ts +100 -0
  88. package/src/ui-tailwind/editor-surface/perf-probe.ts +27 -1
  89. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +20 -2
  90. package/src/ui-tailwind/editor-surface/pm-decorations.ts +93 -23
  91. package/src/ui-tailwind/editor-surface/predicted-position-map.ts +78 -0
  92. package/src/ui-tailwind/editor-surface/predicted-tag-preflight.ts +63 -0
  93. package/src/ui-tailwind/editor-surface/predicted-tx-gate.ts +39 -0
  94. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +176 -6
  95. package/src/ui-tailwind/index.ts +33 -0
  96. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +2 -2
  97. package/src/ui-tailwind/review/tw-rail-card.tsx +150 -0
  98. package/src/ui-tailwind/review/tw-review-rail-footer.tsx +52 -0
  99. package/src/ui-tailwind/review/tw-review-rail.tsx +166 -11
  100. package/src/ui-tailwind/review/tw-workflow-tab.tsx +108 -0
  101. package/src/ui-tailwind/theme/editor-theme.css +505 -144
  102. package/src/ui-tailwind/toolbar/tw-role-action-region.tsx +559 -0
  103. package/src/ui-tailwind/toolbar/tw-scope-posture-menu.tsx +182 -0
  104. package/src/ui-tailwind/toolbar/tw-shell-header.tsx +162 -0
  105. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +2 -2
  106. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +304 -166
  107. package/src/ui-tailwind/tw-review-workspace.tsx +163 -2
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Project surface blocks → per-page RuntimeBlockFragments (P4).
3
+ *
4
+ * The pagination engine produces `DocumentPageSnapshot[]` keyed by offset
5
+ * ranges, but for render-kernel consumers to get per-block geometry (and
6
+ * for the chrome to anchor tables, images, etc.) we need one block
7
+ * fragment per top-level surface block, assigned to the page that contains
8
+ * its offset range.
9
+ *
10
+ * Today the engine does not split tables across pages, so this emission
11
+ * pass treats each top-level SurfaceBlockSnapshot as an atomic fragment
12
+ * with `pageIndex` resolved from `pages[i].startOffset..endOffset`. Row-
13
+ * level splitting (for header-row repeat + per-row cantSplit) will refine
14
+ * this to multiple fragments per block.
15
+ */
16
+
17
+ import type {
18
+ DocumentPageSnapshot,
19
+ EditorSurfaceSnapshot,
20
+ SurfaceBlockSnapshot,
21
+ } from "../../api/public-types";
22
+ import type { RuntimeBlockFragment } from "./page-graph.ts";
23
+
24
+ type FragmentWithoutPageId = Omit<RuntimeBlockFragment, "pageId">;
25
+
26
+ export function projectSurfaceBlocksToPageFragments(
27
+ surface: EditorSurfaceSnapshot,
28
+ pages: readonly DocumentPageSnapshot[],
29
+ ): Map<number, FragmentWithoutPageId[]> {
30
+ const byPage = new Map<number, FragmentWithoutPageId[]>();
31
+ const perPageCounter = new Map<number, number>();
32
+
33
+ for (const block of surface.blocks) {
34
+ const pageIndex = findPageIndexForOffset(pages, block.from);
35
+ if (pageIndex === null) continue;
36
+ const orderInRegion = perPageCounter.get(pageIndex) ?? 0;
37
+ perPageCounter.set(pageIndex, orderInRegion + 1);
38
+
39
+ const fragment: FragmentWithoutPageId = {
40
+ fragmentId: `fragment-${block.blockId}`,
41
+ blockId: block.blockId,
42
+ orderInRegion,
43
+ regionKind: "body",
44
+ from: block.from,
45
+ to: block.to,
46
+ // Height is not recomputed here — the pagination engine already
47
+ // measured the block to assign it to this page. Chrome surfaces
48
+ // that need precise heights can consult layout facet measurements.
49
+ heightTwips: estimateBlockHeightFromSpan(block),
50
+ };
51
+
52
+ const existing = byPage.get(pageIndex);
53
+ if (existing) {
54
+ existing.push(fragment);
55
+ } else {
56
+ byPage.set(pageIndex, [fragment]);
57
+ }
58
+ }
59
+
60
+ return byPage;
61
+ }
62
+
63
+ function findPageIndexForOffset(
64
+ pages: readonly DocumentPageSnapshot[],
65
+ offset: number,
66
+ ): number | null {
67
+ for (let i = 0; i < pages.length; i += 1) {
68
+ const page = pages[i]!;
69
+ if (offset >= page.startOffset && offset < page.endOffset) {
70
+ return page.pageIndex;
71
+ }
72
+ }
73
+ // Fall back to the last page for offsets that equal storySize.
74
+ const last = pages[pages.length - 1];
75
+ if (last && offset >= last.startOffset && offset <= last.endOffset) {
76
+ return last.pageIndex;
77
+ }
78
+ return null;
79
+ }
80
+
81
+ /**
82
+ * Rough height estimate from the block's offset span. Only used as a
83
+ * fallback when the caller did not pre-measure. Chrome consumers that
84
+ * need accurate heights should read `facet.getMeasurement(blockId)`.
85
+ */
86
+ function estimateBlockHeightFromSpan(block: SurfaceBlockSnapshot): number {
87
+ // 240 twips per line; approximate 80 chars per line for paragraphs.
88
+ const span = Math.max(0, block.to - block.from);
89
+ const lines = Math.max(1, Math.ceil(span / 80));
90
+ return lines * 240;
91
+ }