@beyondwork/docx-react-component 1.0.28 → 1.0.29

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 (354) hide show
  1. package/dist/canonical-document-BLEbzL2J.d.cts +844 -0
  2. package/dist/canonical-document-BLEbzL2J.d.ts +844 -0
  3. package/dist/chunk-2FJS5GZM.js +763 -0
  4. package/dist/chunk-2FJS5GZM.js.map +1 -0
  5. package/{src/core/commands/section-layout-commands.ts → dist/chunk-2OQBZS3F.js} +106 -340
  6. package/dist/chunk-2OQBZS3F.js.map +1 -0
  7. package/dist/chunk-2S7W4KFO.js +127 -0
  8. package/dist/chunk-2S7W4KFO.js.map +1 -0
  9. package/dist/chunk-2TG72QSW.js +3874 -0
  10. package/dist/chunk-2TG72QSW.js.map +1 -0
  11. package/{src/core/commands/table-structure-commands.ts → dist/chunk-36QNIZBO.js} +126 -315
  12. package/dist/chunk-36QNIZBO.js.map +1 -0
  13. package/dist/chunk-4AQOYAW4.js +3069 -0
  14. package/dist/chunk-4AQOYAW4.js.map +1 -0
  15. package/dist/chunk-4D5EWJ3P.js +77 -0
  16. package/dist/chunk-4D5EWJ3P.js.map +1 -0
  17. package/dist/chunk-5FN54NDH.js +2257 -0
  18. package/dist/chunk-5FN54NDH.js.map +1 -0
  19. package/dist/chunk-BOYGQYRQ.js +7306 -0
  20. package/dist/chunk-BOYGQYRQ.js.map +1 -0
  21. package/dist/chunk-CN3XMECL.js +212 -0
  22. package/dist/chunk-CN3XMECL.js.map +1 -0
  23. package/dist/chunk-EBI3BX6U.js +164 -0
  24. package/dist/chunk-EBI3BX6U.js.map +1 -0
  25. package/dist/chunk-EILUG3VB.js +1275 -0
  26. package/dist/chunk-EILUG3VB.js.map +1 -0
  27. package/dist/chunk-FUDY333O.js +70 -0
  28. package/dist/chunk-FUDY333O.js.map +1 -0
  29. package/dist/chunk-GBVOWFIK.js +1237 -0
  30. package/dist/chunk-GBVOWFIK.js.map +1 -0
  31. package/dist/chunk-H4TQ3H3Y.js +262 -0
  32. package/dist/chunk-H4TQ3H3Y.js.map +1 -0
  33. package/{src/core/commands/style-commands.ts → dist/chunk-JGB3IXZO.js} +40 -113
  34. package/dist/chunk-JGB3IXZO.js.map +1 -0
  35. package/dist/chunk-KD2QRQPY.js +4342 -0
  36. package/dist/chunk-KD2QRQPY.js.map +1 -0
  37. package/dist/chunk-KLMXQVYK.js +369 -0
  38. package/dist/chunk-KLMXQVYK.js.map +1 -0
  39. package/dist/chunk-KZUG5KFQ.js +214 -0
  40. package/dist/chunk-KZUG5KFQ.js.map +1 -0
  41. package/{src/core/state/text-transaction.ts → dist/chunk-QDAQ4CJU.js} +79 -236
  42. package/dist/chunk-QDAQ4CJU.js.map +1 -0
  43. package/{src/legal/bookmarks.ts → dist/chunk-RMH72RZI.js} +44 -130
  44. package/dist/chunk-RMH72RZI.js.map +1 -0
  45. package/dist/chunk-SWKWQZXM.js +117 -0
  46. package/dist/chunk-SWKWQZXM.js.map +1 -0
  47. package/{src/core/commands/formatting-commands.ts → dist/chunk-TJBP2K4T.js} +196 -536
  48. package/dist/chunk-TJBP2K4T.js.map +1 -0
  49. package/dist/chunk-TLCEAQDQ.js +542 -0
  50. package/dist/chunk-TLCEAQDQ.js.map +1 -0
  51. package/{src/core/commands/text-commands.ts → dist/chunk-UZXBISGO.js} +86 -142
  52. package/dist/chunk-UZXBISGO.js.map +1 -0
  53. package/dist/chunk-WGBAKP3Q.js +3220 -0
  54. package/dist/chunk-WGBAKP3Q.js.map +1 -0
  55. package/dist/compare/index.cjs +5475 -0
  56. package/dist/compare/index.cjs.map +1 -0
  57. package/dist/compare/index.d.cts +114 -0
  58. package/dist/compare/index.d.ts +114 -0
  59. package/dist/compare/index.js +731 -0
  60. package/dist/compare/index.js.map +1 -0
  61. package/dist/core/commands/formatting-commands.cjs +828 -0
  62. package/dist/core/commands/formatting-commands.cjs.map +1 -0
  63. package/dist/core/commands/formatting-commands.d.cts +63 -0
  64. package/dist/core/commands/formatting-commands.d.ts +63 -0
  65. package/dist/core/commands/formatting-commands.js +37 -0
  66. package/dist/core/commands/formatting-commands.js.map +1 -0
  67. package/dist/core/commands/image-commands.cjs +2023 -0
  68. package/dist/core/commands/image-commands.cjs.map +1 -0
  69. package/dist/core/commands/image-commands.d.cts +58 -0
  70. package/dist/core/commands/image-commands.d.ts +58 -0
  71. package/dist/core/commands/image-commands.js +18 -0
  72. package/dist/core/commands/image-commands.js.map +1 -0
  73. package/dist/core/commands/section-layout-commands.cjs +477 -0
  74. package/dist/core/commands/section-layout-commands.cjs.map +1 -0
  75. package/dist/core/commands/section-layout-commands.d.cts +62 -0
  76. package/dist/core/commands/section-layout-commands.d.ts +62 -0
  77. package/dist/core/commands/section-layout-commands.js +21 -0
  78. package/dist/core/commands/section-layout-commands.js.map +1 -0
  79. package/dist/core/commands/style-commands.cjs +214 -0
  80. package/dist/core/commands/style-commands.cjs.map +1 -0
  81. package/dist/core/commands/style-commands.d.cts +13 -0
  82. package/dist/core/commands/style-commands.d.ts +13 -0
  83. package/dist/core/commands/style-commands.js +9 -0
  84. package/dist/core/commands/style-commands.js.map +1 -0
  85. package/dist/core/commands/table-structure-commands.cjs +1883 -0
  86. package/dist/core/commands/table-structure-commands.cjs.map +1 -0
  87. package/dist/core/commands/table-structure-commands.d.cts +59 -0
  88. package/dist/core/commands/table-structure-commands.d.ts +59 -0
  89. package/dist/core/commands/table-structure-commands.js +12 -0
  90. package/dist/core/commands/table-structure-commands.js.map +1 -0
  91. package/dist/core/commands/text-commands.cjs +2391 -0
  92. package/dist/core/commands/text-commands.cjs.map +1 -0
  93. package/dist/core/commands/text-commands.d.cts +24 -0
  94. package/dist/core/commands/text-commands.d.ts +24 -0
  95. package/dist/core/commands/text-commands.js +28 -0
  96. package/dist/core/commands/text-commands.js.map +1 -0
  97. package/dist/core/selection/mapping.cjs +200 -0
  98. package/dist/core/selection/mapping.cjs.map +1 -0
  99. package/dist/core/selection/mapping.d.cts +2 -0
  100. package/dist/core/selection/mapping.d.ts +2 -0
  101. package/dist/core/selection/mapping.js +31 -0
  102. package/dist/core/selection/mapping.js.map +1 -0
  103. package/dist/core/state/editor-state.cjs +2278 -0
  104. package/dist/core/state/editor-state.cjs.map +1 -0
  105. package/dist/core/state/editor-state.d.cts +2 -0
  106. package/dist/core/state/editor-state.d.ts +2 -0
  107. package/dist/core/state/editor-state.js +26 -0
  108. package/dist/core/state/editor-state.js.map +1 -0
  109. package/dist/index.cjs +38553 -0
  110. package/dist/index.cjs.map +1 -0
  111. package/dist/index.d.cts +15 -0
  112. package/dist/index.d.ts +15 -0
  113. package/dist/index.js +7856 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/io/docx-session.cjs +16236 -0
  116. package/dist/io/docx-session.cjs.map +1 -0
  117. package/dist/io/docx-session.d.cts +21 -0
  118. package/dist/io/docx-session.d.ts +21 -0
  119. package/dist/io/docx-session.js +18 -0
  120. package/dist/io/docx-session.js.map +1 -0
  121. package/dist/legal/index.cjs +3900 -0
  122. package/dist/legal/index.cjs.map +1 -0
  123. package/dist/legal/index.d.cts +86 -0
  124. package/dist/legal/index.d.ts +86 -0
  125. package/dist/legal/index.js +616 -0
  126. package/dist/legal/index.js.map +1 -0
  127. package/dist/public-types-7ZL_94cz.d.ts +1573 -0
  128. package/dist/public-types-CeMaDueh.d.cts +1573 -0
  129. package/dist/public-types.cjs +19 -0
  130. package/dist/public-types.cjs.map +1 -0
  131. package/dist/public-types.d.cts +2 -0
  132. package/dist/public-types.d.ts +2 -0
  133. package/dist/public-types.js +1 -0
  134. package/dist/public-types.js.map +1 -0
  135. package/dist/runtime/document-runtime.cjs +11140 -0
  136. package/dist/runtime/document-runtime.cjs.map +1 -0
  137. package/dist/runtime/document-runtime.d.cts +231 -0
  138. package/dist/runtime/document-runtime.d.ts +231 -0
  139. package/dist/runtime/document-runtime.js +21 -0
  140. package/dist/runtime/document-runtime.js.map +1 -0
  141. package/dist/structural-helpers-CilgOVhh.d.cts +10 -0
  142. package/dist/structural-helpers-q0Gd-eBN.d.ts +10 -0
  143. package/dist/ui-tailwind/editor-surface/search-plugin.cjs +313 -0
  144. package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +1 -0
  145. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +67 -0
  146. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +67 -0
  147. package/dist/ui-tailwind/editor-surface/search-plugin.js +23 -0
  148. package/dist/ui-tailwind/editor-surface/search-plugin.js.map +1 -0
  149. package/dist/ui-tailwind/index.cjs +4833 -0
  150. package/dist/ui-tailwind/index.cjs.map +1 -0
  151. package/dist/ui-tailwind/index.d.cts +617 -0
  152. package/dist/ui-tailwind/index.d.ts +617 -0
  153. package/dist/ui-tailwind/index.js +575 -0
  154. package/dist/ui-tailwind/index.js.map +1 -0
  155. package/package.json +61 -41
  156. package/src/README.md +0 -85
  157. package/src/api/README.md +0 -26
  158. package/src/api/public-types.ts +0 -1421
  159. package/src/api/session-state.ts +0 -60
  160. package/src/compare/diff-engine.ts +0 -623
  161. package/src/compare/export-redlines.ts +0 -280
  162. package/src/compare/index.ts +0 -25
  163. package/src/compare/snapshot.ts +0 -97
  164. package/src/component-inventory.md +0 -99
  165. package/src/core/README.md +0 -10
  166. package/src/core/commands/README.md +0 -3
  167. package/src/core/commands/image-commands.ts +0 -373
  168. package/src/core/commands/index.ts +0 -1757
  169. package/src/core/commands/list-commands.ts +0 -565
  170. package/src/core/commands/paragraph-layout-commands.ts +0 -339
  171. package/src/core/commands/review-commands.ts +0 -108
  172. package/src/core/commands/structural-helpers.ts +0 -309
  173. package/src/core/schema/README.md +0 -3
  174. package/src/core/schema/text-schema.ts +0 -516
  175. package/src/core/search/search-text.ts +0 -357
  176. package/src/core/selection/README.md +0 -3
  177. package/src/core/selection/mapping.ts +0 -289
  178. package/src/core/selection/review-anchors.ts +0 -183
  179. package/src/core/state/README.md +0 -3
  180. package/src/core/state/editor-state.ts +0 -892
  181. package/src/formats/xlsx/io/parse-shared-strings.ts +0 -41
  182. package/src/formats/xlsx/io/parse-sheet.ts +0 -459
  183. package/src/formats/xlsx/io/parse-styles.ts +0 -59
  184. package/src/formats/xlsx/io/parse-workbook.ts +0 -75
  185. package/src/formats/xlsx/io/serialize-shared-strings.ts +0 -72
  186. package/src/formats/xlsx/io/serialize-sheet.ts +0 -333
  187. package/src/formats/xlsx/io/serialize-styles.ts +0 -98
  188. package/src/formats/xlsx/io/serialize-workbook.ts +0 -429
  189. package/src/formats/xlsx/io/xlsx-session.ts +0 -314
  190. package/src/formats/xlsx/model/cell.ts +0 -189
  191. package/src/formats/xlsx/model/sheet.ts +0 -326
  192. package/src/formats/xlsx/model/styles.ts +0 -118
  193. package/src/formats/xlsx/model/workbook.ts +0 -453
  194. package/src/formats/xlsx/runtime/cell-commands.ts +0 -567
  195. package/src/formats/xlsx/runtime/sheet-commands.ts +0 -206
  196. package/src/formats/xlsx/runtime/workbook-runtime.ts +0 -177
  197. package/src/formats/xlsx/runtime/workbook-transaction.ts +0 -822
  198. package/src/index.ts +0 -101
  199. package/src/io/README.md +0 -10
  200. package/src/io/docx-session.ts +0 -2882
  201. package/src/io/export/README.md +0 -3
  202. package/src/io/export/export-session.ts +0 -220
  203. package/src/io/export/minimal-docx.ts +0 -115
  204. package/src/io/export/reattach-preserved-parts.ts +0 -54
  205. package/src/io/export/serialize-comments.ts +0 -947
  206. package/src/io/export/serialize-footnotes.ts +0 -399
  207. package/src/io/export/serialize-headers-footers.ts +0 -372
  208. package/src/io/export/serialize-main-document.ts +0 -1376
  209. package/src/io/export/serialize-numbering.ts +0 -118
  210. package/src/io/export/serialize-revisions.ts +0 -389
  211. package/src/io/export/serialize-runtime-revisions.ts +0 -269
  212. package/src/io/export/serialize-tables.ts +0 -174
  213. package/src/io/export/split-review-boundaries.ts +0 -356
  214. package/src/io/normalize/README.md +0 -3
  215. package/src/io/normalize/normalize-text.ts +0 -639
  216. package/src/io/ooxml/README.md +0 -3
  217. package/src/io/ooxml/highlight-colors.ts +0 -39
  218. package/src/io/ooxml/numbering-sentinels.ts +0 -44
  219. package/src/io/ooxml/parse-comments.ts +0 -846
  220. package/src/io/ooxml/parse-complex-content.ts +0 -287
  221. package/src/io/ooxml/parse-fields.ts +0 -834
  222. package/src/io/ooxml/parse-footnotes.ts +0 -896
  223. package/src/io/ooxml/parse-headers-footers.ts +0 -1169
  224. package/src/io/ooxml/parse-inline-media.ts +0 -461
  225. package/src/io/ooxml/parse-main-document.ts +0 -2877
  226. package/src/io/ooxml/parse-numbering.ts +0 -432
  227. package/src/io/ooxml/parse-revisions.ts +0 -931
  228. package/src/io/ooxml/parse-settings.ts +0 -184
  229. package/src/io/ooxml/parse-shapes.ts +0 -296
  230. package/src/io/ooxml/parse-styles.ts +0 -463
  231. package/src/io/ooxml/parse-tables.ts +0 -618
  232. package/src/io/ooxml/parse-theme.ts +0 -346
  233. package/src/io/ooxml/part-manifest.ts +0 -136
  234. package/src/io/ooxml/revision-boundaries.ts +0 -351
  235. package/src/io/opc/README.md +0 -3
  236. package/src/io/opc/corrupt-package.ts +0 -166
  237. package/src/io/opc/docx-package.ts +0 -74
  238. package/src/io/opc/package-reader.ts +0 -325
  239. package/src/io/opc/package-writer.ts +0 -273
  240. package/src/io/source-package-provenance.ts +0 -241
  241. package/src/legal/cross-references.ts +0 -414
  242. package/src/legal/defined-terms.ts +0 -203
  243. package/src/legal/index.ts +0 -32
  244. package/src/legal/signature-blocks.ts +0 -259
  245. package/src/model/README.md +0 -3
  246. package/src/model/canonical-document.ts +0 -2632
  247. package/src/model/cds-1.0.0.ts +0 -212
  248. package/src/model/snapshot.ts +0 -649
  249. package/src/preservation/README.md +0 -3
  250. package/src/preservation/markup-compatibility.ts +0 -48
  251. package/src/preservation/opaque-fragment-store.ts +0 -89
  252. package/src/preservation/opaque-region.ts +0 -233
  253. package/src/preservation/package-preservation.ts +0 -113
  254. package/src/preservation/preserved-part-manifest.ts +0 -56
  255. package/src/preservation/relationship-retention.ts +0 -57
  256. package/src/preservation/store.ts +0 -185
  257. package/src/review/README.md +0 -16
  258. package/src/review/store/README.md +0 -3
  259. package/src/review/store/comment-anchors.ts +0 -70
  260. package/src/review/store/comment-remapping.ts +0 -154
  261. package/src/review/store/comment-store.ts +0 -331
  262. package/src/review/store/comment-thread.ts +0 -109
  263. package/src/review/store/revision-actions.ts +0 -394
  264. package/src/review/store/revision-store.ts +0 -312
  265. package/src/review/store/revision-types.ts +0 -171
  266. package/src/review/store/runtime-comment-store.ts +0 -43
  267. package/src/runtime/README.md +0 -3
  268. package/src/runtime/ai-action-policy.ts +0 -764
  269. package/src/runtime/document-layout.ts +0 -332
  270. package/src/runtime/document-navigation.ts +0 -603
  271. package/src/runtime/document-runtime.ts +0 -3159
  272. package/src/runtime/document-search.ts +0 -145
  273. package/src/runtime/numbering-prefix.ts +0 -216
  274. package/src/runtime/page-layout-estimation.ts +0 -212
  275. package/src/runtime/read-only-diagnostics-runtime.ts +0 -241
  276. package/src/runtime/review-runtime.ts +0 -44
  277. package/src/runtime/revision-runtime.ts +0 -107
  278. package/src/runtime/session-capabilities.ts +0 -192
  279. package/src/runtime/story-context.ts +0 -164
  280. package/src/runtime/story-targeting.ts +0 -162
  281. package/src/runtime/surface-projection.ts +0 -1357
  282. package/src/runtime/table-commands.ts +0 -173
  283. package/src/runtime/table-schema.ts +0 -309
  284. package/src/runtime/view-state.ts +0 -477
  285. package/src/runtime/virtualized-rendering.ts +0 -258
  286. package/src/runtime/workflow-markup.ts +0 -353
  287. package/src/ui/README.md +0 -30
  288. package/src/ui/WordReviewEditor.tsx +0 -4086
  289. package/src/ui/browser-export.ts +0 -52
  290. package/src/ui/comments/README.md +0 -3
  291. package/src/ui/compatibility/README.md +0 -3
  292. package/src/ui/editor-command-bag.ts +0 -120
  293. package/src/ui/editor-runtime-boundary.ts +0 -1457
  294. package/src/ui/editor-shell-view.tsx +0 -142
  295. package/src/ui/editor-surface/README.md +0 -3
  296. package/src/ui/editor-surface-controller.tsx +0 -61
  297. package/src/ui/headless/comment-decoration-model.ts +0 -124
  298. package/src/ui/headless/preserve-editor-selection.ts +0 -5
  299. package/src/ui/headless/revision-decoration-model.ts +0 -128
  300. package/src/ui/headless/selection-helpers.ts +0 -54
  301. package/src/ui/headless/selection-toolbar-model.ts +0 -34
  302. package/src/ui/headless/use-editor-keyboard.ts +0 -103
  303. package/src/ui/review/README.md +0 -3
  304. package/src/ui/runtime-snapshot-selectors.ts +0 -197
  305. package/src/ui/shared/revision-filters.ts +0 -31
  306. package/src/ui/status/README.md +0 -3
  307. package/src/ui/theme/README.md +0 -3
  308. package/src/ui/toolbar/README.md +0 -3
  309. package/src/ui/workflow-surface-blocked-rails.ts +0 -94
  310. package/src/ui-tailwind/chrome/tw-alert-banner.tsx +0 -64
  311. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +0 -129
  312. package/src/ui-tailwind/chrome/tw-layout-panel.tsx +0 -114
  313. package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +0 -34
  314. package/src/ui-tailwind/chrome/tw-page-ruler.tsx +0 -386
  315. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +0 -186
  316. package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +0 -139
  317. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +0 -128
  318. package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +0 -58
  319. package/src/ui-tailwind/chrome/use-before-unload.ts +0 -20
  320. package/src/ui-tailwind/editor-surface/perf-probe.ts +0 -179
  321. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +0 -184
  322. package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +0 -31
  323. package/src/ui-tailwind/editor-surface/pm-decorations.ts +0 -427
  324. package/src/ui-tailwind/editor-surface/pm-position-map.ts +0 -123
  325. package/src/ui-tailwind/editor-surface/pm-schema.ts +0 -876
  326. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +0 -504
  327. package/src/ui-tailwind/editor-surface/search-plugin.ts +0 -168
  328. package/src/ui-tailwind/editor-surface/surface-build-keys.ts +0 -61
  329. package/src/ui-tailwind/editor-surface/tw-caret.tsx +0 -12
  330. package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +0 -150
  331. package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +0 -129
  332. package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +0 -58
  333. package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +0 -151
  334. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +0 -944
  335. package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +0 -111
  336. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +0 -436
  337. package/src/ui-tailwind/index.ts +0 -62
  338. package/src/ui-tailwind/page-chrome-model.ts +0 -27
  339. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +0 -406
  340. package/src/ui-tailwind/review/tw-health-panel.tsx +0 -149
  341. package/src/ui-tailwind/review/tw-review-rail.tsx +0 -120
  342. package/src/ui-tailwind/review/tw-revision-sidebar.tsx +0 -164
  343. package/src/ui-tailwind/status/tw-status-bar.tsx +0 -61
  344. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +0 -52
  345. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +0 -1064
  346. package/src/ui-tailwind/tw-review-workspace.tsx +0 -1417
  347. package/src/validation/README.md +0 -3
  348. package/src/validation/compatibility-engine.ts +0 -634
  349. package/src/validation/compatibility-report.ts +0 -161
  350. package/src/validation/diagnostics.ts +0 -204
  351. package/src/validation/docx-comment-proof.ts +0 -707
  352. package/src/validation/import-diagnostics.ts +0 -128
  353. package/src/validation/low-priority-word-surfaces.ts +0 -373
  354. /package/{src → dist}/ui-tailwind/theme/editor-theme.css +0 -0
@@ -1,892 +0,0 @@
1
- import {
2
- DEFAULT_BOUNDARY_ASSOC,
3
- createDetachedAnchor,
4
- createNodeAnchor,
5
- createRangeAnchor,
6
- type EditorAnchorProjection,
7
- } from "../selection/mapping.ts";
8
- import { isUuid } from "../../model/cds-1.0.0.ts";
9
- import {
10
- assertPersistedEditorSnapshot as assertModelPersistedEditorSnapshot,
11
- createPersistedEditorSnapshot as createModelPersistedEditorSnapshot,
12
- validatePersistedEditorSnapshot as validateModelPersistedEditorSnapshot,
13
- type ProtectionSnapshotRecord as ModelProtectionSnapshotRecord,
14
- type PersistedEditorSnapshot as ModelPersistedEditorSnapshot,
15
- } from "../../model/snapshot.ts";
16
- import {
17
- assertCanonicalDocument,
18
- type CanonicalDocument,
19
- type CommentEntry as ModelCommentEntry,
20
- type CommentResolution as ModelCommentResolution,
21
- type CommentThread as ModelCommentThread,
22
- type RevisionMetadataRecord as ModelRevisionMetadataRecord,
23
- type RevisionRecord as ModelRevisionRecord,
24
- } from "../../model/canonical-document.ts";
25
-
26
- export type RuntimePhase = "loading" | "ready" | "error";
27
- export type EditorWarningCode =
28
- | "unsupported_ooxml_preserved"
29
- | "unsupported_ooxml_locked"
30
- | "import_normalized"
31
- | "export_roundtrip_risk"
32
- | "comment_anchor_detached"
33
- | "revision_anchor_detached"
34
- | "large_document_degraded"
35
- | "font_substitution"
36
- | "image_missing";
37
-
38
- export interface EditorWarning {
39
- warningId: string;
40
- code: EditorWarningCode;
41
- severity: "info" | "warning";
42
- message: string;
43
- source:
44
- | "import"
45
- | "runtime"
46
- | "review"
47
- | "preservation"
48
- | "validation"
49
- | "export";
50
- affectedAnchor?: EditorAnchorProjection;
51
- featureEntryId?: string;
52
- details?: Record<string, unknown>;
53
- }
54
-
55
- export interface EditorError {
56
- errorId: string;
57
- code:
58
- | "import_failed"
59
- | "export_failed"
60
- | "package_corrupt"
61
- | "validation_failed"
62
- | "datastore_failed"
63
- | "internal_invariant";
64
- message: string;
65
- isFatal: boolean;
66
- source: "import" | "runtime" | "validation" | "datastore" | "host" | "export";
67
- details?: Record<string, unknown>;
68
- }
69
-
70
- export type CompatibilityFeatureClass =
71
- | "supported-roundtrip"
72
- | "preserve-only"
73
- | "unsupported-fatal";
74
-
75
- export interface CompatibilityFeatureEntry {
76
- featureEntryId: string;
77
- featureKey: string;
78
- featureClass: CompatibilityFeatureClass;
79
- message: string;
80
- affectedAnchor?: EditorAnchorProjection;
81
- details?: Record<string, unknown>;
82
- }
83
-
84
- export interface CompatibilityReport {
85
- reportVersion: "compatibility-report/1";
86
- generatedAt: string;
87
- blockExport: boolean;
88
- featureEntries: CompatibilityFeatureEntry[];
89
- warnings: EditorWarning[];
90
- errors: EditorError[];
91
- }
92
-
93
- export type CommentEntryRecord = ModelCommentEntry;
94
- export type CommentResolutionRecord = ModelCommentResolution;
95
- export type CommentThreadRecord = ModelCommentThread;
96
- export type RevisionMetadataRecord = ModelRevisionMetadataRecord;
97
- export type RevisionRecord = ModelRevisionRecord;
98
- export type ReviewStore = CanonicalDocument["review"];
99
- export type CanonicalDocumentEnvelope = CanonicalDocument;
100
-
101
- export interface SelectionSnapshot {
102
- anchor: number;
103
- head: number;
104
- isCollapsed: boolean;
105
- activeRange: EditorAnchorProjection;
106
- }
107
-
108
- export interface DocumentStats {
109
- paragraphCount: number;
110
- wordCount: number;
111
- characterCount: number;
112
- commentCount: number;
113
- revisionCount: number;
114
- }
115
-
116
- export interface CommentSidebarSnapshot {
117
- activeCommentId?: string;
118
- openThreadCount: number;
119
- resolvedThreadCount: number;
120
- threads: CommentThreadRecord[];
121
- }
122
-
123
- export interface TrackedChangesSnapshot {
124
- totalCount: number;
125
- pendingCount: number;
126
- acceptedCount: number;
127
- rejectedCount: number;
128
- }
129
-
130
- export interface CompatibilityPanelSnapshot {
131
- report: CompatibilityReport;
132
- blockExport: boolean;
133
- totalEntries: number;
134
- }
135
-
136
- export interface CommandStateSnapshot {
137
- canUndo: boolean;
138
- canRedo: boolean;
139
- canAddComment: boolean;
140
- canAcceptAllChanges: boolean;
141
- canRejectAllChanges: boolean;
142
- }
143
-
144
- export interface RuntimeRenderSnapshot {
145
- documentId: string;
146
- sessionId: string;
147
- sourceLabel?: string;
148
- revisionToken: string;
149
- isReady: boolean;
150
- isDirty: boolean;
151
- readOnly: boolean;
152
- selection: SelectionSnapshot;
153
- documentStats: DocumentStats;
154
- comments: CommentSidebarSnapshot;
155
- trackedChanges: TrackedChangesSnapshot;
156
- compatibility: CompatibilityPanelSnapshot;
157
- warnings: EditorWarning[];
158
- fatalError?: EditorError;
159
- commandState: CommandStateSnapshot;
160
- }
161
-
162
- export interface PersistedEditorSnapshot
163
- extends Omit<
164
- ModelPersistedEditorSnapshot,
165
- "canonicalDocument" | "compatibility" | "warningLog"
166
- > {
167
- canonicalDocument: CanonicalDocumentEnvelope;
168
- compatibility: CompatibilityReport;
169
- warningLog: EditorWarning[];
170
- }
171
-
172
- export interface EditorRuntimeState {
173
- hasFocus: boolean;
174
- activeCommentId?: string;
175
- }
176
-
177
- export interface EditorState {
178
- phase: RuntimePhase;
179
- documentId: string;
180
- sessionId: string;
181
- sourceLabel?: string;
182
- sourcePackage?: ModelPersistedEditorSnapshot["sourcePackage"];
183
- revision: number;
184
- revisionToken: string;
185
- isDirty: boolean;
186
- readOnly: boolean;
187
- document: CanonicalDocumentEnvelope;
188
- selection: SelectionSnapshot;
189
- warnings: EditorWarning[];
190
- compatibility: CompatibilityReport;
191
- fatalError?: EditorError;
192
- runtime: EditorRuntimeState;
193
- }
194
-
195
- export interface CreateEditorStateOptions {
196
- documentId: string;
197
- sessionId: string;
198
- sourceLabel?: string;
199
- readOnly?: boolean;
200
- canonicalDocument?: CanonicalDocumentEnvelope;
201
- persistedSnapshot?: PersistedEditorSnapshot;
202
- compatibility?: CompatibilityReport;
203
- warnings?: EditorWarning[];
204
- fatalError?: EditorError;
205
- }
206
-
207
- export function createEmptyReviewStore(): ReviewStore {
208
- return {
209
- comments: {},
210
- revisions: {},
211
- };
212
- }
213
-
214
- export function createDefaultCanonicalDocument(
215
- documentId: string,
216
- timestamp: string,
217
- ): CanonicalDocumentEnvelope {
218
- return {
219
- schemaVersion: "cds/1.0.0",
220
- docId: createCanonicalDocumentId(documentId),
221
- createdAt: timestamp,
222
- updatedAt: timestamp,
223
- metadata: {
224
- customProperties: {},
225
- },
226
- styles: {
227
- paragraphs: {},
228
- characters: {},
229
- tables: {},
230
- },
231
- numbering: {
232
- abstractDefinitions: {},
233
- instances: {},
234
- },
235
- media: {
236
- items: {},
237
- },
238
- content: {
239
- type: "doc",
240
- children: [{ type: "paragraph", children: [] }],
241
- },
242
- review: createEmptyReviewStore(),
243
- preservation: {
244
- opaqueFragments: {},
245
- packageParts: {},
246
- },
247
- diagnostics: {
248
- warnings: [],
249
- errors: [],
250
- },
251
- };
252
- }
253
-
254
- export function createSelectionSnapshot(anchor = 0, head = anchor): SelectionSnapshot {
255
- return {
256
- anchor,
257
- head,
258
- isCollapsed: anchor === head,
259
- activeRange: createRangeAnchor(anchor, head, DEFAULT_BOUNDARY_ASSOC),
260
- };
261
- }
262
-
263
- export function createEmptyCompatibilityReport(generatedAt: string): CompatibilityReport {
264
- return {
265
- reportVersion: "compatibility-report/1",
266
- generatedAt,
267
- blockExport: false,
268
- featureEntries: [],
269
- warnings: [],
270
- errors: [],
271
- };
272
- }
273
-
274
- export function createEditorState(options: CreateEditorStateOptions): EditorState {
275
- const timestamp = new Date(0).toISOString();
276
- const normalizedSnapshot = options.persistedSnapshot
277
- ? normalizePersistedSnapshotForRuntime(options.persistedSnapshot, options.documentId, timestamp)
278
- : undefined;
279
- if (options.canonicalDocument) {
280
- assertCanonicalDocument(options.canonicalDocument as unknown);
281
- }
282
-
283
- const normalizedDocument = normalizedSnapshot
284
- ? structuredClone(normalizedSnapshot.canonicalDocument)
285
- : options.canonicalDocument
286
- ? structuredClone(options.canonicalDocument)
287
- : createDefaultCanonicalDocument(options.documentId, timestamp);
288
- const warnings = normalizedSnapshot
289
- ? normalizeWarningLog(normalizedSnapshot.warningLog)
290
- : options.warnings ?? [];
291
- const compatibility =
292
- normalizedSnapshot
293
- ? normalizeCompatibilityReport(normalizedSnapshot.compatibility)
294
- : options.compatibility ?? createEmptyCompatibilityReport(normalizedDocument.updatedAt);
295
-
296
- return {
297
- phase: options.fatalError ? "error" : "ready",
298
- documentId: options.documentId,
299
- sessionId: options.sessionId,
300
- sourceLabel: options.sourceLabel,
301
- sourcePackage: normalizedSnapshot?.sourcePackage,
302
- revision: 0,
303
- revisionToken: `${options.sessionId}:0`,
304
- isDirty: false,
305
- readOnly: options.readOnly ?? false,
306
- document: normalizedDocument,
307
- selection: createSelectionSnapshot(),
308
- warnings,
309
- compatibility,
310
- fatalError: options.fatalError,
311
- runtime: {
312
- hasFocus: false,
313
- },
314
- };
315
- }
316
-
317
- function normalizePersistedSnapshotForRuntime(
318
- snapshot: PersistedEditorSnapshot,
319
- documentId: string,
320
- timestamp: string,
321
- ): PersistedEditorSnapshot {
322
- const issues = validateModelPersistedEditorSnapshot(snapshot as unknown);
323
- if (issues.length === 0) {
324
- return snapshot;
325
- }
326
-
327
- if (!isRecord(snapshot) || !isRecord(snapshot.canonicalDocument)) {
328
- assertModelPersistedEditorSnapshot(snapshot as unknown);
329
- }
330
-
331
- const normalizedDocument = normalizeCanonicalDocumentEnvelope(
332
- snapshot.canonicalDocument,
333
- documentId,
334
- timestamp,
335
- );
336
- try {
337
- assertCanonicalDocument(normalizedDocument as unknown);
338
- } catch {
339
- assertModelPersistedEditorSnapshot(snapshot as unknown);
340
- }
341
- const repairWarning = createSnapshotRepairWarning(issues.length);
342
- const compatibility = coerceCompatibilityReport(
343
- snapshot.compatibility,
344
- normalizedDocument.updatedAt,
345
- repairWarning,
346
- );
347
-
348
- return {
349
- snapshotVersion:
350
- snapshot.snapshotVersion === "persisted-editor-snapshot/1" ||
351
- snapshot.snapshotVersion === "persisted-editor-snapshot/2"
352
- ? snapshot.snapshotVersion
353
- : "persisted-editor-snapshot/2",
354
- schemaVersion: "cds/1.0.0",
355
- documentId:
356
- typeof snapshot.documentId === "string" && snapshot.documentId.length > 0
357
- ? snapshot.documentId
358
- : documentId,
359
- docId: normalizedDocument.docId,
360
- createdAt: normalizedDocument.createdAt,
361
- updatedAt: normalizedDocument.updatedAt,
362
- savedAt:
363
- typeof snapshot.savedAt === "string" && snapshot.savedAt.length > 0
364
- ? snapshot.savedAt
365
- : normalizedDocument.updatedAt,
366
- editorBuild:
367
- typeof snapshot.editorBuild === "string" && snapshot.editorBuild.length > 0
368
- ? snapshot.editorBuild
369
- : "dev",
370
- canonicalDocument: normalizedDocument,
371
- compatibility,
372
- warningLog: dedupeWarnings([
373
- ...coerceWarnings(snapshot.warningLog),
374
- repairWarning,
375
- ]),
376
- sourcePackage: snapshot.sourcePackage,
377
- };
378
- }
379
-
380
- function normalizeCanonicalDocumentEnvelope(
381
- value: unknown,
382
- documentId: string,
383
- timestamp: string,
384
- ): CanonicalDocumentEnvelope {
385
- const base = createDefaultCanonicalDocument(documentId, timestamp);
386
- const record = isRecord(value) ? value : {};
387
- const metadata = isRecord(record.metadata) ? record.metadata : {};
388
-
389
- return {
390
- ...base,
391
- ...record,
392
- schemaVersion: "cds/1.0.0",
393
- docId: isUuid(record.docId) ? record.docId : createCanonicalDocumentId(documentId),
394
- createdAt:
395
- typeof record.createdAt === "string" && record.createdAt.length > 0
396
- ? record.createdAt
397
- : base.createdAt,
398
- updatedAt:
399
- typeof record.updatedAt === "string" && record.updatedAt.length > 0
400
- ? record.updatedAt
401
- : base.updatedAt,
402
- metadata: {
403
- ...base.metadata,
404
- ...metadata,
405
- customProperties: isRecord(metadata.customProperties)
406
- ? (Object.fromEntries(
407
- Object.entries(metadata.customProperties).filter(([, entry]) => typeof entry === "string"),
408
- ) as Record<string, string>)
409
- : {},
410
- },
411
- styles:
412
- record.styles === undefined
413
- ? base.styles
414
- : (record.styles as CanonicalDocumentEnvelope["styles"]),
415
- numbering:
416
- record.numbering === undefined
417
- ? base.numbering
418
- : (record.numbering as CanonicalDocumentEnvelope["numbering"]),
419
- media:
420
- record.media === undefined
421
- ? base.media
422
- : (record.media as CanonicalDocumentEnvelope["media"]),
423
- content: isRecord(record.content)
424
- ? (record.content as unknown as CanonicalDocumentEnvelope["content"])
425
- : base.content,
426
- review:
427
- record.review === undefined
428
- ? base.review
429
- : (record.review as CanonicalDocumentEnvelope["review"]),
430
- preservation:
431
- record.preservation === undefined
432
- ? base.preservation
433
- : (record.preservation as CanonicalDocumentEnvelope["preservation"]),
434
- diagnostics:
435
- record.diagnostics === undefined
436
- ? base.diagnostics
437
- : (record.diagnostics as CanonicalDocumentEnvelope["diagnostics"]),
438
- ...(isRecord(record.subParts)
439
- ? { subParts: record.subParts as unknown as CanonicalDocumentEnvelope["subParts"] }
440
- : {}),
441
- };
442
- }
443
-
444
- function coerceCompatibilityReport(
445
- value: unknown,
446
- generatedAt: string,
447
- repairWarning: EditorWarning,
448
- ): CompatibilityReport {
449
- const record = isRecord(value) ? value : {};
450
- const warnings = dedupeWarnings([
451
- ...coerceWarnings(record.warnings),
452
- repairWarning,
453
- ]);
454
-
455
- return {
456
- reportVersion: "compatibility-report/1",
457
- generatedAt:
458
- typeof record.generatedAt === "string" && record.generatedAt.length > 0
459
- ? record.generatedAt
460
- : generatedAt,
461
- blockExport: typeof record.blockExport === "boolean" ? record.blockExport : false,
462
- featureEntries: Array.isArray(record.featureEntries)
463
- ? record.featureEntries.flatMap((entry) => {
464
- if (!isRecord(entry)) {
465
- return [];
466
- }
467
- if (
468
- typeof entry.featureEntryId !== "string" ||
469
- typeof entry.featureKey !== "string" ||
470
- typeof entry.featureClass !== "string" ||
471
- typeof entry.message !== "string"
472
- ) {
473
- return [];
474
- }
475
- return [{
476
- featureEntryId: entry.featureEntryId,
477
- featureKey: entry.featureKey,
478
- featureClass: entry.featureClass as CompatibilityFeatureEntry["featureClass"],
479
- message: entry.message,
480
- ...(entry.affectedAnchor && isRecord(entry.affectedAnchor)
481
- ? { affectedAnchor: entry.affectedAnchor as unknown as EditorAnchorProjection }
482
- : {}),
483
- ...(isRecord(entry.details) ? { details: entry.details } : {}),
484
- }];
485
- })
486
- : [],
487
- warnings,
488
- errors: Array.isArray(record.errors)
489
- ? record.errors.flatMap((entry) => {
490
- if (!isRecord(entry)) {
491
- return [];
492
- }
493
- if (
494
- typeof entry.errorId !== "string" ||
495
- typeof entry.code !== "string" ||
496
- typeof entry.message !== "string" ||
497
- typeof entry.source !== "string" ||
498
- typeof entry.isFatal !== "boolean"
499
- ) {
500
- return [];
501
- }
502
- return [{
503
- errorId: entry.errorId,
504
- code: entry.code as EditorError["code"],
505
- message: entry.message,
506
- source: entry.source as EditorError["source"],
507
- isFatal: entry.isFatal,
508
- ...(isRecord(entry.details) ? { details: entry.details } : {}),
509
- }];
510
- })
511
- : [],
512
- };
513
- }
514
-
515
- function coerceWarnings(value: unknown): EditorWarning[] {
516
- if (!Array.isArray(value)) {
517
- return [];
518
- }
519
-
520
- return value.flatMap((warning) => {
521
- if (!isRecord(warning)) {
522
- return [];
523
- }
524
- if (
525
- typeof warning.warningId !== "string" ||
526
- typeof warning.code !== "string" ||
527
- typeof warning.severity !== "string" ||
528
- typeof warning.message !== "string" ||
529
- typeof warning.source !== "string"
530
- ) {
531
- return [];
532
- }
533
-
534
- return [{
535
- warningId: warning.warningId,
536
- code: warning.code as EditorWarning["code"],
537
- severity: warning.severity as EditorWarning["severity"],
538
- message: warning.message,
539
- source: warning.source as EditorWarning["source"],
540
- ...(warning.affectedAnchor && isRecord(warning.affectedAnchor)
541
- ? { affectedAnchor: warning.affectedAnchor as unknown as EditorAnchorProjection }
542
- : {}),
543
- ...(typeof warning.featureEntryId === "string"
544
- ? { featureEntryId: warning.featureEntryId }
545
- : {}),
546
- ...(isRecord(warning.details) ? { details: warning.details } : {}),
547
- }];
548
- });
549
- }
550
-
551
- function createSnapshotRepairWarning(issueCount: number): EditorWarning {
552
- return {
553
- warningId: `warning:snapshot-repair:${issueCount}`,
554
- code: "import_normalized",
555
- severity: "warning",
556
- message: `Loaded a persisted snapshot after repairing ${issueCount} validation issue${issueCount === 1 ? "" : "s"}.`,
557
- source: "validation",
558
- };
559
- }
560
-
561
- function dedupeWarnings(warnings: EditorWarning[]): EditorWarning[] {
562
- const seen = new Set<string>();
563
- const result: EditorWarning[] = [];
564
-
565
- for (const warning of warnings) {
566
- if (!warning.warningId || seen.has(warning.warningId)) {
567
- continue;
568
- }
569
- seen.add(warning.warningId);
570
- result.push(warning);
571
- }
572
-
573
- return result;
574
- }
575
-
576
- export function deriveDocumentStats(state: Pick<EditorState, "document">): DocumentStats {
577
- const serializedContent = extractText(state.document.content);
578
-
579
- return {
580
- paragraphCount: estimateParagraphCount(state.document.content),
581
- wordCount: serializedContent.trim().length === 0 ? 0 : serializedContent.trim().split(/\s+/u).length,
582
- characterCount: Array.from(serializedContent).length,
583
- commentCount: Object.keys(state.document.review.comments).length,
584
- revisionCount: Object.keys(state.document.review.revisions).length,
585
- };
586
- }
587
-
588
- export function deriveRenderSnapshot(
589
- state: EditorState,
590
- history: { canUndo: boolean; canRedo: boolean },
591
- ): RuntimeRenderSnapshot {
592
- const comments = Object.values(state.document.review.comments).sort((left, right) =>
593
- left.createdAt.localeCompare(right.createdAt),
594
- );
595
- const revisions = Object.values(state.document.review.revisions);
596
-
597
- return {
598
- documentId: state.documentId,
599
- sessionId: state.sessionId,
600
- sourceLabel: state.sourceLabel,
601
- revisionToken: state.revisionToken,
602
- isReady: state.phase === "ready",
603
- isDirty: state.isDirty,
604
- readOnly: state.readOnly,
605
- selection: state.selection,
606
- documentStats: deriveDocumentStats(state),
607
- comments: {
608
- activeCommentId: state.runtime.activeCommentId,
609
- openThreadCount: comments.filter((comment) => comment.status === "open").length,
610
- resolvedThreadCount: comments.filter((comment) => comment.status === "resolved").length,
611
- threads: comments,
612
- },
613
- trackedChanges: {
614
- totalCount: revisions.length,
615
- pendingCount: revisions.filter((revision) => revision.status === "open").length,
616
- acceptedCount: revisions.filter((revision) => revision.status === "accepted").length,
617
- rejectedCount: revisions.filter((revision) => revision.status === "rejected").length,
618
- },
619
- compatibility: {
620
- report: state.compatibility,
621
- blockExport: state.compatibility.blockExport,
622
- totalEntries: state.compatibility.featureEntries.length,
623
- },
624
- warnings: state.warnings,
625
- fatalError: state.fatalError,
626
- commandState: {
627
- canUndo: history.canUndo,
628
- canRedo: history.canRedo,
629
- canAddComment: !state.readOnly,
630
- canAcceptAllChanges: revisions.some((revision) => revision.status === "open"),
631
- canRejectAllChanges: revisions.some((revision) => revision.status === "open"),
632
- },
633
- };
634
- }
635
-
636
- export function createPersistedEditorSnapshot(
637
- state: EditorState,
638
- options: {
639
- editorBuild: string;
640
- savedAt: string;
641
- compatibility?: CompatibilityReport;
642
- protectionSnapshot?: ModelProtectionSnapshotRecord;
643
- },
644
- ): PersistedEditorSnapshot {
645
- const snapshot = createModelPersistedEditorSnapshot({
646
- documentId: state.documentId,
647
- savedAt: options.savedAt,
648
- editorBuild: options.editorBuild,
649
- canonicalDocument: state.document,
650
- compatibility: (options.compatibility ?? state.compatibility) as never,
651
- warningLog: state.warnings as never,
652
- protectionSnapshot: options.protectionSnapshot,
653
- sourcePackage: state.sourcePackage,
654
- });
655
- return snapshot as PersistedEditorSnapshot;
656
- }
657
-
658
- function estimateParagraphCount(content: unknown): number {
659
- if (Array.isArray(content)) {
660
- return content.length;
661
- }
662
-
663
- if (content && typeof content === "object" && Array.isArray((content as { blocks?: unknown[] }).blocks)) {
664
- return ((content as { blocks: unknown[] }).blocks).length;
665
- }
666
-
667
- return extractText(content).length > 0 ? 1 : 0;
668
- }
669
-
670
- function normalizeWarningLog(warnings: EditorWarning[]): EditorWarning[] {
671
- return warnings.map((warning) => ({
672
- ...warning,
673
- affectedAnchor: warning.affectedAnchor
674
- ? normalizeAnchorProjection(warning.affectedAnchor)
675
- : undefined,
676
- }));
677
- }
678
-
679
- function normalizeCompatibilityReport(report: CompatibilityReport): CompatibilityReport {
680
- return {
681
- ...report,
682
- featureEntries: report.featureEntries.map((entry) => ({
683
- ...entry,
684
- affectedAnchor: entry.affectedAnchor
685
- ? normalizeAnchorProjection(entry.affectedAnchor)
686
- : undefined,
687
- })),
688
- warnings: normalizeWarningLog(report.warnings),
689
- };
690
- }
691
-
692
- function normalizeAnchorProjection(anchor: EditorAnchorProjection): EditorAnchorProjection {
693
- switch (anchor.kind) {
694
- case "range": {
695
- const rangeAnchor = anchor as EditorAnchorProjection & {
696
- range?: { from: number; to: number };
697
- from?: number;
698
- to?: number;
699
- assoc: { start: -1 | 1; end: -1 | 1 };
700
- };
701
- return rangeAnchor.range
702
- ? createRangeAnchor(rangeAnchor.range.from, rangeAnchor.range.to, rangeAnchor.assoc)
703
- : createRangeAnchor(rangeAnchor.from ?? 0, rangeAnchor.to ?? 0, rangeAnchor.assoc);
704
- }
705
- case "node":
706
- return createNodeAnchor(anchor.at, anchor.assoc);
707
- case "detached":
708
- return createDetachedAnchor(anchor.lastKnownRange, anchor.reason);
709
- }
710
- }
711
-
712
- function extractText(value: unknown): string {
713
- if (typeof value === "string") {
714
- return value;
715
- }
716
-
717
- if (Array.isArray(value)) {
718
- return value.map((item) => extractText(item)).join(" ");
719
- }
720
-
721
- if (!value || typeof value !== "object") {
722
- return "";
723
- }
724
-
725
- return Object.values(value as Record<string, unknown>)
726
- .map((item) => extractText(item))
727
- .filter(Boolean)
728
- .join(" ");
729
- }
730
-
731
- function isRecord(value: unknown): value is Record<string, unknown> {
732
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
733
- }
734
-
735
- export function createCanonicalDocumentId(documentId: string): string {
736
- const hashWord = (seed: string): string => {
737
- let hash = 0x811c9dc5;
738
- for (const char of seed) {
739
- hash ^= char.charCodeAt(0);
740
- hash = Math.imul(hash, 0x01000193);
741
- }
742
- return (hash >>> 0).toString(16).padStart(8, "0");
743
- };
744
-
745
- const raw =
746
- hashWord(`${documentId}:0`) +
747
- hashWord(`${documentId}:1`) +
748
- hashWord(`${documentId}:2`) +
749
- hashWord(`${documentId}:3`);
750
-
751
- return [
752
- raw.slice(0, 8),
753
- raw.slice(8, 12),
754
- `4${raw.slice(13, 16)}`,
755
- `8${raw.slice(17, 20)}`,
756
- raw.slice(20, 32),
757
- ].join("-");
758
- }
759
-
760
- export function normalizeCommentThreadRecord(value: unknown): CommentThreadRecord {
761
- const record = isRecord(value) ? value : {};
762
- const authorId =
763
- typeof record.createdBy === "string" && record.createdBy.length > 0
764
- ? record.createdBy
765
- : typeof record.authorId === "string" && record.authorId.length > 0
766
- ? record.authorId
767
- : "unknown";
768
- const createdAt =
769
- typeof record.createdAt === "string" && record.createdAt.length > 0
770
- ? record.createdAt
771
- : new Date(0).toISOString();
772
- const entries = Array.isArray(record.entries)
773
- ? record.entries
774
- .filter((entry): entry is Record<string, unknown> => isRecord(entry))
775
- .map((entry, index) => ({
776
- entryId:
777
- typeof entry.entryId === "string" && entry.entryId.length > 0
778
- ? entry.entryId
779
- : `${String(record.commentId ?? "comment")}-entry-${index + 1}`,
780
- authorId:
781
- typeof entry.authorId === "string" && entry.authorId.length > 0
782
- ? entry.authorId
783
- : authorId,
784
- body: typeof entry.body === "string" ? entry.body : "",
785
- createdAt:
786
- typeof entry.createdAt === "string" && entry.createdAt.length > 0
787
- ? entry.createdAt
788
- : createdAt,
789
- metadata: isRecord(entry.metadata)
790
- ? {
791
- ooxmlCommentId:
792
- typeof entry.metadata.ooxmlCommentId === "string"
793
- ? entry.metadata.ooxmlCommentId
794
- : undefined,
795
- paraId:
796
- typeof entry.metadata.paraId === "string"
797
- ? entry.metadata.paraId
798
- : undefined,
799
- parentParaId:
800
- typeof entry.metadata.parentParaId === "string"
801
- ? entry.metadata.parentParaId
802
- : undefined,
803
- durableId:
804
- typeof entry.metadata.durableId === "string"
805
- ? entry.metadata.durableId
806
- : undefined,
807
- initials:
808
- typeof entry.metadata.initials === "string"
809
- ? entry.metadata.initials
810
- : undefined,
811
- }
812
- : undefined,
813
- }))
814
- : [
815
- {
816
- entryId: `${String(record.commentId ?? "comment")}-entry-1`,
817
- authorId,
818
- body: typeof record.body === "string" ? record.body : "",
819
- createdAt,
820
- },
821
- ];
822
- const resolution = isRecord(record.resolution)
823
- ? {
824
- resolvedAt:
825
- typeof record.resolution.resolvedAt === "string"
826
- ? record.resolution.resolvedAt
827
- : typeof record.resolvedAt === "string"
828
- ? record.resolvedAt
829
- : createdAt,
830
- resolvedBy:
831
- typeof record.resolution.resolvedBy === "string" &&
832
- record.resolution.resolvedBy.length > 0
833
- ? record.resolution.resolvedBy
834
- : authorId,
835
- }
836
- : typeof record.resolvedAt === "string"
837
- ? {
838
- resolvedAt: record.resolvedAt,
839
- resolvedBy: authorId,
840
- }
841
- : undefined;
842
- const normalizedStatus =
843
- typeof record.status === "string"
844
- ? record.status
845
- : record.anchor && isRecord(record.anchor) && record.anchor.kind === "detached"
846
- ? "detached"
847
- : resolution || record.isResolved
848
- ? "resolved"
849
- : "open";
850
-
851
- return {
852
- commentId:
853
- typeof record.commentId === "string" && record.commentId.length > 0
854
- ? record.commentId
855
- : "comment-generated",
856
- anchor:
857
- isRecord(record.anchor) && typeof record.anchor.kind === "string"
858
- ? (record.anchor as unknown as EditorAnchorProjection)
859
- : createDetachedAnchor({ from: 0, to: 0 }, "importAmbiguity"),
860
- createdAt,
861
- createdBy: authorId,
862
- authorId,
863
- body: entries.map((entry) => entry.body).join("\n"),
864
- entries,
865
- status:
866
- normalizedStatus === "resolved" || normalizedStatus === "detached"
867
- ? normalizedStatus
868
- : "open",
869
- resolution,
870
- resolvedAt: resolution?.resolvedAt,
871
- warningIds: Array.isArray(record.warningIds)
872
- ? record.warningIds.filter((warningId): warningId is string => typeof warningId === "string")
873
- : [],
874
- isResolved: normalizedStatus === "resolved",
875
- metadata: isRecord(record.metadata)
876
- ? {
877
- source:
878
- record.metadata.source === "import" || record.metadata.source === "runtime"
879
- ? record.metadata.source
880
- : undefined,
881
- rootOoxmlCommentId:
882
- typeof record.metadata.rootOoxmlCommentId === "string"
883
- ? record.metadata.rootOoxmlCommentId
884
- : undefined,
885
- rootParaId:
886
- typeof record.metadata.rootParaId === "string"
887
- ? record.metadata.rootParaId
888
- : undefined,
889
- }
890
- : undefined,
891
- };
892
- }