@beyondwork/docx-react-component 1.0.29 → 1.0.30

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 (381) hide show
  1. package/package.json +65 -96
  2. package/src/README.md +85 -0
  3. package/src/api/README.md +26 -0
  4. package/src/api/public-types.ts +1952 -0
  5. package/src/api/session-state.ts +62 -0
  6. package/src/compare/diff-engine.ts +623 -0
  7. package/src/compare/export-redlines.ts +280 -0
  8. package/src/compare/index.ts +25 -0
  9. package/src/compare/snapshot.ts +97 -0
  10. package/src/component-inventory.md +99 -0
  11. package/src/core/README.md +10 -0
  12. package/src/core/commands/README.md +3 -0
  13. package/{dist/chunk-TJBP2K4T.js → src/core/commands/formatting-commands.ts} +536 -196
  14. package/src/core/commands/image-commands.ts +373 -0
  15. package/src/core/commands/index.ts +1879 -0
  16. package/src/core/commands/list-commands.ts +565 -0
  17. package/src/core/commands/paragraph-layout-commands.ts +339 -0
  18. package/src/core/commands/review-commands.ts +108 -0
  19. package/{dist/core/commands/section-layout-commands.cjs → src/core/commands/section-layout-commands.ts} +340 -137
  20. package/src/core/commands/structural-helpers.ts +309 -0
  21. package/{dist/core/commands/style-commands.cjs → src/core/commands/style-commands.ts} +113 -65
  22. package/src/core/commands/table-structure-commands.ts +854 -0
  23. package/{dist/chunk-UZXBISGO.js → src/core/commands/text-commands.ts} +142 -86
  24. package/src/core/schema/README.md +3 -0
  25. package/src/core/schema/text-schema.ts +516 -0
  26. package/src/core/search/search-text.ts +357 -0
  27. package/src/core/selection/README.md +3 -0
  28. package/src/core/selection/mapping.ts +289 -0
  29. package/src/core/selection/review-anchors.ts +183 -0
  30. package/src/core/state/README.md +3 -0
  31. package/src/core/state/editor-state.ts +892 -0
  32. package/src/core/state/text-transaction.ts +869 -0
  33. package/src/formats/xlsx/io/parse-shared-strings.ts +41 -0
  34. package/src/formats/xlsx/io/parse-sheet.ts +459 -0
  35. package/src/formats/xlsx/io/parse-styles.ts +59 -0
  36. package/src/formats/xlsx/io/parse-workbook.ts +75 -0
  37. package/src/formats/xlsx/io/serialize-shared-strings.ts +72 -0
  38. package/src/formats/xlsx/io/serialize-sheet.ts +333 -0
  39. package/src/formats/xlsx/io/serialize-styles.ts +98 -0
  40. package/src/formats/xlsx/io/serialize-workbook.ts +429 -0
  41. package/src/formats/xlsx/io/xlsx-session.ts +314 -0
  42. package/src/formats/xlsx/model/cell.ts +189 -0
  43. package/src/formats/xlsx/model/sheet.ts +326 -0
  44. package/src/formats/xlsx/model/styles.ts +118 -0
  45. package/src/formats/xlsx/model/workbook.ts +453 -0
  46. package/src/formats/xlsx/runtime/cell-commands.ts +567 -0
  47. package/src/formats/xlsx/runtime/sheet-commands.ts +206 -0
  48. package/src/formats/xlsx/runtime/workbook-runtime.ts +177 -0
  49. package/src/formats/xlsx/runtime/workbook-transaction.ts +822 -0
  50. package/src/index.ts +142 -0
  51. package/src/io/README.md +10 -0
  52. package/src/io/docx-session.ts +3175 -0
  53. package/src/io/export/README.md +3 -0
  54. package/src/io/export/export-session.ts +220 -0
  55. package/src/io/export/minimal-docx.ts +115 -0
  56. package/src/io/export/reattach-preserved-parts.ts +54 -0
  57. package/src/io/export/serialize-comments.ts +947 -0
  58. package/src/io/export/serialize-footnotes.ts +394 -0
  59. package/src/io/export/serialize-headers-footers.ts +368 -0
  60. package/src/io/export/serialize-main-document.ts +1342 -0
  61. package/src/io/export/serialize-numbering.ts +218 -0
  62. package/src/io/export/serialize-revisions.ts +389 -0
  63. package/src/io/export/serialize-runtime-revisions.ts +463 -0
  64. package/src/io/export/serialize-tables.ts +174 -0
  65. package/src/io/export/split-review-boundaries.ts +356 -0
  66. package/src/io/export/split-story-blocks-for-runtime-revisions.ts +252 -0
  67. package/src/io/export/table-properties-xml.ts +318 -0
  68. package/src/io/normalize/README.md +3 -0
  69. package/src/io/normalize/normalize-text.ts +670 -0
  70. package/src/io/ooxml/README.md +3 -0
  71. package/src/io/ooxml/highlight-colors.ts +39 -0
  72. package/src/io/ooxml/numbering-sentinels.ts +44 -0
  73. package/src/io/ooxml/parse-comments.ts +852 -0
  74. package/src/io/ooxml/parse-complex-content.ts +287 -0
  75. package/src/io/ooxml/parse-fields.ts +834 -0
  76. package/src/io/ooxml/parse-footnotes.ts +952 -0
  77. package/src/io/ooxml/parse-headers-footers.ts +1212 -0
  78. package/src/io/ooxml/parse-inline-media.ts +461 -0
  79. package/src/io/ooxml/parse-main-document.ts +2947 -0
  80. package/src/io/ooxml/parse-numbering.ts +747 -0
  81. package/src/io/ooxml/parse-revisions.ts +1045 -0
  82. package/src/io/ooxml/parse-settings.ts +184 -0
  83. package/src/io/ooxml/parse-shapes.ts +296 -0
  84. package/src/io/ooxml/parse-styles.ts +639 -0
  85. package/src/io/ooxml/parse-tables.ts +627 -0
  86. package/src/io/ooxml/parse-theme.ts +346 -0
  87. package/src/io/ooxml/part-manifest.ts +136 -0
  88. package/src/io/ooxml/revision-boundaries.ts +475 -0
  89. package/src/io/ooxml/workflow-payload.ts +544 -0
  90. package/src/io/opc/README.md +3 -0
  91. package/src/io/opc/corrupt-package.ts +166 -0
  92. package/src/io/opc/docx-package.ts +74 -0
  93. package/src/io/opc/package-reader.ts +325 -0
  94. package/src/io/opc/package-writer.ts +273 -0
  95. package/src/io/source-package-provenance.ts +241 -0
  96. package/{dist/chunk-RMH72RZI.js → src/legal/bookmarks.ts} +130 -44
  97. package/src/legal/cross-references.ts +414 -0
  98. package/src/legal/defined-terms.ts +203 -0
  99. package/src/legal/index.ts +32 -0
  100. package/src/legal/signature-blocks.ts +259 -0
  101. package/src/model/README.md +3 -0
  102. package/src/model/canonical-document.ts +2722 -0
  103. package/src/model/cds-1.0.0.ts +212 -0
  104. package/src/model/snapshot.ts +760 -0
  105. package/src/preservation/README.md +3 -0
  106. package/src/preservation/markup-compatibility.ts +48 -0
  107. package/src/preservation/opaque-fragment-store.ts +89 -0
  108. package/src/preservation/opaque-region.ts +233 -0
  109. package/src/preservation/package-preservation.ts +113 -0
  110. package/src/preservation/preserved-part-manifest.ts +56 -0
  111. package/src/preservation/relationship-retention.ts +57 -0
  112. package/src/preservation/store.ts +255 -0
  113. package/src/review/README.md +16 -0
  114. package/src/review/store/README.md +3 -0
  115. package/src/review/store/comment-anchors.ts +70 -0
  116. package/src/review/store/comment-remapping.ts +154 -0
  117. package/src/review/store/comment-store.ts +349 -0
  118. package/src/review/store/comment-thread.ts +109 -0
  119. package/src/review/store/revision-actions.ts +423 -0
  120. package/src/review/store/revision-store.ts +323 -0
  121. package/src/review/store/revision-types.ts +182 -0
  122. package/src/review/store/runtime-comment-store.ts +43 -0
  123. package/src/runtime/README.md +3 -0
  124. package/src/runtime/ai-action-policy.ts +764 -0
  125. package/src/runtime/context-analytics.ts +824 -0
  126. package/src/runtime/document-layout.ts +332 -0
  127. package/src/runtime/document-locations.ts +521 -0
  128. package/src/runtime/document-navigation.ts +616 -0
  129. package/src/runtime/document-outline.ts +440 -0
  130. package/src/runtime/document-runtime.ts +4055 -0
  131. package/src/runtime/document-search.ts +145 -0
  132. package/src/runtime/event-refresh-hints.ts +137 -0
  133. package/src/runtime/numbering-prefix.ts +244 -0
  134. package/src/runtime/page-layout-estimation.ts +305 -0
  135. package/src/runtime/read-only-diagnostics-runtime.ts +241 -0
  136. package/src/runtime/resolved-numbering-geometry.ts +293 -0
  137. package/src/runtime/review-runtime.ts +44 -0
  138. package/src/runtime/revision-runtime.ts +107 -0
  139. package/src/runtime/session-capabilities.ts +192 -0
  140. package/src/runtime/story-context.ts +164 -0
  141. package/src/runtime/story-targeting.ts +162 -0
  142. package/src/runtime/suggestions-snapshot.ts +137 -0
  143. package/src/runtime/surface-projection.ts +1553 -0
  144. package/src/runtime/table-commands.ts +173 -0
  145. package/src/runtime/table-schema.ts +309 -0
  146. package/src/runtime/table-style-resolver.ts +409 -0
  147. package/src/runtime/view-state.ts +493 -0
  148. package/src/runtime/virtualized-rendering.ts +258 -0
  149. package/src/runtime/workflow-markup.ts +393 -0
  150. package/src/ui/README.md +30 -0
  151. package/src/ui/WordReviewEditor.tsx +5268 -0
  152. package/src/ui/browser-export.ts +52 -0
  153. package/src/ui/comments/README.md +3 -0
  154. package/src/ui/compatibility/README.md +3 -0
  155. package/src/ui/editor-command-bag.ts +127 -0
  156. package/src/ui/editor-runtime-boundary.ts +1558 -0
  157. package/src/ui/editor-shell-view.tsx +144 -0
  158. package/src/ui/editor-surface/README.md +3 -0
  159. package/src/ui/editor-surface-controller.tsx +66 -0
  160. package/src/ui/headless/comment-decoration-model.ts +124 -0
  161. package/src/ui/headless/preserve-editor-selection.ts +5 -0
  162. package/src/ui/headless/revision-decoration-model.ts +128 -0
  163. package/src/ui/headless/selection-helpers.ts +54 -0
  164. package/src/ui/headless/selection-tool-context.ts +19 -0
  165. package/src/ui/headless/selection-tool-resolver.ts +752 -0
  166. package/src/ui/headless/selection-tool-types.ts +129 -0
  167. package/src/ui/headless/selection-toolbar-model.ts +11 -0
  168. package/src/ui/headless/use-editor-keyboard.ts +103 -0
  169. package/src/ui/review/README.md +3 -0
  170. package/src/ui/runtime-shortcut-dispatch.ts +365 -0
  171. package/src/ui/runtime-snapshot-selectors.ts +197 -0
  172. package/src/ui/shared/revision-filters.ts +31 -0
  173. package/src/ui/status/README.md +3 -0
  174. package/src/ui/theme/README.md +3 -0
  175. package/src/ui/toolbar/README.md +3 -0
  176. package/src/ui/workflow-surface-blocked-rails.ts +94 -0
  177. package/src/ui-tailwind/chrome/chrome-preset-model.ts +107 -0
  178. package/src/ui-tailwind/chrome/chrome-preset-toolbar.tsx +15 -0
  179. package/src/ui-tailwind/chrome/review-queue-bar.tsx +97 -0
  180. package/src/ui-tailwind/chrome/tw-alert-banner.tsx +64 -0
  181. package/src/ui-tailwind/chrome/tw-context-analytics-summary.tsx +122 -0
  182. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +121 -0
  183. package/src/ui-tailwind/chrome/tw-layout-panel.tsx +114 -0
  184. package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +30 -0
  185. package/src/ui-tailwind/chrome/tw-page-ruler.tsx +365 -0
  186. package/src/ui-tailwind/chrome/tw-selection-tool-blocked.tsx +23 -0
  187. package/src/ui-tailwind/chrome/tw-selection-tool-comment.tsx +35 -0
  188. package/src/ui-tailwind/chrome/tw-selection-tool-formatting.tsx +37 -0
  189. package/src/ui-tailwind/chrome/tw-selection-tool-host.tsx +298 -0
  190. package/src/ui-tailwind/chrome/tw-selection-tool-structure.tsx +116 -0
  191. package/src/ui-tailwind/chrome/tw-selection-tool-suggestion.tsx +29 -0
  192. package/src/ui-tailwind/chrome/tw-selection-tool-workflow.tsx +27 -0
  193. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +186 -0
  194. package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +139 -0
  195. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +200 -0
  196. package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +58 -0
  197. package/src/ui-tailwind/chrome/use-before-unload.ts +20 -0
  198. package/src/ui-tailwind/editor-surface/perf-probe.ts +179 -0
  199. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +189 -0
  200. package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +31 -0
  201. package/src/ui-tailwind/editor-surface/pm-decorations.ts +411 -0
  202. package/src/ui-tailwind/editor-surface/pm-position-map.ts +123 -0
  203. package/src/ui-tailwind/editor-surface/pm-schema.ts +927 -0
  204. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +567 -0
  205. package/src/ui-tailwind/editor-surface/search-plugin.ts +168 -0
  206. package/src/ui-tailwind/editor-surface/surface-build-keys.ts +65 -0
  207. package/src/ui-tailwind/editor-surface/tw-caret.tsx +12 -0
  208. package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +150 -0
  209. package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +129 -0
  210. package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +58 -0
  211. package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +151 -0
  212. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +1047 -0
  213. package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +111 -0
  214. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +503 -0
  215. package/src/ui-tailwind/index.ts +62 -0
  216. package/src/ui-tailwind/page-chrome-model.ts +27 -0
  217. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +406 -0
  218. package/src/ui-tailwind/review/tw-health-panel.tsx +149 -0
  219. package/src/ui-tailwind/review/tw-review-rail.tsx +122 -0
  220. package/src/ui-tailwind/review/tw-revision-sidebar.tsx +164 -0
  221. package/src/ui-tailwind/status/tw-status-bar.tsx +65 -0
  222. package/{dist → src}/ui-tailwind/theme/editor-theme.css +58 -40
  223. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +52 -0
  224. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +1133 -0
  225. package/src/ui-tailwind/tw-review-workspace.tsx +1460 -0
  226. package/src/validation/README.md +3 -0
  227. package/src/validation/compatibility-engine.ts +878 -0
  228. package/src/validation/compatibility-report.ts +161 -0
  229. package/src/validation/diagnostics.ts +204 -0
  230. package/src/validation/docx-comment-proof.ts +720 -0
  231. package/src/validation/import-diagnostics.ts +128 -0
  232. package/src/validation/low-priority-word-surfaces.ts +373 -0
  233. package/dist/canonical-document-BLEbzL2J.d.cts +0 -844
  234. package/dist/canonical-document-BLEbzL2J.d.ts +0 -844
  235. package/dist/chunk-2FJS5GZM.js +0 -763
  236. package/dist/chunk-2FJS5GZM.js.map +0 -1
  237. package/dist/chunk-2OQBZS3F.js +0 -446
  238. package/dist/chunk-2OQBZS3F.js.map +0 -1
  239. package/dist/chunk-2S7W4KFO.js +0 -127
  240. package/dist/chunk-2S7W4KFO.js.map +0 -1
  241. package/dist/chunk-2TG72QSW.js +0 -3874
  242. package/dist/chunk-2TG72QSW.js.map +0 -1
  243. package/dist/chunk-36QNIZBO.js +0 -532
  244. package/dist/chunk-36QNIZBO.js.map +0 -1
  245. package/dist/chunk-4AQOYAW4.js +0 -3069
  246. package/dist/chunk-4AQOYAW4.js.map +0 -1
  247. package/dist/chunk-4D5EWJ3P.js +0 -77
  248. package/dist/chunk-4D5EWJ3P.js.map +0 -1
  249. package/dist/chunk-5FN54NDH.js +0 -2257
  250. package/dist/chunk-5FN54NDH.js.map +0 -1
  251. package/dist/chunk-BOYGQYRQ.js +0 -7306
  252. package/dist/chunk-BOYGQYRQ.js.map +0 -1
  253. package/dist/chunk-CN3XMECL.js +0 -212
  254. package/dist/chunk-CN3XMECL.js.map +0 -1
  255. package/dist/chunk-EBI3BX6U.js +0 -164
  256. package/dist/chunk-EBI3BX6U.js.map +0 -1
  257. package/dist/chunk-EILUG3VB.js +0 -1275
  258. package/dist/chunk-EILUG3VB.js.map +0 -1
  259. package/dist/chunk-FUDY333O.js +0 -70
  260. package/dist/chunk-FUDY333O.js.map +0 -1
  261. package/dist/chunk-GBVOWFIK.js +0 -1237
  262. package/dist/chunk-GBVOWFIK.js.map +0 -1
  263. package/dist/chunk-H4TQ3H3Y.js +0 -262
  264. package/dist/chunk-H4TQ3H3Y.js.map +0 -1
  265. package/dist/chunk-JGB3IXZO.js +0 -189
  266. package/dist/chunk-JGB3IXZO.js.map +0 -1
  267. package/dist/chunk-KD2QRQPY.js +0 -4342
  268. package/dist/chunk-KD2QRQPY.js.map +0 -1
  269. package/dist/chunk-KLMXQVYK.js +0 -369
  270. package/dist/chunk-KLMXQVYK.js.map +0 -1
  271. package/dist/chunk-KZUG5KFQ.js +0 -214
  272. package/dist/chunk-KZUG5KFQ.js.map +0 -1
  273. package/dist/chunk-QDAQ4CJU.js +0 -345
  274. package/dist/chunk-QDAQ4CJU.js.map +0 -1
  275. package/dist/chunk-RMH72RZI.js.map +0 -1
  276. package/dist/chunk-SWKWQZXM.js +0 -117
  277. package/dist/chunk-SWKWQZXM.js.map +0 -1
  278. package/dist/chunk-TJBP2K4T.js.map +0 -1
  279. package/dist/chunk-TLCEAQDQ.js +0 -542
  280. package/dist/chunk-TLCEAQDQ.js.map +0 -1
  281. package/dist/chunk-UZXBISGO.js.map +0 -1
  282. package/dist/chunk-WGBAKP3Q.js +0 -3220
  283. package/dist/chunk-WGBAKP3Q.js.map +0 -1
  284. package/dist/compare/index.cjs +0 -5475
  285. package/dist/compare/index.cjs.map +0 -1
  286. package/dist/compare/index.d.cts +0 -114
  287. package/dist/compare/index.d.ts +0 -114
  288. package/dist/compare/index.js +0 -731
  289. package/dist/compare/index.js.map +0 -1
  290. package/dist/core/commands/formatting-commands.cjs +0 -828
  291. package/dist/core/commands/formatting-commands.cjs.map +0 -1
  292. package/dist/core/commands/formatting-commands.d.cts +0 -63
  293. package/dist/core/commands/formatting-commands.d.ts +0 -63
  294. package/dist/core/commands/formatting-commands.js +0 -37
  295. package/dist/core/commands/formatting-commands.js.map +0 -1
  296. package/dist/core/commands/image-commands.cjs +0 -2023
  297. package/dist/core/commands/image-commands.cjs.map +0 -1
  298. package/dist/core/commands/image-commands.d.cts +0 -58
  299. package/dist/core/commands/image-commands.d.ts +0 -58
  300. package/dist/core/commands/image-commands.js +0 -18
  301. package/dist/core/commands/image-commands.js.map +0 -1
  302. package/dist/core/commands/section-layout-commands.cjs.map +0 -1
  303. package/dist/core/commands/section-layout-commands.d.cts +0 -62
  304. package/dist/core/commands/section-layout-commands.d.ts +0 -62
  305. package/dist/core/commands/section-layout-commands.js +0 -21
  306. package/dist/core/commands/section-layout-commands.js.map +0 -1
  307. package/dist/core/commands/style-commands.cjs.map +0 -1
  308. package/dist/core/commands/style-commands.d.cts +0 -13
  309. package/dist/core/commands/style-commands.d.ts +0 -13
  310. package/dist/core/commands/style-commands.js +0 -9
  311. package/dist/core/commands/style-commands.js.map +0 -1
  312. package/dist/core/commands/table-structure-commands.cjs +0 -1883
  313. package/dist/core/commands/table-structure-commands.cjs.map +0 -1
  314. package/dist/core/commands/table-structure-commands.d.cts +0 -59
  315. package/dist/core/commands/table-structure-commands.d.ts +0 -59
  316. package/dist/core/commands/table-structure-commands.js +0 -12
  317. package/dist/core/commands/table-structure-commands.js.map +0 -1
  318. package/dist/core/commands/text-commands.cjs +0 -2391
  319. package/dist/core/commands/text-commands.cjs.map +0 -1
  320. package/dist/core/commands/text-commands.d.cts +0 -24
  321. package/dist/core/commands/text-commands.d.ts +0 -24
  322. package/dist/core/commands/text-commands.js +0 -28
  323. package/dist/core/commands/text-commands.js.map +0 -1
  324. package/dist/core/selection/mapping.cjs +0 -200
  325. package/dist/core/selection/mapping.cjs.map +0 -1
  326. package/dist/core/selection/mapping.d.cts +0 -2
  327. package/dist/core/selection/mapping.d.ts +0 -2
  328. package/dist/core/selection/mapping.js +0 -31
  329. package/dist/core/selection/mapping.js.map +0 -1
  330. package/dist/core/state/editor-state.cjs +0 -2278
  331. package/dist/core/state/editor-state.cjs.map +0 -1
  332. package/dist/core/state/editor-state.d.cts +0 -2
  333. package/dist/core/state/editor-state.d.ts +0 -2
  334. package/dist/core/state/editor-state.js +0 -26
  335. package/dist/core/state/editor-state.js.map +0 -1
  336. package/dist/index.cjs +0 -38553
  337. package/dist/index.cjs.map +0 -1
  338. package/dist/index.d.cts +0 -15
  339. package/dist/index.d.ts +0 -15
  340. package/dist/index.js +0 -7856
  341. package/dist/index.js.map +0 -1
  342. package/dist/io/docx-session.cjs +0 -16236
  343. package/dist/io/docx-session.cjs.map +0 -1
  344. package/dist/io/docx-session.d.cts +0 -21
  345. package/dist/io/docx-session.d.ts +0 -21
  346. package/dist/io/docx-session.js +0 -18
  347. package/dist/io/docx-session.js.map +0 -1
  348. package/dist/legal/index.cjs +0 -3900
  349. package/dist/legal/index.cjs.map +0 -1
  350. package/dist/legal/index.d.cts +0 -86
  351. package/dist/legal/index.d.ts +0 -86
  352. package/dist/legal/index.js +0 -616
  353. package/dist/legal/index.js.map +0 -1
  354. package/dist/public-types-7ZL_94cz.d.ts +0 -1573
  355. package/dist/public-types-CeMaDueh.d.cts +0 -1573
  356. package/dist/public-types.cjs +0 -19
  357. package/dist/public-types.cjs.map +0 -1
  358. package/dist/public-types.d.cts +0 -2
  359. package/dist/public-types.d.ts +0 -2
  360. package/dist/public-types.js +0 -1
  361. package/dist/public-types.js.map +0 -1
  362. package/dist/runtime/document-runtime.cjs +0 -11140
  363. package/dist/runtime/document-runtime.cjs.map +0 -1
  364. package/dist/runtime/document-runtime.d.cts +0 -231
  365. package/dist/runtime/document-runtime.d.ts +0 -231
  366. package/dist/runtime/document-runtime.js +0 -21
  367. package/dist/runtime/document-runtime.js.map +0 -1
  368. package/dist/structural-helpers-CilgOVhh.d.cts +0 -10
  369. package/dist/structural-helpers-q0Gd-eBN.d.ts +0 -10
  370. package/dist/ui-tailwind/editor-surface/search-plugin.cjs +0 -313
  371. package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +0 -1
  372. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +0 -67
  373. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +0 -67
  374. package/dist/ui-tailwind/editor-surface/search-plugin.js +0 -23
  375. package/dist/ui-tailwind/editor-surface/search-plugin.js.map +0 -1
  376. package/dist/ui-tailwind/index.cjs +0 -4833
  377. package/dist/ui-tailwind/index.cjs.map +0 -1
  378. package/dist/ui-tailwind/index.d.cts +0 -617
  379. package/dist/ui-tailwind/index.d.ts +0 -617
  380. package/dist/ui-tailwind/index.js +0 -575
  381. package/dist/ui-tailwind/index.js.map +0 -1
@@ -1,2257 +0,0 @@
1
- import {
2
- DEFAULT_BOUNDARY_ASSOC,
3
- createDetachedAnchor,
4
- createNodeAnchor,
5
- createRangeAnchor
6
- } from "./chunk-EBI3BX6U.js";
7
-
8
- // src/model/cds-1.0.0.ts
9
- var CDS_SCHEMA_VERSION = "cds/1.0.0";
10
- var LEGACY_PERSISTED_EDITOR_SNAPSHOT_VERSION = "persisted-editor-snapshot/1";
11
- var PERSISTED_EDITOR_SNAPSHOT_VERSION = "persisted-editor-snapshot/2";
12
- var COMPATIBILITY_REPORT_VERSION = "compatibility-report/1";
13
- var ModelValidationError = class extends Error {
14
- issues;
15
- constructor(message, issues) {
16
- super(message);
17
- this.name = "ModelValidationError";
18
- this.issues = issues;
19
- }
20
- };
21
- var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
22
- var ISO_8601_UTC_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/;
23
- function isPlainObject(value) {
24
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
25
- return false;
26
- }
27
- const prototype = Object.getPrototypeOf(value);
28
- return prototype === Object.prototype || prototype === null;
29
- }
30
- function isNonEmptyString(value) {
31
- return typeof value === "string" && value.trim().length > 0;
32
- }
33
- function isUuid(value) {
34
- return typeof value === "string" && UUID_PATTERN.test(value);
35
- }
36
- function isIso8601UtcTimestamp(value) {
37
- return typeof value === "string" && ISO_8601_UTC_PATTERN.test(value) && !Number.isNaN(Date.parse(value));
38
- }
39
- function asPlainObject(value, path, issues) {
40
- if (!isPlainObject(value)) {
41
- issues.push({ path, message: "Expected a plain object." });
42
- return null;
43
- }
44
- return value;
45
- }
46
- function expectString(value, path, issues) {
47
- if (!isNonEmptyString(value)) {
48
- issues.push({ path, message: "Expected a non-empty string." });
49
- return null;
50
- }
51
- return value;
52
- }
53
- function expectStringAllowEmpty(value, path, issues) {
54
- if (typeof value !== "string") {
55
- issues.push({ path, message: "Expected a string." });
56
- return null;
57
- }
58
- return value;
59
- }
60
- function expectExactString(value, expected, path, issues) {
61
- if (value !== expected) {
62
- issues.push({
63
- path,
64
- message: `Expected ${JSON.stringify(expected)}.`
65
- });
66
- return null;
67
- }
68
- return expected;
69
- }
70
- function expectIso8601UtcTimestamp(value, path, issues) {
71
- if (!isIso8601UtcTimestamp(value)) {
72
- issues.push({
73
- path,
74
- message: "Expected an ISO 8601 UTC timestamp string."
75
- });
76
- return null;
77
- }
78
- return value;
79
- }
80
- function expectUuid(value, path, issues) {
81
- if (!isUuid(value)) {
82
- issues.push({
83
- path,
84
- message: "Expected an RFC 4122 UUID string."
85
- });
86
- return null;
87
- }
88
- return value;
89
- }
90
- function sortRecordKeys(record) {
91
- return Object.entries(record).sort(
92
- ([left], [right]) => left.localeCompare(right)
93
- );
94
- }
95
- function assertValid(issues, message) {
96
- if (issues.length > 0) {
97
- throw new ModelValidationError(message, issues);
98
- }
99
- }
100
- function toStableJsonValue(value) {
101
- if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
102
- return value;
103
- }
104
- if (Array.isArray(value)) {
105
- return value.map((item) => toStableJsonValue(item));
106
- }
107
- if (!isPlainObject(value)) {
108
- throw new TypeError("Cannot serialize non-JSON value.");
109
- }
110
- const sortedEntries = sortRecordKeys(value).filter(
111
- ([, entryValue]) => entryValue !== void 0
112
- );
113
- const result = {};
114
- for (const [key, entryValue] of sortedEntries) {
115
- result[key] = toStableJsonValue(entryValue);
116
- }
117
- return result;
118
- }
119
- function stableStringify(value) {
120
- return JSON.stringify(toStableJsonValue(value));
121
- }
122
-
123
- // src/model/canonical-document.ts
124
- var CANONICAL_DOCUMENT_TOP_LEVEL_KEYS = [
125
- "schemaVersion",
126
- "docId",
127
- "createdAt",
128
- "updatedAt",
129
- "metadata",
130
- "styles",
131
- "numbering",
132
- "media",
133
- "content",
134
- "review",
135
- "preservation",
136
- "diagnostics"
137
- ];
138
- var CANONICAL_DOCUMENT_OPTIONAL_KEYS = ["subParts", "fieldRegistry"];
139
- var ID_PATTERNS = {
140
- styleId: /^[A-Za-z_][A-Za-z0-9._-]{0,127}$/,
141
- abstractNumberingId: /^abstract-num:[A-Za-z0-9._-]{1,120}$/,
142
- numberingInstanceId: /^num:[A-Za-z0-9._-]{1,120}$/,
143
- mediaId: /^media:[A-Za-z0-9._/-]{1,120}$/,
144
- commentId: /^(?:comment:[A-Za-z0-9._-]{1,120}|comment-[A-Za-z0-9._-]{1,120}|[0-9]{1,18})$/,
145
- revisionId: /^(?:revision:[A-Za-z0-9._-]{1,120}|change-[A-Za-z0-9._-]{1,120})$/,
146
- fragmentId: /^fragment:[A-Za-z0-9._-]{1,120}$/,
147
- warningId: /^warning:[A-Za-z0-9._:-]{1,120}$/,
148
- diagnosticId: /^diagnostic:[A-Za-z0-9._-]{1,120}$/,
149
- packagePartName: /^\/[A-Za-z0-9_.\-\/]+\.[A-Za-z0-9]+$/,
150
- relationshipId: /^rId[A-Za-z0-9._-]{1,120}$/
151
- };
152
- function createCanonicalDocumentSignature(document) {
153
- return stableStringify(document);
154
- }
155
- function projectCanonicalDocument(document) {
156
- assertCanonicalDocument(document);
157
- return JSON.parse(stableStringify(document));
158
- }
159
- function assertCanonicalDocument(value) {
160
- const issues = validateCanonicalDocument(value);
161
- assertValid(issues, "Invalid canonical document.");
162
- }
163
- function validateCanonicalDocument(value) {
164
- const issues = [];
165
- const record = asPlainObject(value, "$", issues);
166
- if (!record) {
167
- return issues;
168
- }
169
- validateExactObjectKeys(record, CANONICAL_DOCUMENT_TOP_LEVEL_KEYS, "$", issues, CANONICAL_DOCUMENT_OPTIONAL_KEYS);
170
- expectExactString(record.schemaVersion, CDS_SCHEMA_VERSION, "$.schemaVersion", issues);
171
- expectUuid(record.docId, "$.docId", issues);
172
- expectIso8601UtcTimestamp(record.createdAt, "$.createdAt", issues);
173
- expectIso8601UtcTimestamp(record.updatedAt, "$.updatedAt", issues);
174
- validateMetadata(record.metadata, "$.metadata", issues);
175
- validateStylesCatalog(record.styles, "$.styles", issues);
176
- validateNumberingCatalog(record.numbering, "$.numbering", issues);
177
- validateMediaCatalog(record.media, "$.media", issues);
178
- validateDocumentNode(record.content, "$.content", issues);
179
- validateReviewStore(record.review, "$.review", issues);
180
- validatePreservationStore(record.preservation, "$.preservation", issues);
181
- validateDiagnosticStore(record.diagnostics, "$.diagnostics", issues);
182
- if (record.subParts !== void 0) {
183
- validateSubPartsCatalog(record.subParts, "$.subParts", issues);
184
- }
185
- validateDocumentReferences(record, issues);
186
- return issues;
187
- }
188
- function validateMetadata(value, path, issues) {
189
- const record = asPlainObject(value, path, issues);
190
- if (!record) {
191
- return;
192
- }
193
- const customProperties = asPlainObject(record.customProperties, `${path}.customProperties`, issues);
194
- if (!customProperties) {
195
- return;
196
- }
197
- for (const [propertyKey, propertyValue] of Object.entries(customProperties)) {
198
- if (typeof propertyValue !== "string") {
199
- issues.push({
200
- path: `${path}.customProperties.${propertyKey}`,
201
- message: "customProperties values must be strings."
202
- });
203
- }
204
- }
205
- }
206
- function validateStylesCatalog(value, path, issues) {
207
- const record = asPlainObject(value, path, issues);
208
- if (!record) {
209
- return;
210
- }
211
- validateStyleMap(record.paragraphs, `${path}.paragraphs`, issues);
212
- validateStyleMap(record.characters, `${path}.characters`, issues);
213
- validateStyleMap(record.tables, `${path}.tables`, issues);
214
- if (record.latentStyles !== void 0) {
215
- validateLatentStyleMap(record.latentStyles, `${path}.latentStyles`, issues);
216
- }
217
- }
218
- function validateStyleMap(value, path, issues) {
219
- const record = asPlainObject(value, path, issues);
220
- if (!record) {
221
- return;
222
- }
223
- for (const [styleId, definition] of Object.entries(record)) {
224
- expectDomainString(styleId, "styleId", `${path}.${styleId}`, issues);
225
- const definitionRecord = asPlainObject(definition, `${path}.${styleId}`, issues);
226
- if (!definitionRecord) {
227
- continue;
228
- }
229
- if (definitionRecord.styleId !== styleId) {
230
- issues.push({
231
- path: `${path}.${styleId}.styleId`,
232
- message: "styleId must match the map key."
233
- });
234
- }
235
- }
236
- }
237
- function validateLatentStyleMap(value, path, issues) {
238
- const record = asPlainObject(value, path, issues);
239
- if (!record) {
240
- return;
241
- }
242
- for (const [styleName, definition] of Object.entries(record)) {
243
- const definitionRecord = asPlainObject(definition, `${path}.${styleName}`, issues);
244
- if (!definitionRecord) {
245
- continue;
246
- }
247
- if (definitionRecord.name !== styleName) {
248
- issues.push({
249
- path: `${path}.${styleName}.name`,
250
- message: "name must match the map key."
251
- });
252
- }
253
- if (definitionRecord.uiPriority !== void 0 && typeof definitionRecord.uiPriority !== "number") {
254
- issues.push({
255
- path: `${path}.${styleName}.uiPriority`,
256
- message: "uiPriority must be a number."
257
- });
258
- }
259
- }
260
- }
261
- function validateNumberingCatalog(value, path, issues) {
262
- const record = asPlainObject(value, path, issues);
263
- if (!record) {
264
- return;
265
- }
266
- const abstractDefinitions = asPlainObject(
267
- record.abstractDefinitions,
268
- `${path}.abstractDefinitions`,
269
- issues
270
- );
271
- if (abstractDefinitions) {
272
- for (const [abstractId, definition] of Object.entries(abstractDefinitions)) {
273
- expectDomainString(
274
- abstractId,
275
- "abstractNumberingId",
276
- `${path}.abstractDefinitions.${abstractId}`,
277
- issues
278
- );
279
- const definitionRecord = asPlainObject(
280
- definition,
281
- `${path}.abstractDefinitions.${abstractId}`,
282
- issues
283
- );
284
- if (definitionRecord && definitionRecord.abstractNumberingId !== abstractId) {
285
- issues.push({
286
- path: `${path}.abstractDefinitions.${abstractId}.abstractNumberingId`,
287
- message: "abstractNumberingId must match the map key."
288
- });
289
- }
290
- }
291
- }
292
- const instances = asPlainObject(record.instances, `${path}.instances`, issues);
293
- if (instances) {
294
- for (const [instanceId, instance] of Object.entries(instances)) {
295
- expectDomainString(
296
- instanceId,
297
- "numberingInstanceId",
298
- `${path}.instances.${instanceId}`,
299
- issues
300
- );
301
- const instanceRecord = asPlainObject(
302
- instance,
303
- `${path}.instances.${instanceId}`,
304
- issues
305
- );
306
- if (!instanceRecord) {
307
- continue;
308
- }
309
- if (instanceRecord.numberingInstanceId !== instanceId) {
310
- issues.push({
311
- path: `${path}.instances.${instanceId}.numberingInstanceId`,
312
- message: "numberingInstanceId must match the map key."
313
- });
314
- }
315
- expectDomainString(
316
- instanceRecord.abstractNumberingId,
317
- "abstractNumberingId",
318
- `${path}.instances.${instanceId}.abstractNumberingId`,
319
- issues
320
- );
321
- }
322
- }
323
- }
324
- function validateMediaCatalog(value, path, issues) {
325
- const record = asPlainObject(value, path, issues);
326
- if (!record) {
327
- return;
328
- }
329
- const items = asPlainObject(record.items, `${path}.items`, issues);
330
- if (!items) {
331
- return;
332
- }
333
- for (const [mediaId, item] of Object.entries(items)) {
334
- expectDomainString(mediaId, "mediaId", `${path}.items.${mediaId}`, issues);
335
- const itemRecord = asPlainObject(item, `${path}.items.${mediaId}`, issues);
336
- if (!itemRecord) {
337
- continue;
338
- }
339
- if (itemRecord.mediaId !== mediaId) {
340
- issues.push({
341
- path: `${path}.items.${mediaId}.mediaId`,
342
- message: "mediaId must match the map key."
343
- });
344
- }
345
- expectDomainString(
346
- itemRecord.packagePartName,
347
- "packagePartName",
348
- `${path}.items.${mediaId}.packagePartName`,
349
- issues
350
- );
351
- if (itemRecord.relationshipId !== void 0) {
352
- expectDomainString(
353
- itemRecord.relationshipId,
354
- "relationshipId",
355
- `${path}.items.${mediaId}.relationshipId`,
356
- issues
357
- );
358
- }
359
- }
360
- }
361
- function validateDocumentNode(value, path, issues) {
362
- const record = asPlainObject(value, path, issues);
363
- if (!record) {
364
- return;
365
- }
366
- const type = expectString(record.type, `${path}.type`, issues);
367
- if (!type) {
368
- return;
369
- }
370
- switch (type) {
371
- case "doc":
372
- case "paragraph":
373
- case "sdt":
374
- case "custom_xml":
375
- case "hyperlink":
376
- if (!Array.isArray(record.children)) {
377
- issues.push({ path: `${path}.children`, message: "children must be an array." });
378
- } else {
379
- record.children.forEach(
380
- (child, index) => validateDocumentNode(child, `${path}.children[${index}]`, issues)
381
- );
382
- }
383
- if (type === "paragraph" && record.styleId !== void 0) {
384
- expectDomainString(record.styleId, "styleId", `${path}.styleId`, issues);
385
- }
386
- if (type === "paragraph" && record.numbering !== void 0) {
387
- const numbering = asPlainObject(record.numbering, `${path}.numbering`, issues);
388
- if (numbering) {
389
- expectDomainString(
390
- numbering.numberingInstanceId,
391
- "numberingInstanceId",
392
- `${path}.numbering.numberingInstanceId`,
393
- issues
394
- );
395
- if (typeof numbering.level !== "number") {
396
- issues.push({
397
- path: `${path}.numbering.level`,
398
- message: "level must be a number."
399
- });
400
- }
401
- }
402
- }
403
- if (type === "hyperlink") {
404
- expectString(record.href, `${path}.href`, issues);
405
- }
406
- return;
407
- case "alt_chunk":
408
- expectDomainString(record.relationshipId, "relationshipId", `${path}.relationshipId`, issues);
409
- return;
410
- case "image":
411
- expectDomainString(record.mediaId, "mediaId", `${path}.mediaId`, issues);
412
- if (record.placementXml !== void 0) {
413
- expectString(record.placementXml, `${path}.placementXml`, issues);
414
- }
415
- if (record.display !== void 0) {
416
- const display = expectString(record.display, `${path}.display`, issues);
417
- if (display && display !== "inline" && display !== "floating") {
418
- issues.push({
419
- path: `${path}.display`,
420
- message: "display must be 'inline' or 'floating'."
421
- });
422
- }
423
- }
424
- if (record.floating !== void 0) {
425
- validateFloatingImageProperties(record.floating, `${path}.floating`, issues);
426
- }
427
- return;
428
- case "opaque_inline":
429
- case "opaque_block":
430
- expectDomainString(record.fragmentId, "fragmentId", `${path}.fragmentId`, issues);
431
- expectDomainString(record.warningId, "warningId", `${path}.warningId`, issues);
432
- if (record.rawXml !== void 0) {
433
- expectString(record.rawXml, `${path}.rawXml`, issues);
434
- }
435
- return;
436
- case "table":
437
- if (!Array.isArray(record.gridColumns)) {
438
- issues.push({ path: `${path}.gridColumns`, message: "gridColumns must be an array." });
439
- }
440
- if (!Array.isArray(record.rows)) {
441
- issues.push({ path: `${path}.rows`, message: "rows must be an array." });
442
- } else {
443
- record.rows.forEach(
444
- (row, rowIndex) => validateDocumentNode(row, `${path}.rows[${rowIndex}]`, issues)
445
- );
446
- }
447
- return;
448
- case "table_row":
449
- if (!Array.isArray(record.cells)) {
450
- issues.push({ path: `${path}.cells`, message: "cells must be an array." });
451
- } else {
452
- record.cells.forEach(
453
- (cell, cellIndex) => validateDocumentNode(cell, `${path}.cells[${cellIndex}]`, issues)
454
- );
455
- }
456
- return;
457
- case "table_cell":
458
- if (!Array.isArray(record.children)) {
459
- issues.push({ path: `${path}.children`, message: "children must be an array." });
460
- } else {
461
- record.children.forEach(
462
- (child, childIndex) => validateDocumentNode(child, `${path}.children[${childIndex}]`, issues)
463
- );
464
- }
465
- return;
466
- case "field":
467
- expectString(record.fieldType, `${path}.fieldType`, issues);
468
- expectString(record.instruction, `${path}.instruction`, issues);
469
- if (!Array.isArray(record.children)) {
470
- issues.push({ path: `${path}.children`, message: "children must be an array." });
471
- } else {
472
- record.children.forEach(
473
- (child, index) => validateDocumentNode(child, `${path}.children[${index}]`, issues)
474
- );
475
- }
476
- return;
477
- case "bookmark_start":
478
- expectString(record.bookmarkId, `${path}.bookmarkId`, issues);
479
- expectString(record.name, `${path}.name`, issues);
480
- return;
481
- case "bookmark_end":
482
- expectString(record.bookmarkId, `${path}.bookmarkId`, issues);
483
- return;
484
- case "section_break":
485
- return;
486
- case "text":
487
- if (typeof record.text !== "string") {
488
- issues.push({
489
- path: `${path}.text`,
490
- message: "text must be a string."
491
- });
492
- }
493
- return;
494
- case "hard_break":
495
- case "column_break":
496
- case "tab":
497
- return;
498
- case "symbol":
499
- expectString(record.char, `${path}.char`, issues);
500
- if (record.font !== void 0) {
501
- expectString(record.font, `${path}.font`, issues);
502
- }
503
- return;
504
- case "footnote_ref":
505
- expectString(record.noteId, `${path}.noteId`, issues);
506
- if (record.noteKind !== "footnote" && record.noteKind !== "endnote") {
507
- issues.push({
508
- path: `${path}.noteKind`,
509
- message: "noteKind must be 'footnote' or 'endnote'."
510
- });
511
- }
512
- return;
513
- case "chart_preview":
514
- case "smartart_preview":
515
- case "shape":
516
- case "wordart":
517
- case "vml_shape":
518
- expectString(record.rawXml, `${path}.rawXml`, issues);
519
- return;
520
- default:
521
- issues.push({
522
- path: `${path}.type`,
523
- message: `Unsupported node type ${JSON.stringify(type)}.`
524
- });
525
- }
526
- }
527
- function validateFloatingImageProperties(value, path, issues) {
528
- const record = asPlainObject(value, path, issues);
529
- if (!record) {
530
- return;
531
- }
532
- if (record.horizontalPosition !== void 0) {
533
- validateFloatingAxisPosition(record.horizontalPosition, `${path}.horizontalPosition`, issues);
534
- }
535
- if (record.verticalPosition !== void 0) {
536
- validateFloatingAxisPosition(record.verticalPosition, `${path}.verticalPosition`, issues);
537
- }
538
- if (record.wrap !== void 0) {
539
- const wrap = expectString(record.wrap, `${path}.wrap`, issues);
540
- if (wrap && wrap !== "none" && wrap !== "square" && wrap !== "tight" && wrap !== "through" && wrap !== "topAndBottom") {
541
- issues.push({
542
- path: `${path}.wrap`,
543
- message: "wrap must be one of none, square, tight, through, or topAndBottom."
544
- });
545
- }
546
- }
547
- }
548
- function validateFloatingAxisPosition(value, path, issues) {
549
- const record = asPlainObject(value, path, issues);
550
- if (!record) {
551
- return;
552
- }
553
- if (record.relativeFrom !== void 0) {
554
- expectString(record.relativeFrom, `${path}.relativeFrom`, issues);
555
- }
556
- if (record.align !== void 0) {
557
- expectString(record.align, `${path}.align`, issues);
558
- }
559
- if (record.offset !== void 0 && typeof record.offset !== "number") {
560
- issues.push({
561
- path: `${path}.offset`,
562
- message: "offset must be a number."
563
- });
564
- }
565
- }
566
- function validateReviewStore(value, path, issues) {
567
- const record = asPlainObject(value, path, issues);
568
- if (!record) {
569
- return;
570
- }
571
- const comments = asPlainObject(record.comments, `${path}.comments`, issues);
572
- if (comments) {
573
- for (const [commentId, thread] of Object.entries(comments)) {
574
- expectDomainString(commentId, "commentId", `${path}.comments.${commentId}`, issues);
575
- const threadRecord = asPlainObject(thread, `${path}.comments.${commentId}`, issues);
576
- if (!threadRecord) {
577
- continue;
578
- }
579
- if (threadRecord.commentId !== commentId) {
580
- issues.push({
581
- path: `${path}.comments.${commentId}.commentId`,
582
- message: "commentId must match the map key."
583
- });
584
- }
585
- validateAnchor(threadRecord.anchor, `${path}.comments.${commentId}.anchor`, issues);
586
- expectIso8601UtcTimestamp(
587
- threadRecord.createdAt,
588
- `${path}.comments.${commentId}.createdAt`,
589
- issues
590
- );
591
- validateCommentStatus(threadRecord.status, `${path}.comments.${commentId}.status`, issues);
592
- if (threadRecord.createdBy !== void 0) {
593
- expectString(
594
- threadRecord.createdBy,
595
- `${path}.comments.${commentId}.createdBy`,
596
- issues
597
- );
598
- }
599
- if (threadRecord.authorId !== void 0) {
600
- expectString(
601
- threadRecord.authorId,
602
- `${path}.comments.${commentId}.authorId`,
603
- issues
604
- );
605
- }
606
- if (threadRecord.body !== void 0) {
607
- expectStringAllowEmpty(
608
- threadRecord.body,
609
- `${path}.comments.${commentId}.body`,
610
- issues
611
- );
612
- }
613
- if (!Array.isArray(threadRecord.warningIds)) {
614
- issues.push({
615
- path: `${path}.comments.${commentId}.warningIds`,
616
- message: "warningIds must be an array."
617
- });
618
- } else {
619
- threadRecord.warningIds.forEach(
620
- (warningId, index) => expectDomainString(
621
- warningId,
622
- "warningId",
623
- `${path}.comments.${commentId}.warningIds[${index}]`,
624
- issues
625
- )
626
- );
627
- }
628
- if (threadRecord.entries !== void 0) {
629
- validateCommentEntries(
630
- threadRecord.entries,
631
- `${path}.comments.${commentId}.entries`,
632
- issues
633
- );
634
- }
635
- if (threadRecord.resolution !== void 0) {
636
- validateCommentResolution(
637
- threadRecord.resolution,
638
- `${path}.comments.${commentId}.resolution`,
639
- issues
640
- );
641
- }
642
- if (threadRecord.resolvedAt !== void 0) {
643
- expectIso8601UtcTimestamp(
644
- threadRecord.resolvedAt,
645
- `${path}.comments.${commentId}.resolvedAt`,
646
- issues
647
- );
648
- }
649
- if (threadRecord.isResolved !== void 0 && typeof threadRecord.isResolved !== "boolean") {
650
- issues.push({
651
- path: `${path}.comments.${commentId}.isResolved`,
652
- message: "isResolved must be a boolean."
653
- });
654
- }
655
- if (threadRecord.metadata !== void 0) {
656
- validateCommentThreadMetadata(
657
- threadRecord.metadata,
658
- `${path}.comments.${commentId}.metadata`,
659
- issues
660
- );
661
- }
662
- }
663
- }
664
- const revisions = asPlainObject(record.revisions, `${path}.revisions`, issues);
665
- if (revisions) {
666
- for (const [revisionId, revision] of Object.entries(revisions)) {
667
- expectDomainString(revisionId, "revisionId", `${path}.revisions.${revisionId}`, issues);
668
- const revisionRecord = asPlainObject(
669
- revision,
670
- `${path}.revisions.${revisionId}`,
671
- issues
672
- );
673
- if (!revisionRecord) {
674
- continue;
675
- }
676
- if (revisionRecord.changeId !== revisionId) {
677
- issues.push({
678
- path: `${path}.revisions.${revisionId}.changeId`,
679
- message: "changeId must match the map key."
680
- });
681
- }
682
- validateAnchor(revisionRecord.anchor, `${path}.revisions.${revisionId}.anchor`, issues);
683
- validateRevisionKind(revisionRecord.kind, `${path}.revisions.${revisionId}.kind`, issues);
684
- validateRevisionStatus(
685
- revisionRecord.status,
686
- `${path}.revisions.${revisionId}.status`,
687
- issues
688
- );
689
- expectIso8601UtcTimestamp(
690
- revisionRecord.createdAt,
691
- `${path}.revisions.${revisionId}.createdAt`,
692
- issues
693
- );
694
- if (revisionRecord.authorId !== void 0) {
695
- expectString(
696
- revisionRecord.authorId,
697
- `${path}.revisions.${revisionId}.authorId`,
698
- issues
699
- );
700
- }
701
- if (revisionRecord.warningIds !== void 0) {
702
- validateWarningIds(
703
- revisionRecord.warningIds,
704
- `${path}.revisions.${revisionId}.warningIds`,
705
- issues
706
- );
707
- }
708
- if (revisionRecord.metadata !== void 0) {
709
- validateRevisionMetadata(
710
- revisionRecord.metadata,
711
- `${path}.revisions.${revisionId}.metadata`,
712
- issues
713
- );
714
- }
715
- }
716
- }
717
- }
718
- function validateCommentStatus(value, path, issues) {
719
- if (value === "open" || value === "resolved" || value === "detached") {
720
- return;
721
- }
722
- issues.push({
723
- path,
724
- message: "status must be one of open, resolved, or detached."
725
- });
726
- }
727
- function validateCommentEntries(value, path, issues) {
728
- if (!Array.isArray(value)) {
729
- issues.push({
730
- path,
731
- message: "entries must be an array."
732
- });
733
- return;
734
- }
735
- value.forEach((entry, index) => {
736
- const record = asPlainObject(entry, `${path}[${index}]`, issues);
737
- if (!record) {
738
- return;
739
- }
740
- expectString(record.entryId, `${path}[${index}].entryId`, issues);
741
- expectString(record.authorId, `${path}[${index}].authorId`, issues);
742
- expectStringAllowEmpty(record.body, `${path}[${index}].body`, issues);
743
- expectIso8601UtcTimestamp(record.createdAt, `${path}[${index}].createdAt`, issues);
744
- if (record.metadata !== void 0) {
745
- validateCommentEntryMetadata(record.metadata, `${path}[${index}].metadata`, issues);
746
- }
747
- });
748
- }
749
- function validateCommentEntryMetadata(value, path, issues) {
750
- const record = asPlainObject(value, path, issues);
751
- if (!record) {
752
- return;
753
- }
754
- for (const field of [
755
- "ooxmlCommentId",
756
- "paraId",
757
- "parentParaId",
758
- "durableId",
759
- "initials"
760
- ]) {
761
- if (record[field] !== void 0) {
762
- expectString(record[field], `${path}.${field}`, issues);
763
- }
764
- }
765
- }
766
- function validateCommentResolution(value, path, issues) {
767
- const record = asPlainObject(value, path, issues);
768
- if (!record) {
769
- return;
770
- }
771
- expectIso8601UtcTimestamp(record.resolvedAt, `${path}.resolvedAt`, issues);
772
- expectString(record.resolvedBy, `${path}.resolvedBy`, issues);
773
- }
774
- function validateCommentThreadMetadata(value, path, issues) {
775
- const record = asPlainObject(value, path, issues);
776
- if (!record) {
777
- return;
778
- }
779
- if (record.source !== void 0 && record.source !== "runtime" && record.source !== "import") {
780
- issues.push({
781
- path: `${path}.source`,
782
- message: "source must be either runtime or import."
783
- });
784
- }
785
- if (record.rootOoxmlCommentId !== void 0) {
786
- expectString(record.rootOoxmlCommentId, `${path}.rootOoxmlCommentId`, issues);
787
- }
788
- if (record.rootParaId !== void 0) {
789
- expectString(record.rootParaId, `${path}.rootParaId`, issues);
790
- }
791
- }
792
- function validateRevisionKind(value, path, issues) {
793
- if (value === "insertion" || value === "deletion" || value === "formatting" || value === "move" || value === "property-change") {
794
- return;
795
- }
796
- issues.push({
797
- path,
798
- message: "kind must be insertion, deletion, formatting, move, or property-change."
799
- });
800
- }
801
- function validateRevisionStatus(value, path, issues) {
802
- if (value === "open" || value === "accepted" || value === "rejected" || value === "detached") {
803
- return;
804
- }
805
- issues.push({
806
- path,
807
- message: "status must be one of open, accepted, rejected, or detached."
808
- });
809
- }
810
- function validateWarningIds(value, path, issues) {
811
- if (!Array.isArray(value)) {
812
- issues.push({
813
- path,
814
- message: "warningIds must be an array."
815
- });
816
- return;
817
- }
818
- value.forEach(
819
- (warningId, index) => expectDomainString(warningId, "warningId", `${path}[${index}]`, issues)
820
- );
821
- }
822
- function validateRevisionMetadata(value, path, issues) {
823
- const record = asPlainObject(value, path, issues);
824
- if (!record) {
825
- return;
826
- }
827
- if (record.source !== void 0 && record.source !== "runtime" && record.source !== "import") {
828
- issues.push({
829
- path: `${path}.source`,
830
- message: "source must be either runtime or import."
831
- });
832
- }
833
- for (const field of [
834
- "preserveOnlyReason",
835
- "importedRevisionForm",
836
- "originalRevisionType",
837
- "ooxmlRevisionId"
838
- ]) {
839
- if (record[field] !== void 0) {
840
- expectString(record[field], `${path}.${field}`, issues);
841
- }
842
- }
843
- if (record.propertyChangeData !== void 0) {
844
- const pcd = asPlainObject(record.propertyChangeData, `${path}.propertyChangeData`, issues);
845
- if (pcd) {
846
- expectString(pcd.xmlTag, `${path}.propertyChangeData.xmlTag`, issues);
847
- expectString(pcd.beforeXml, `${path}.propertyChangeData.beforeXml`, issues);
848
- }
849
- }
850
- if (record.moveData !== void 0) {
851
- const md = asPlainObject(record.moveData, `${path}.moveData`, issues);
852
- if (md) {
853
- expectString(md.moveId, `${path}.moveData.moveId`, issues);
854
- expectString(md.direction, `${path}.moveData.direction`, issues);
855
- }
856
- }
857
- }
858
- function validatePreservationStore(value, path, issues) {
859
- const record = asPlainObject(value, path, issues);
860
- if (!record) {
861
- return;
862
- }
863
- const opaqueFragments = asPlainObject(
864
- record.opaqueFragments,
865
- `${path}.opaqueFragments`,
866
- issues
867
- );
868
- if (opaqueFragments) {
869
- for (const [fragmentId, fragment] of Object.entries(opaqueFragments)) {
870
- expectDomainString(fragmentId, "fragmentId", `${path}.opaqueFragments.${fragmentId}`, issues);
871
- const fragmentRecord = asPlainObject(
872
- fragment,
873
- `${path}.opaqueFragments.${fragmentId}`,
874
- issues
875
- );
876
- if (!fragmentRecord) {
877
- continue;
878
- }
879
- if (fragmentRecord.fragmentId !== fragmentId) {
880
- issues.push({
881
- path: `${path}.opaqueFragments.${fragmentId}.fragmentId`,
882
- message: "fragmentId must match the map key."
883
- });
884
- }
885
- validateRange(
886
- fragmentRecord.lastKnownRange,
887
- `${path}.opaqueFragments.${fragmentId}.lastKnownRange`,
888
- issues
889
- );
890
- expectDomainString(
891
- fragmentRecord.warningId,
892
- "warningId",
893
- `${path}.opaqueFragments.${fragmentId}.warningId`,
894
- issues
895
- );
896
- if (fragmentRecord.packagePartName !== void 0) {
897
- expectDomainString(
898
- fragmentRecord.packagePartName,
899
- "packagePartName",
900
- `${path}.opaqueFragments.${fragmentId}.packagePartName`,
901
- issues
902
- );
903
- }
904
- if (fragmentRecord.relationshipId !== void 0) {
905
- expectDomainString(
906
- fragmentRecord.relationshipId,
907
- "relationshipId",
908
- `${path}.opaqueFragments.${fragmentId}.relationshipId`,
909
- issues
910
- );
911
- }
912
- }
913
- }
914
- const packageParts = asPlainObject(record.packageParts, `${path}.packageParts`, issues);
915
- if (packageParts) {
916
- for (const [packagePartName, packagePart] of Object.entries(packageParts)) {
917
- expectDomainString(
918
- packagePartName,
919
- "packagePartName",
920
- `${path}.packageParts.${packagePartName}`,
921
- issues
922
- );
923
- const packagePartRecord = asPlainObject(
924
- packagePart,
925
- `${path}.packageParts.${packagePartName}`,
926
- issues
927
- );
928
- if (!packagePartRecord) {
929
- continue;
930
- }
931
- if (packagePartRecord.packagePartName !== packagePartName) {
932
- issues.push({
933
- path: `${path}.packageParts.${packagePartName}.packagePartName`,
934
- message: "packagePartName must match the map key."
935
- });
936
- }
937
- if (Array.isArray(packagePartRecord.relationshipIds)) {
938
- packagePartRecord.relationshipIds.forEach(
939
- (relationshipId, index) => expectDomainString(
940
- relationshipId,
941
- "relationshipId",
942
- `${path}.packageParts.${packagePartName}.relationshipIds[${index}]`,
943
- issues
944
- )
945
- );
946
- }
947
- }
948
- }
949
- }
950
- function validateDiagnosticStore(value, path, issues) {
951
- const record = asPlainObject(value, path, issues);
952
- if (!record) {
953
- return;
954
- }
955
- if (Array.isArray(record.warnings)) {
956
- record.warnings.forEach((warning, index) => {
957
- const warningRecord = asPlainObject(warning, `${path}.warnings[${index}]`, issues);
958
- if (!warningRecord) {
959
- return;
960
- }
961
- expectDomainString(
962
- warningRecord.diagnosticId,
963
- "diagnosticId",
964
- `${path}.warnings[${index}].diagnosticId`,
965
- issues
966
- );
967
- expectDomainString(
968
- warningRecord.warningId,
969
- "warningId",
970
- `${path}.warnings[${index}].warningId`,
971
- issues
972
- );
973
- });
974
- }
975
- if (Array.isArray(record.errors)) {
976
- record.errors.forEach((error, index) => {
977
- const errorRecord = asPlainObject(error, `${path}.errors[${index}]`, issues);
978
- if (!errorRecord) {
979
- return;
980
- }
981
- expectDomainString(
982
- errorRecord.diagnosticId,
983
- "diagnosticId",
984
- `${path}.errors[${index}].diagnosticId`,
985
- issues
986
- );
987
- });
988
- }
989
- }
990
- function validateAnchor(value, path, issues) {
991
- const record = asPlainObject(value, path, issues);
992
- if (!record) {
993
- return;
994
- }
995
- const kind = expectString(record.kind, `${path}.kind`, issues);
996
- if (!kind) {
997
- return;
998
- }
999
- if (kind === "range") {
1000
- validateRange(record.range, `${path}.range`, issues);
1001
- validateBoundaryAssoc(record.assoc, `${path}.assoc`, issues);
1002
- } else if (kind === "node") {
1003
- if (typeof record.at !== "number") {
1004
- issues.push({
1005
- path: `${path}.at`,
1006
- message: "node anchors must contain a numeric at value."
1007
- });
1008
- }
1009
- if (record.assoc !== -1 && record.assoc !== 1) {
1010
- issues.push({
1011
- path: `${path}.assoc`,
1012
- message: "node anchor assoc must be -1 or 1."
1013
- });
1014
- }
1015
- } else if (kind === "detached") {
1016
- validateRange(record.lastKnownRange, `${path}.lastKnownRange`, issues);
1017
- if (record.reason !== "deleted" && record.reason !== "invalidatedByStructureChange" && record.reason !== "importAmbiguity") {
1018
- issues.push({
1019
- path: `${path}.reason`,
1020
- message: "detached anchor reason must be deleted, invalidatedByStructureChange, or importAmbiguity."
1021
- });
1022
- }
1023
- } else {
1024
- issues.push({
1025
- path: `${path}.kind`,
1026
- message: "anchor kind must be range, node, or detached."
1027
- });
1028
- }
1029
- }
1030
- function validateBoundaryAssoc(value, path, issues) {
1031
- const record = asPlainObject(value, path, issues);
1032
- if (!record) {
1033
- return;
1034
- }
1035
- if (record.start !== -1 && record.start !== 1) {
1036
- issues.push({
1037
- path: `${path}.start`,
1038
- message: "assoc.start must be -1 or 1."
1039
- });
1040
- }
1041
- if (record.end !== -1 && record.end !== 1) {
1042
- issues.push({
1043
- path: `${path}.end`,
1044
- message: "assoc.end must be -1 or 1."
1045
- });
1046
- }
1047
- }
1048
- function validateDocumentReferences(record, issues) {
1049
- const paragraphStyleIds = new Set(
1050
- Object.keys(asPlainObject(asPlainObject(record.styles, "$.styles", [])?.paragraphs, "$.styles.paragraphs", []) ?? {})
1051
- );
1052
- const numberingInstanceIds = new Set(
1053
- Object.keys(asPlainObject(asPlainObject(record.numbering, "$.numbering", [])?.instances, "$.numbering.instances", []) ?? {})
1054
- );
1055
- const abstractNumberingIds = new Set(
1056
- Object.keys(asPlainObject(asPlainObject(record.numbering, "$.numbering", [])?.abstractDefinitions, "$.numbering.abstractDefinitions", []) ?? {})
1057
- );
1058
- const mediaIds = new Set(
1059
- Object.keys(asPlainObject(asPlainObject(record.media, "$.media", [])?.items, "$.media.items", []) ?? {})
1060
- );
1061
- const warningIds = new Set(
1062
- (Array.isArray(asPlainObject(record.diagnostics, "$.diagnostics", [])?.warnings) ? asPlainObject(record.diagnostics, "$.diagnostics", [])?.warnings : []).flatMap((warning) => typeof warning.warningId === "string" ? [warning.warningId] : [])
1063
- );
1064
- const fragmentIds = new Set(
1065
- Object.keys(asPlainObject(asPlainObject(record.preservation, "$.preservation", [])?.opaqueFragments, "$.preservation.opaqueFragments", []) ?? {})
1066
- );
1067
- const noteIds = collectNoteIds(record);
1068
- const numberingInstances = asPlainObject(
1069
- asPlainObject(record.numbering, "$.numbering", [])?.instances,
1070
- "$.numbering.instances",
1071
- []
1072
- );
1073
- if (numberingInstances) {
1074
- for (const [instanceId, instance] of Object.entries(numberingInstances)) {
1075
- const instanceRecord = asPlainObject(instance, `$.numbering.instances.${instanceId}`, []);
1076
- if (instanceRecord && typeof instanceRecord.abstractNumberingId === "string" && !abstractNumberingIds.has(instanceRecord.abstractNumberingId)) {
1077
- issues.push({
1078
- path: `$.numbering.instances.${instanceId}.abstractNumberingId`,
1079
- message: "abstractNumberingId must reference an existing abstract numbering definition."
1080
- });
1081
- }
1082
- }
1083
- }
1084
- validateDocumentNodeReferences(record.content, "$.content", issues, {
1085
- paragraphStyleIds,
1086
- numberingInstanceIds,
1087
- mediaIds,
1088
- warningIds,
1089
- fragmentIds,
1090
- noteIds
1091
- });
1092
- validateSubPartReferences(record.subParts, "$.subParts", issues, {
1093
- paragraphStyleIds,
1094
- numberingInstanceIds,
1095
- mediaIds,
1096
- warningIds,
1097
- fragmentIds,
1098
- noteIds
1099
- });
1100
- validateReviewReferences(record.review, "$.review", issues, warningIds);
1101
- }
1102
- function validateDocumentNodeReferences(value, path, issues, references) {
1103
- const record = asPlainObject(value, path, issues);
1104
- if (!record) {
1105
- return;
1106
- }
1107
- const type = typeof record.type === "string" ? record.type : void 0;
1108
- if (type === "paragraph") {
1109
- if (typeof record.styleId === "string" && !references.paragraphStyleIds.has(record.styleId)) {
1110
- issues.push({
1111
- path: `${path}.styleId`,
1112
- message: "styleId must reference an existing paragraph style definition."
1113
- });
1114
- }
1115
- const numbering = asPlainObject(record.numbering, `${path}.numbering`, []);
1116
- if (numbering && typeof numbering.numberingInstanceId === "string" && !references.numberingInstanceIds.has(numbering.numberingInstanceId)) {
1117
- issues.push({
1118
- path: `${path}.numbering.numberingInstanceId`,
1119
- message: "numberingInstanceId must reference an existing numbering instance."
1120
- });
1121
- }
1122
- } else if (type === "image") {
1123
- if (typeof record.mediaId === "string" && !references.mediaIds.has(record.mediaId)) {
1124
- issues.push({
1125
- path: `${path}.mediaId`,
1126
- message: "mediaId must reference an existing media catalog item."
1127
- });
1128
- }
1129
- } else if (type === "opaque_inline" || type === "opaque_block") {
1130
- if (typeof record.fragmentId === "string" && !references.fragmentIds.has(record.fragmentId)) {
1131
- issues.push({
1132
- path: `${path}.fragmentId`,
1133
- message: "fragmentId must reference an existing opaque fragment."
1134
- });
1135
- }
1136
- if (typeof record.warningId === "string" && !references.warningIds.has(record.warningId)) {
1137
- issues.push({
1138
- path: `${path}.warningId`,
1139
- message: "warningId must reference an existing diagnostic warning."
1140
- });
1141
- }
1142
- } else if (type === "footnote_ref") {
1143
- if (typeof record.noteId === "string" && !references.noteIds.has(`${record.noteKind}:${record.noteId}`)) {
1144
- issues.push({
1145
- path: `${path}.noteId`,
1146
- message: "noteId must reference an existing footnote or endnote definition."
1147
- });
1148
- }
1149
- }
1150
- if (Array.isArray(record.children)) {
1151
- record.children.forEach(
1152
- (child, index) => validateDocumentNodeReferences(child, `${path}.children[${index}]`, issues, references)
1153
- );
1154
- }
1155
- if (Array.isArray(record.rows)) {
1156
- record.rows.forEach(
1157
- (row, index) => validateDocumentNodeReferences(row, `${path}.rows[${index}]`, issues, references)
1158
- );
1159
- }
1160
- if (Array.isArray(record.cells)) {
1161
- record.cells.forEach(
1162
- (cell, index) => validateDocumentNodeReferences(cell, `${path}.cells[${index}]`, issues, references)
1163
- );
1164
- }
1165
- }
1166
- function validateReviewReferences(value, path, issues, warningIds) {
1167
- const record = asPlainObject(value, path, issues);
1168
- if (!record) {
1169
- return;
1170
- }
1171
- const comments = asPlainObject(record.comments, `${path}.comments`, []);
1172
- if (comments) {
1173
- for (const [commentId, thread] of Object.entries(comments)) {
1174
- const threadRecord = asPlainObject(thread, `${path}.comments.${commentId}`, []);
1175
- if (!threadRecord || !Array.isArray(threadRecord.warningIds)) {
1176
- continue;
1177
- }
1178
- threadRecord.warningIds.forEach((warningId, index) => {
1179
- if (typeof warningId === "string" && !warningIds.has(warningId)) {
1180
- issues.push({
1181
- path: `${path}.comments.${commentId}.warningIds[${index}]`,
1182
- message: "warningIds must reference existing diagnostic warnings."
1183
- });
1184
- }
1185
- });
1186
- }
1187
- }
1188
- const revisions = asPlainObject(record.revisions, `${path}.revisions`, []);
1189
- if (revisions) {
1190
- for (const [revisionId, revision] of Object.entries(revisions)) {
1191
- const revisionRecord = asPlainObject(revision, `${path}.revisions.${revisionId}`, []);
1192
- if (!revisionRecord || !Array.isArray(revisionRecord.warningIds)) {
1193
- continue;
1194
- }
1195
- revisionRecord.warningIds.forEach((warningId, index) => {
1196
- if (typeof warningId === "string" && !warningIds.has(warningId)) {
1197
- issues.push({
1198
- path: `${path}.revisions.${revisionId}.warningIds[${index}]`,
1199
- message: "warningIds must reference existing diagnostic warnings."
1200
- });
1201
- }
1202
- });
1203
- }
1204
- }
1205
- }
1206
- function validateSubPartReferences(value, path, issues, references) {
1207
- if (value === void 0) {
1208
- return;
1209
- }
1210
- const record = asPlainObject(value, path, issues);
1211
- if (!record) {
1212
- return;
1213
- }
1214
- const headers = Array.isArray(record.headers) ? record.headers : [];
1215
- headers.forEach((header, index) => {
1216
- const headerRecord = asPlainObject(header, `${path}.headers[${index}]`, []);
1217
- if (!headerRecord || !Array.isArray(headerRecord.blocks)) {
1218
- return;
1219
- }
1220
- headerRecord.blocks.forEach(
1221
- (block, blockIndex) => validateDocumentNodeReferences(block, `${path}.headers[${index}].blocks[${blockIndex}]`, issues, references)
1222
- );
1223
- });
1224
- const footers = Array.isArray(record.footers) ? record.footers : [];
1225
- footers.forEach((footer, index) => {
1226
- const footerRecord = asPlainObject(footer, `${path}.footers[${index}]`, []);
1227
- if (!footerRecord || !Array.isArray(footerRecord.blocks)) {
1228
- return;
1229
- }
1230
- footerRecord.blocks.forEach(
1231
- (block, blockIndex) => validateDocumentNodeReferences(block, `${path}.footers[${index}].blocks[${blockIndex}]`, issues, references)
1232
- );
1233
- });
1234
- if (record.footnoteCollection !== void 0) {
1235
- const footnoteCollection = asPlainObject(record.footnoteCollection, `${path}.footnoteCollection`, []);
1236
- const footnotes = asPlainObject(footnoteCollection?.footnotes, `${path}.footnoteCollection.footnotes`, []);
1237
- if (footnotes) {
1238
- for (const [noteId, note] of Object.entries(footnotes)) {
1239
- const noteRecord = asPlainObject(note, `${path}.footnoteCollection.footnotes.${noteId}`, []);
1240
- if (!noteRecord || !Array.isArray(noteRecord.blocks)) {
1241
- continue;
1242
- }
1243
- noteRecord.blocks.forEach(
1244
- (block, blockIndex) => validateDocumentNodeReferences(
1245
- block,
1246
- `${path}.footnoteCollection.footnotes.${noteId}.blocks[${blockIndex}]`,
1247
- issues,
1248
- references
1249
- )
1250
- );
1251
- }
1252
- }
1253
- const endnotes = asPlainObject(footnoteCollection?.endnotes, `${path}.footnoteCollection.endnotes`, []);
1254
- if (endnotes) {
1255
- for (const [noteId, note] of Object.entries(endnotes)) {
1256
- const noteRecord = asPlainObject(note, `${path}.footnoteCollection.endnotes.${noteId}`, []);
1257
- if (!noteRecord || !Array.isArray(noteRecord.blocks)) {
1258
- continue;
1259
- }
1260
- noteRecord.blocks.forEach(
1261
- (block, blockIndex) => validateDocumentNodeReferences(
1262
- block,
1263
- `${path}.footnoteCollection.endnotes.${noteId}.blocks[${blockIndex}]`,
1264
- issues,
1265
- references
1266
- )
1267
- );
1268
- }
1269
- }
1270
- }
1271
- }
1272
- function collectNoteIds(record) {
1273
- const noteIds = /* @__PURE__ */ new Set();
1274
- const subParts = asPlainObject(record.subParts, "$.subParts", []);
1275
- const footnoteCollection = asPlainObject(subParts?.footnoteCollection, "$.subParts.footnoteCollection", []);
1276
- const footnotes = asPlainObject(footnoteCollection?.footnotes, "$.subParts.footnoteCollection.footnotes", []);
1277
- if (footnotes) {
1278
- Object.keys(footnotes).forEach((noteId) => noteIds.add(`footnote:${noteId}`));
1279
- }
1280
- const endnotes = asPlainObject(footnoteCollection?.endnotes, "$.subParts.footnoteCollection.endnotes", []);
1281
- if (endnotes) {
1282
- Object.keys(endnotes).forEach((noteId) => noteIds.add(`endnote:${noteId}`));
1283
- }
1284
- return noteIds;
1285
- }
1286
- function validateRange(value, path, issues) {
1287
- const record = asPlainObject(value, path, issues);
1288
- if (!record) {
1289
- return;
1290
- }
1291
- if (typeof record.from !== "number" || typeof record.to !== "number") {
1292
- issues.push({
1293
- path,
1294
- message: "Range must contain numeric from and to values."
1295
- });
1296
- }
1297
- }
1298
- function validateExactObjectKeys(record, expectedKeys, path, issues, allowedOptionalKeys) {
1299
- const actualKeys = new Set(Object.keys(record));
1300
- const expected = new Set(expectedKeys);
1301
- const optional = new Set(allowedOptionalKeys ?? []);
1302
- for (const expectedKey of expectedKeys) {
1303
- if (!actualKeys.has(expectedKey)) {
1304
- issues.push({
1305
- path,
1306
- message: `Missing required key ${JSON.stringify(expectedKey)}.`
1307
- });
1308
- }
1309
- }
1310
- for (const actualKey of actualKeys) {
1311
- if (!expected.has(actualKey) && !optional.has(actualKey)) {
1312
- issues.push({
1313
- path: `${path}.${actualKey}`,
1314
- message: "Unexpected canonical document key. Render/UI state is not part of the canonical envelope."
1315
- });
1316
- }
1317
- }
1318
- }
1319
- function validateSubPartsCatalog(value, path, issues) {
1320
- if (value === void 0) {
1321
- return;
1322
- }
1323
- const record = asPlainObject(value, path, issues);
1324
- if (!record) {
1325
- return;
1326
- }
1327
- if (record.headers !== void 0) {
1328
- if (!Array.isArray(record.headers)) {
1329
- issues.push({ path: `${path}.headers`, message: "headers must be an array." });
1330
- } else {
1331
- record.headers.forEach((header, index) => {
1332
- const headerRecord = asPlainObject(header, `${path}.headers[${index}]`, issues);
1333
- if (headerRecord) {
1334
- expectString(headerRecord.variant, `${path}.headers[${index}].variant`, issues);
1335
- expectString(headerRecord.partPath, `${path}.headers[${index}].partPath`, issues);
1336
- expectString(headerRecord.relationshipId, `${path}.headers[${index}].relationshipId`, issues);
1337
- if (!Array.isArray(headerRecord.blocks)) {
1338
- issues.push({ path: `${path}.headers[${index}].blocks`, message: "blocks must be an array." });
1339
- } else {
1340
- headerRecord.blocks.forEach(
1341
- (block, blockIndex) => validateDocumentNode(block, `${path}.headers[${index}].blocks[${blockIndex}]`, issues)
1342
- );
1343
- }
1344
- }
1345
- });
1346
- }
1347
- }
1348
- if (record.footers !== void 0) {
1349
- if (!Array.isArray(record.footers)) {
1350
- issues.push({ path: `${path}.footers`, message: "footers must be an array." });
1351
- } else {
1352
- record.footers.forEach((footer, index) => {
1353
- const footerRecord = asPlainObject(footer, `${path}.footers[${index}]`, issues);
1354
- if (footerRecord) {
1355
- expectString(footerRecord.variant, `${path}.footers[${index}].variant`, issues);
1356
- expectString(footerRecord.partPath, `${path}.footers[${index}].partPath`, issues);
1357
- expectString(footerRecord.relationshipId, `${path}.footers[${index}].relationshipId`, issues);
1358
- if (!Array.isArray(footerRecord.blocks)) {
1359
- issues.push({ path: `${path}.footers[${index}].blocks`, message: "blocks must be an array." });
1360
- } else {
1361
- footerRecord.blocks.forEach(
1362
- (block, blockIndex) => validateDocumentNode(block, `${path}.footers[${index}].blocks[${blockIndex}]`, issues)
1363
- );
1364
- }
1365
- }
1366
- });
1367
- }
1368
- }
1369
- if (record.footnoteCollection !== void 0) {
1370
- const footnoteCollection = asPlainObject(record.footnoteCollection, `${path}.footnoteCollection`, issues);
1371
- if (footnoteCollection) {
1372
- validateSubPartNoteMap(footnoteCollection.footnotes, "footnote", `${path}.footnoteCollection.footnotes`, issues);
1373
- validateSubPartNoteMap(footnoteCollection.endnotes, "endnote", `${path}.footnoteCollection.endnotes`, issues);
1374
- }
1375
- }
1376
- }
1377
- function validateSubPartNoteMap(value, expectedKind, path, issues) {
1378
- const record = asPlainObject(value, path, issues);
1379
- if (!record) {
1380
- return;
1381
- }
1382
- for (const [noteId, note] of Object.entries(record)) {
1383
- const noteRecord = asPlainObject(note, `${path}.${noteId}`, issues);
1384
- if (!noteRecord) {
1385
- continue;
1386
- }
1387
- expectString(noteRecord.noteId, `${path}.${noteId}.noteId`, issues);
1388
- if (noteRecord.noteId !== noteId) {
1389
- issues.push({
1390
- path: `${path}.${noteId}.noteId`,
1391
- message: "noteId must match the map key."
1392
- });
1393
- }
1394
- if (noteRecord.kind !== expectedKind) {
1395
- issues.push({
1396
- path: `${path}.${noteId}.kind`,
1397
- message: `kind must be ${expectedKind}.`
1398
- });
1399
- }
1400
- if (!Array.isArray(noteRecord.blocks)) {
1401
- issues.push({ path: `${path}.${noteId}.blocks`, message: "blocks must be an array." });
1402
- } else {
1403
- noteRecord.blocks.forEach(
1404
- (block, blockIndex) => validateDocumentNode(block, `${path}.${noteId}.blocks[${blockIndex}]`, issues)
1405
- );
1406
- }
1407
- }
1408
- }
1409
- function expectDomainString(value, domain, path, issues) {
1410
- const stableId = expectString(value, path, issues);
1411
- if (!stableId) {
1412
- return null;
1413
- }
1414
- if (!ID_PATTERNS[domain].test(stableId)) {
1415
- issues.push({
1416
- path,
1417
- message: `Expected a valid ${domain}.`
1418
- });
1419
- return null;
1420
- }
1421
- return stableId;
1422
- }
1423
-
1424
- // src/model/snapshot.ts
1425
- var SNAPSHOT_REQUIRED_TOP_LEVEL_KEYS = [
1426
- "snapshotVersion",
1427
- "schemaVersion",
1428
- "documentId",
1429
- "docId",
1430
- "createdAt",
1431
- "updatedAt",
1432
- "savedAt",
1433
- "editorBuild",
1434
- "canonicalDocument",
1435
- "compatibility",
1436
- "warningLog"
1437
- ];
1438
- var SNAPSHOT_OPTIONAL_TOP_LEVEL_KEYS = ["sourcePackage", "protectionSnapshot"];
1439
- var PERSISTED_EDITOR_SNAPSHOT_VERSIONS = /* @__PURE__ */ new Set([
1440
- LEGACY_PERSISTED_EDITOR_SNAPSHOT_VERSION,
1441
- PERSISTED_EDITOR_SNAPSHOT_VERSION
1442
- ]);
1443
- var DOCX_SOURCE_PACKAGE_MIME_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
1444
- var COMPATIBILITY_FEATURE_CLASSES = /* @__PURE__ */ new Set([
1445
- "supported-roundtrip",
1446
- "preserve-only",
1447
- "unsupported-fatal"
1448
- ]);
1449
- var EDITOR_WARNING_CODES = /* @__PURE__ */ new Set([
1450
- "unsupported_ooxml_preserved",
1451
- "unsupported_ooxml_locked",
1452
- "import_normalized",
1453
- "export_roundtrip_risk",
1454
- "comment_anchor_detached",
1455
- "revision_anchor_detached",
1456
- "large_document_degraded",
1457
- "font_substitution",
1458
- "image_missing"
1459
- ]);
1460
- var EDITOR_WARNING_SEVERITIES = /* @__PURE__ */ new Set(["info", "warning"]);
1461
- var EDITOR_WARNING_SOURCES = /* @__PURE__ */ new Set([
1462
- "import",
1463
- "runtime",
1464
- "review",
1465
- "preservation",
1466
- "validation",
1467
- "export"
1468
- ]);
1469
- var EDITOR_ERROR_CODES = /* @__PURE__ */ new Set([
1470
- "import_failed",
1471
- "export_failed",
1472
- "package_corrupt",
1473
- "validation_failed",
1474
- "datastore_failed",
1475
- "internal_invariant"
1476
- ]);
1477
- var EDITOR_ERROR_SOURCES = /* @__PURE__ */ new Set([
1478
- "import",
1479
- "runtime",
1480
- "validation",
1481
- "datastore",
1482
- "host",
1483
- "export"
1484
- ]);
1485
- function assertPersistedEditorSnapshot(snapshot) {
1486
- const issues = validatePersistedEditorSnapshot(snapshot);
1487
- assertValid(issues, "Invalid persisted editor snapshot.");
1488
- }
1489
- function validatePersistedEditorSnapshot(snapshot) {
1490
- const issues = [];
1491
- const record = asPlainObject(snapshot, "$", issues);
1492
- if (!record) {
1493
- return issues;
1494
- }
1495
- validateExactObjectKeys2(
1496
- record,
1497
- SNAPSHOT_REQUIRED_TOP_LEVEL_KEYS,
1498
- SNAPSHOT_OPTIONAL_TOP_LEVEL_KEYS,
1499
- "$",
1500
- issues
1501
- );
1502
- validateSnapshotVersion(record.snapshotVersion, "$.snapshotVersion", issues);
1503
- expectExactString(
1504
- record.schemaVersion,
1505
- CDS_SCHEMA_VERSION,
1506
- "$.schemaVersion",
1507
- issues
1508
- );
1509
- expectString(record.documentId, "$.documentId", issues);
1510
- expectString(record.docId, "$.docId", issues);
1511
- expectIso8601UtcTimestamp(record.createdAt, "$.createdAt", issues);
1512
- expectIso8601UtcTimestamp(record.updatedAt, "$.updatedAt", issues);
1513
- expectIso8601UtcTimestamp(record.savedAt, "$.savedAt", issues);
1514
- expectString(record.editorBuild, "$.editorBuild", issues);
1515
- const canonicalDocumentIssues = validateCanonicalDocument(record.canonicalDocument);
1516
- issues.push(...canonicalDocumentIssues.map(prefixIssue("$.canonicalDocument")));
1517
- if (asPlainObject(record.canonicalDocument, "$.canonicalDocument", [])?.docId !== record.docId) {
1518
- issues.push({
1519
- path: "$.docId",
1520
- message: "Snapshot docId must match canonicalDocument.docId."
1521
- });
1522
- }
1523
- validateCompatibilityReport(record.compatibility, "$.compatibility", issues);
1524
- if (!Array.isArray(record.warningLog)) {
1525
- issues.push({
1526
- path: "$.warningLog",
1527
- message: "warningLog must be an array."
1528
- });
1529
- } else {
1530
- record.warningLog.forEach((warning, index) => {
1531
- validateEditorWarning(warning, `$.warningLog[${index}]`, issues);
1532
- });
1533
- }
1534
- if (record.sourcePackage !== void 0) {
1535
- validatePersistedSourcePackage(record.sourcePackage, "$.sourcePackage", issues);
1536
- }
1537
- if (record.protectionSnapshot !== void 0) {
1538
- validateProtectionSnapshot(record.protectionSnapshot, "$.protectionSnapshot", issues);
1539
- }
1540
- return issues;
1541
- }
1542
- function assertCompatibilityReport(report) {
1543
- const issues = validateCompatibilityReport(report);
1544
- assertValid(issues, "Invalid compatibility report.");
1545
- }
1546
- function validateCompatibilityReport(report, path = "$", issues = []) {
1547
- const record = asPlainObject(report, path, issues);
1548
- if (!record) {
1549
- return issues;
1550
- }
1551
- expectExactString(
1552
- record.reportVersion,
1553
- COMPATIBILITY_REPORT_VERSION,
1554
- `${path}.reportVersion`,
1555
- issues
1556
- );
1557
- expectIso8601UtcTimestamp(record.generatedAt, `${path}.generatedAt`, issues);
1558
- if (typeof record.blockExport !== "boolean") {
1559
- issues.push({
1560
- path: `${path}.blockExport`,
1561
- message: "blockExport must be a boolean."
1562
- });
1563
- }
1564
- if (!Array.isArray(record.featureEntries)) {
1565
- issues.push({
1566
- path: `${path}.featureEntries`,
1567
- message: "featureEntries must be an array."
1568
- });
1569
- } else {
1570
- record.featureEntries.forEach((featureEntry, index) => {
1571
- validateCompatibilityFeatureEntry(
1572
- featureEntry,
1573
- `${path}.featureEntries[${index}]`,
1574
- issues
1575
- );
1576
- });
1577
- }
1578
- if (!Array.isArray(record.warnings)) {
1579
- issues.push({
1580
- path: `${path}.warnings`,
1581
- message: "warnings must be an array."
1582
- });
1583
- } else {
1584
- record.warnings.forEach((warning, index) => {
1585
- validateEditorWarning(warning, `${path}.warnings[${index}]`, issues);
1586
- });
1587
- }
1588
- if (!Array.isArray(record.errors)) {
1589
- issues.push({
1590
- path: `${path}.errors`,
1591
- message: "errors must be an array."
1592
- });
1593
- } else {
1594
- record.errors.forEach((error, index) => {
1595
- validateEditorError(error, `${path}.errors[${index}]`, issues);
1596
- });
1597
- }
1598
- return issues;
1599
- }
1600
- function validateCompatibilityFeatureEntry(featureEntry, path, issues) {
1601
- const record = asPlainObject(featureEntry, path, issues);
1602
- if (!record) {
1603
- return;
1604
- }
1605
- expectString(record.featureEntryId, `${path}.featureEntryId`, issues);
1606
- expectString(record.featureKey, `${path}.featureKey`, issues);
1607
- if (typeof record.featureClass !== "string" || !COMPATIBILITY_FEATURE_CLASSES.has(record.featureClass)) {
1608
- issues.push({
1609
- path: `${path}.featureClass`,
1610
- message: "featureClass must be supported-roundtrip, preserve-only, or unsupported-fatal."
1611
- });
1612
- }
1613
- expectString(record.message, `${path}.message`, issues);
1614
- }
1615
- function validateEditorWarning(warning, path, issues) {
1616
- const record = asPlainObject(warning, path, issues);
1617
- if (!record) {
1618
- return;
1619
- }
1620
- expectString(record.warningId, `${path}.warningId`, issues);
1621
- if (typeof record.code !== "string" || !EDITOR_WARNING_CODES.has(record.code)) {
1622
- issues.push({
1623
- path: `${path}.code`,
1624
- message: `code must be one of ${JSON.stringify([...EDITOR_WARNING_CODES])}.`
1625
- });
1626
- }
1627
- if (typeof record.severity !== "string" || !EDITOR_WARNING_SEVERITIES.has(record.severity)) {
1628
- issues.push({
1629
- path: `${path}.severity`,
1630
- message: "severity must be info or warning."
1631
- });
1632
- }
1633
- expectString(record.message, `${path}.message`, issues);
1634
- if (typeof record.source !== "string" || !EDITOR_WARNING_SOURCES.has(record.source)) {
1635
- issues.push({
1636
- path: `${path}.source`,
1637
- message: `source must be one of ${JSON.stringify([...EDITOR_WARNING_SOURCES])}.`
1638
- });
1639
- }
1640
- }
1641
- function validateEditorError(error, path, issues) {
1642
- const record = asPlainObject(error, path, issues);
1643
- if (!record) {
1644
- return;
1645
- }
1646
- expectString(record.errorId, `${path}.errorId`, issues);
1647
- if (typeof record.code !== "string" || !EDITOR_ERROR_CODES.has(record.code)) {
1648
- issues.push({
1649
- path: `${path}.code`,
1650
- message: `code must be one of ${JSON.stringify([...EDITOR_ERROR_CODES])}.`
1651
- });
1652
- }
1653
- expectString(record.message, `${path}.message`, issues);
1654
- if (typeof record.source !== "string" || !EDITOR_ERROR_SOURCES.has(record.source)) {
1655
- issues.push({
1656
- path: `${path}.source`,
1657
- message: `source must be one of ${JSON.stringify([...EDITOR_ERROR_SOURCES])}.`
1658
- });
1659
- }
1660
- if (typeof record.isFatal !== "boolean") {
1661
- issues.push({
1662
- path: `${path}.isFatal`,
1663
- message: "isFatal must be a boolean."
1664
- });
1665
- }
1666
- }
1667
- function validateExactObjectKeys2(record, requiredKeys, optionalKeys, path, issues) {
1668
- const actualKeys = new Set(Object.keys(record));
1669
- const allowedKeys = /* @__PURE__ */ new Set([...requiredKeys, ...optionalKeys]);
1670
- for (const requiredKey of requiredKeys) {
1671
- if (!actualKeys.has(requiredKey)) {
1672
- issues.push({
1673
- path,
1674
- message: `Missing required key ${JSON.stringify(requiredKey)}.`
1675
- });
1676
- }
1677
- }
1678
- for (const actualKey of actualKeys) {
1679
- if (!allowedKeys.has(actualKey)) {
1680
- issues.push({
1681
- path: `${path}.${actualKey}`,
1682
- message: "Unexpected persisted snapshot key. Render/UI state is not part of the persistence contract."
1683
- });
1684
- }
1685
- }
1686
- }
1687
- function prefixIssue(basePath) {
1688
- return (issue) => ({
1689
- path: `${basePath}${issue.path === "$" ? "" : issue.path.slice(1)}`,
1690
- message: issue.message
1691
- });
1692
- }
1693
- function validateSnapshotVersion(value, path, issues) {
1694
- if (typeof value !== "string" || !PERSISTED_EDITOR_SNAPSHOT_VERSIONS.has(value)) {
1695
- issues.push({
1696
- path,
1697
- message: `Expected one of ${JSON.stringify([...PERSISTED_EDITOR_SNAPSHOT_VERSIONS])}.`
1698
- });
1699
- return null;
1700
- }
1701
- return value;
1702
- }
1703
- function validatePersistedSourcePackage(sourcePackage, path, issues) {
1704
- const record = asPlainObject(sourcePackage, path, issues);
1705
- if (!record) {
1706
- return;
1707
- }
1708
- validateExactObjectKeys2(
1709
- record,
1710
- ["format", "storage", "mimeType", "sha256Hex", "bytesBase64"],
1711
- ["sourceLabel"],
1712
- path,
1713
- issues
1714
- );
1715
- expectExactString(record.format, "docx", `${path}.format`, issues);
1716
- expectExactString(record.storage, "embedded-base64", `${path}.storage`, issues);
1717
- expectExactString(
1718
- record.mimeType,
1719
- DOCX_SOURCE_PACKAGE_MIME_TYPE,
1720
- `${path}.mimeType`,
1721
- issues
1722
- );
1723
- expectString(record.sha256Hex, `${path}.sha256Hex`, issues);
1724
- expectString(record.bytesBase64, `${path}.bytesBase64`, issues);
1725
- if (typeof record.sha256Hex === "string" && !/^[0-9a-f]{64}$/u.test(record.sha256Hex)) {
1726
- issues.push({
1727
- path: `${path}.sha256Hex`,
1728
- message: "Expected a lowercase SHA-256 hex digest."
1729
- });
1730
- }
1731
- if (record.sourceLabel !== void 0) {
1732
- expectString(record.sourceLabel, `${path}.sourceLabel`, issues);
1733
- }
1734
- }
1735
- function createPersistedEditorSnapshot(params) {
1736
- assertCanonicalDocument(params.canonicalDocument);
1737
- assertCompatibilityReport(params.compatibility);
1738
- return {
1739
- snapshotVersion: PERSISTED_EDITOR_SNAPSHOT_VERSION,
1740
- schemaVersion: CDS_SCHEMA_VERSION,
1741
- documentId: params.documentId,
1742
- docId: params.canonicalDocument.docId,
1743
- createdAt: params.canonicalDocument.createdAt,
1744
- updatedAt: params.canonicalDocument.updatedAt,
1745
- savedAt: params.savedAt,
1746
- editorBuild: params.editorBuild,
1747
- canonicalDocument: params.canonicalDocument,
1748
- compatibility: params.compatibility,
1749
- warningLog: params.warningLog ?? params.compatibility.warnings,
1750
- protectionSnapshot: params.protectionSnapshot,
1751
- sourcePackage: params.sourcePackage
1752
- };
1753
- }
1754
- function validateProtectionSnapshot(value, path, issues) {
1755
- const record = asPlainObject(value, path, issues);
1756
- if (!record) {
1757
- return;
1758
- }
1759
- if (typeof record.hasDocumentProtection !== "boolean") {
1760
- issues.push({ path: `${path}.hasDocumentProtection`, message: "hasDocumentProtection must be a boolean." });
1761
- }
1762
- if (record.editType !== void 0) {
1763
- expectString(record.editType, `${path}.editType`, issues);
1764
- }
1765
- if (typeof record.enforcementActive !== "boolean") {
1766
- issues.push({ path: `${path}.enforcementActive`, message: "enforcementActive must be a boolean." });
1767
- }
1768
- if (!Array.isArray(record.ranges)) {
1769
- issues.push({ path: `${path}.ranges`, message: "ranges must be an array." });
1770
- } else {
1771
- record.ranges.forEach((range, index) => validateProtectionRange(range, `${path}.ranges[${index}]`, issues));
1772
- }
1773
- if (!Number.isInteger(record.enforcedRangeCount)) {
1774
- issues.push({ path: `${path}.enforcedRangeCount`, message: "enforcedRangeCount must be an integer." });
1775
- }
1776
- if (!Number.isInteger(record.preservedRangeCount)) {
1777
- issues.push({ path: `${path}.preservedRangeCount`, message: "preservedRangeCount must be an integer." });
1778
- }
1779
- }
1780
- function validateProtectionRange(value, path, issues) {
1781
- const record = asPlainObject(value, path, issues);
1782
- if (!record) {
1783
- return;
1784
- }
1785
- expectString(record.rangeId, `${path}.rangeId`, issues);
1786
- if (record.start !== void 0 && !Number.isInteger(record.start)) {
1787
- issues.push({ path: `${path}.start`, message: "start must be an integer." });
1788
- }
1789
- if (record.end !== void 0 && !Number.isInteger(record.end)) {
1790
- issues.push({ path: `${path}.end`, message: "end must be an integer." });
1791
- }
1792
- if (record.editorGroup !== void 0) {
1793
- expectString(record.editorGroup, `${path}.editorGroup`, issues);
1794
- }
1795
- if (record.editor !== void 0) {
1796
- expectString(record.editor, `${path}.editor`, issues);
1797
- }
1798
- if (typeof record.enforced !== "boolean") {
1799
- issues.push({ path: `${path}.enforced`, message: "enforced must be a boolean." });
1800
- }
1801
- expectString(record.enforcementReason, `${path}.enforcementReason`, issues);
1802
- }
1803
-
1804
- // src/core/state/editor-state.ts
1805
- function createEmptyReviewStore() {
1806
- return {
1807
- comments: {},
1808
- revisions: {}
1809
- };
1810
- }
1811
- function createDefaultCanonicalDocument(documentId, timestamp) {
1812
- return {
1813
- schemaVersion: "cds/1.0.0",
1814
- docId: createCanonicalDocumentId(documentId),
1815
- createdAt: timestamp,
1816
- updatedAt: timestamp,
1817
- metadata: {
1818
- customProperties: {}
1819
- },
1820
- styles: {
1821
- paragraphs: {},
1822
- characters: {},
1823
- tables: {}
1824
- },
1825
- numbering: {
1826
- abstractDefinitions: {},
1827
- instances: {}
1828
- },
1829
- media: {
1830
- items: {}
1831
- },
1832
- content: {
1833
- type: "doc",
1834
- children: [{ type: "paragraph", children: [] }]
1835
- },
1836
- review: createEmptyReviewStore(),
1837
- preservation: {
1838
- opaqueFragments: {},
1839
- packageParts: {}
1840
- },
1841
- diagnostics: {
1842
- warnings: [],
1843
- errors: []
1844
- }
1845
- };
1846
- }
1847
- function createSelectionSnapshot(anchor = 0, head = anchor) {
1848
- return {
1849
- anchor,
1850
- head,
1851
- isCollapsed: anchor === head,
1852
- activeRange: createRangeAnchor(anchor, head, DEFAULT_BOUNDARY_ASSOC)
1853
- };
1854
- }
1855
- function createEmptyCompatibilityReport(generatedAt) {
1856
- return {
1857
- reportVersion: "compatibility-report/1",
1858
- generatedAt,
1859
- blockExport: false,
1860
- featureEntries: [],
1861
- warnings: [],
1862
- errors: []
1863
- };
1864
- }
1865
- function createEditorState(options) {
1866
- const timestamp = (/* @__PURE__ */ new Date(0)).toISOString();
1867
- const normalizedSnapshot = options.persistedSnapshot ? normalizePersistedSnapshotForRuntime(options.persistedSnapshot, options.documentId, timestamp) : void 0;
1868
- if (options.canonicalDocument) {
1869
- assertCanonicalDocument(options.canonicalDocument);
1870
- }
1871
- const normalizedDocument = normalizedSnapshot ? structuredClone(normalizedSnapshot.canonicalDocument) : options.canonicalDocument ? structuredClone(options.canonicalDocument) : createDefaultCanonicalDocument(options.documentId, timestamp);
1872
- const warnings = normalizedSnapshot ? normalizeWarningLog(normalizedSnapshot.warningLog) : options.warnings ?? [];
1873
- const compatibility = normalizedSnapshot ? normalizeCompatibilityReport(normalizedSnapshot.compatibility) : options.compatibility ?? createEmptyCompatibilityReport(normalizedDocument.updatedAt);
1874
- return {
1875
- phase: options.fatalError ? "error" : "ready",
1876
- documentId: options.documentId,
1877
- sessionId: options.sessionId,
1878
- sourceLabel: options.sourceLabel,
1879
- sourcePackage: normalizedSnapshot?.sourcePackage,
1880
- revision: 0,
1881
- revisionToken: `${options.sessionId}:0`,
1882
- isDirty: false,
1883
- readOnly: options.readOnly ?? false,
1884
- document: normalizedDocument,
1885
- selection: createSelectionSnapshot(),
1886
- warnings,
1887
- compatibility,
1888
- fatalError: options.fatalError,
1889
- runtime: {
1890
- hasFocus: false
1891
- }
1892
- };
1893
- }
1894
- function normalizePersistedSnapshotForRuntime(snapshot, documentId, timestamp) {
1895
- const issues = validatePersistedEditorSnapshot(snapshot);
1896
- if (issues.length === 0) {
1897
- return snapshot;
1898
- }
1899
- if (!isRecord(snapshot) || !isRecord(snapshot.canonicalDocument)) {
1900
- assertPersistedEditorSnapshot(snapshot);
1901
- }
1902
- const normalizedDocument = normalizeCanonicalDocumentEnvelope(
1903
- snapshot.canonicalDocument,
1904
- documentId,
1905
- timestamp
1906
- );
1907
- try {
1908
- assertCanonicalDocument(normalizedDocument);
1909
- } catch {
1910
- assertPersistedEditorSnapshot(snapshot);
1911
- }
1912
- const repairWarning = createSnapshotRepairWarning(issues.length);
1913
- const compatibility = coerceCompatibilityReport(
1914
- snapshot.compatibility,
1915
- normalizedDocument.updatedAt,
1916
- repairWarning
1917
- );
1918
- return {
1919
- snapshotVersion: snapshot.snapshotVersion === "persisted-editor-snapshot/1" || snapshot.snapshotVersion === "persisted-editor-snapshot/2" ? snapshot.snapshotVersion : "persisted-editor-snapshot/2",
1920
- schemaVersion: "cds/1.0.0",
1921
- documentId: typeof snapshot.documentId === "string" && snapshot.documentId.length > 0 ? snapshot.documentId : documentId,
1922
- docId: normalizedDocument.docId,
1923
- createdAt: normalizedDocument.createdAt,
1924
- updatedAt: normalizedDocument.updatedAt,
1925
- savedAt: typeof snapshot.savedAt === "string" && snapshot.savedAt.length > 0 ? snapshot.savedAt : normalizedDocument.updatedAt,
1926
- editorBuild: typeof snapshot.editorBuild === "string" && snapshot.editorBuild.length > 0 ? snapshot.editorBuild : "dev",
1927
- canonicalDocument: normalizedDocument,
1928
- compatibility,
1929
- warningLog: dedupeWarnings([
1930
- ...coerceWarnings(snapshot.warningLog),
1931
- repairWarning
1932
- ]),
1933
- sourcePackage: snapshot.sourcePackage
1934
- };
1935
- }
1936
- function normalizeCanonicalDocumentEnvelope(value, documentId, timestamp) {
1937
- const base = createDefaultCanonicalDocument(documentId, timestamp);
1938
- const record = isRecord(value) ? value : {};
1939
- const metadata = isRecord(record.metadata) ? record.metadata : {};
1940
- return {
1941
- ...base,
1942
- ...record,
1943
- schemaVersion: "cds/1.0.0",
1944
- docId: isUuid(record.docId) ? record.docId : createCanonicalDocumentId(documentId),
1945
- createdAt: typeof record.createdAt === "string" && record.createdAt.length > 0 ? record.createdAt : base.createdAt,
1946
- updatedAt: typeof record.updatedAt === "string" && record.updatedAt.length > 0 ? record.updatedAt : base.updatedAt,
1947
- metadata: {
1948
- ...base.metadata,
1949
- ...metadata,
1950
- customProperties: isRecord(metadata.customProperties) ? Object.fromEntries(
1951
- Object.entries(metadata.customProperties).filter(([, entry]) => typeof entry === "string")
1952
- ) : {}
1953
- },
1954
- styles: record.styles === void 0 ? base.styles : record.styles,
1955
- numbering: record.numbering === void 0 ? base.numbering : record.numbering,
1956
- media: record.media === void 0 ? base.media : record.media,
1957
- content: isRecord(record.content) ? record.content : base.content,
1958
- review: record.review === void 0 ? base.review : record.review,
1959
- preservation: record.preservation === void 0 ? base.preservation : record.preservation,
1960
- diagnostics: record.diagnostics === void 0 ? base.diagnostics : record.diagnostics,
1961
- ...isRecord(record.subParts) ? { subParts: record.subParts } : {}
1962
- };
1963
- }
1964
- function coerceCompatibilityReport(value, generatedAt, repairWarning) {
1965
- const record = isRecord(value) ? value : {};
1966
- const warnings = dedupeWarnings([
1967
- ...coerceWarnings(record.warnings),
1968
- repairWarning
1969
- ]);
1970
- return {
1971
- reportVersion: "compatibility-report/1",
1972
- generatedAt: typeof record.generatedAt === "string" && record.generatedAt.length > 0 ? record.generatedAt : generatedAt,
1973
- blockExport: typeof record.blockExport === "boolean" ? record.blockExport : false,
1974
- featureEntries: Array.isArray(record.featureEntries) ? record.featureEntries.flatMap((entry) => {
1975
- if (!isRecord(entry)) {
1976
- return [];
1977
- }
1978
- if (typeof entry.featureEntryId !== "string" || typeof entry.featureKey !== "string" || typeof entry.featureClass !== "string" || typeof entry.message !== "string") {
1979
- return [];
1980
- }
1981
- return [{
1982
- featureEntryId: entry.featureEntryId,
1983
- featureKey: entry.featureKey,
1984
- featureClass: entry.featureClass,
1985
- message: entry.message,
1986
- ...entry.affectedAnchor && isRecord(entry.affectedAnchor) ? { affectedAnchor: entry.affectedAnchor } : {},
1987
- ...isRecord(entry.details) ? { details: entry.details } : {}
1988
- }];
1989
- }) : [],
1990
- warnings,
1991
- errors: Array.isArray(record.errors) ? record.errors.flatMap((entry) => {
1992
- if (!isRecord(entry)) {
1993
- return [];
1994
- }
1995
- if (typeof entry.errorId !== "string" || typeof entry.code !== "string" || typeof entry.message !== "string" || typeof entry.source !== "string" || typeof entry.isFatal !== "boolean") {
1996
- return [];
1997
- }
1998
- return [{
1999
- errorId: entry.errorId,
2000
- code: entry.code,
2001
- message: entry.message,
2002
- source: entry.source,
2003
- isFatal: entry.isFatal,
2004
- ...isRecord(entry.details) ? { details: entry.details } : {}
2005
- }];
2006
- }) : []
2007
- };
2008
- }
2009
- function coerceWarnings(value) {
2010
- if (!Array.isArray(value)) {
2011
- return [];
2012
- }
2013
- return value.flatMap((warning) => {
2014
- if (!isRecord(warning)) {
2015
- return [];
2016
- }
2017
- if (typeof warning.warningId !== "string" || typeof warning.code !== "string" || typeof warning.severity !== "string" || typeof warning.message !== "string" || typeof warning.source !== "string") {
2018
- return [];
2019
- }
2020
- return [{
2021
- warningId: warning.warningId,
2022
- code: warning.code,
2023
- severity: warning.severity,
2024
- message: warning.message,
2025
- source: warning.source,
2026
- ...warning.affectedAnchor && isRecord(warning.affectedAnchor) ? { affectedAnchor: warning.affectedAnchor } : {},
2027
- ...typeof warning.featureEntryId === "string" ? { featureEntryId: warning.featureEntryId } : {},
2028
- ...isRecord(warning.details) ? { details: warning.details } : {}
2029
- }];
2030
- });
2031
- }
2032
- function createSnapshotRepairWarning(issueCount) {
2033
- return {
2034
- warningId: `warning:snapshot-repair:${issueCount}`,
2035
- code: "import_normalized",
2036
- severity: "warning",
2037
- message: `Loaded a persisted snapshot after repairing ${issueCount} validation issue${issueCount === 1 ? "" : "s"}.`,
2038
- source: "validation"
2039
- };
2040
- }
2041
- function dedupeWarnings(warnings) {
2042
- const seen = /* @__PURE__ */ new Set();
2043
- const result = [];
2044
- for (const warning of warnings) {
2045
- if (!warning.warningId || seen.has(warning.warningId)) {
2046
- continue;
2047
- }
2048
- seen.add(warning.warningId);
2049
- result.push(warning);
2050
- }
2051
- return result;
2052
- }
2053
- function deriveDocumentStats(state) {
2054
- const serializedContent = extractText(state.document.content);
2055
- return {
2056
- paragraphCount: estimateParagraphCount(state.document.content),
2057
- wordCount: serializedContent.trim().length === 0 ? 0 : serializedContent.trim().split(/\s+/u).length,
2058
- characterCount: Array.from(serializedContent).length,
2059
- commentCount: Object.keys(state.document.review.comments).length,
2060
- revisionCount: Object.keys(state.document.review.revisions).length
2061
- };
2062
- }
2063
- function deriveRenderSnapshot(state, history) {
2064
- const comments = Object.values(state.document.review.comments).sort(
2065
- (left, right) => left.createdAt.localeCompare(right.createdAt)
2066
- );
2067
- const revisions = Object.values(state.document.review.revisions);
2068
- return {
2069
- documentId: state.documentId,
2070
- sessionId: state.sessionId,
2071
- sourceLabel: state.sourceLabel,
2072
- revisionToken: state.revisionToken,
2073
- isReady: state.phase === "ready",
2074
- isDirty: state.isDirty,
2075
- readOnly: state.readOnly,
2076
- selection: state.selection,
2077
- documentStats: deriveDocumentStats(state),
2078
- comments: {
2079
- activeCommentId: state.runtime.activeCommentId,
2080
- openThreadCount: comments.filter((comment) => comment.status === "open").length,
2081
- resolvedThreadCount: comments.filter((comment) => comment.status === "resolved").length,
2082
- threads: comments
2083
- },
2084
- trackedChanges: {
2085
- totalCount: revisions.length,
2086
- pendingCount: revisions.filter((revision) => revision.status === "open").length,
2087
- acceptedCount: revisions.filter((revision) => revision.status === "accepted").length,
2088
- rejectedCount: revisions.filter((revision) => revision.status === "rejected").length
2089
- },
2090
- compatibility: {
2091
- report: state.compatibility,
2092
- blockExport: state.compatibility.blockExport,
2093
- totalEntries: state.compatibility.featureEntries.length
2094
- },
2095
- warnings: state.warnings,
2096
- fatalError: state.fatalError,
2097
- commandState: {
2098
- canUndo: history.canUndo,
2099
- canRedo: history.canRedo,
2100
- canAddComment: !state.readOnly,
2101
- canAcceptAllChanges: revisions.some((revision) => revision.status === "open"),
2102
- canRejectAllChanges: revisions.some((revision) => revision.status === "open")
2103
- }
2104
- };
2105
- }
2106
- function createPersistedEditorSnapshot2(state, options) {
2107
- const snapshot = createPersistedEditorSnapshot({
2108
- documentId: state.documentId,
2109
- savedAt: options.savedAt,
2110
- editorBuild: options.editorBuild,
2111
- canonicalDocument: state.document,
2112
- compatibility: options.compatibility ?? state.compatibility,
2113
- warningLog: state.warnings,
2114
- protectionSnapshot: options.protectionSnapshot,
2115
- sourcePackage: state.sourcePackage
2116
- });
2117
- return snapshot;
2118
- }
2119
- function estimateParagraphCount(content) {
2120
- if (Array.isArray(content)) {
2121
- return content.length;
2122
- }
2123
- if (content && typeof content === "object" && Array.isArray(content.blocks)) {
2124
- return content.blocks.length;
2125
- }
2126
- return extractText(content).length > 0 ? 1 : 0;
2127
- }
2128
- function normalizeWarningLog(warnings) {
2129
- return warnings.map((warning) => ({
2130
- ...warning,
2131
- affectedAnchor: warning.affectedAnchor ? normalizeAnchorProjection(warning.affectedAnchor) : void 0
2132
- }));
2133
- }
2134
- function normalizeCompatibilityReport(report) {
2135
- return {
2136
- ...report,
2137
- featureEntries: report.featureEntries.map((entry) => ({
2138
- ...entry,
2139
- affectedAnchor: entry.affectedAnchor ? normalizeAnchorProjection(entry.affectedAnchor) : void 0
2140
- })),
2141
- warnings: normalizeWarningLog(report.warnings)
2142
- };
2143
- }
2144
- function normalizeAnchorProjection(anchor) {
2145
- switch (anchor.kind) {
2146
- case "range": {
2147
- const rangeAnchor = anchor;
2148
- return rangeAnchor.range ? createRangeAnchor(rangeAnchor.range.from, rangeAnchor.range.to, rangeAnchor.assoc) : createRangeAnchor(rangeAnchor.from ?? 0, rangeAnchor.to ?? 0, rangeAnchor.assoc);
2149
- }
2150
- case "node":
2151
- return createNodeAnchor(anchor.at, anchor.assoc);
2152
- case "detached":
2153
- return createDetachedAnchor(anchor.lastKnownRange, anchor.reason);
2154
- }
2155
- }
2156
- function extractText(value) {
2157
- if (typeof value === "string") {
2158
- return value;
2159
- }
2160
- if (Array.isArray(value)) {
2161
- return value.map((item) => extractText(item)).join(" ");
2162
- }
2163
- if (!value || typeof value !== "object") {
2164
- return "";
2165
- }
2166
- return Object.values(value).map((item) => extractText(item)).filter(Boolean).join(" ");
2167
- }
2168
- function isRecord(value) {
2169
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
2170
- }
2171
- function createCanonicalDocumentId(documentId) {
2172
- const hashWord = (seed) => {
2173
- let hash = 2166136261;
2174
- for (const char of seed) {
2175
- hash ^= char.charCodeAt(0);
2176
- hash = Math.imul(hash, 16777619);
2177
- }
2178
- return (hash >>> 0).toString(16).padStart(8, "0");
2179
- };
2180
- const raw = hashWord(`${documentId}:0`) + hashWord(`${documentId}:1`) + hashWord(`${documentId}:2`) + hashWord(`${documentId}:3`);
2181
- return [
2182
- raw.slice(0, 8),
2183
- raw.slice(8, 12),
2184
- `4${raw.slice(13, 16)}`,
2185
- `8${raw.slice(17, 20)}`,
2186
- raw.slice(20, 32)
2187
- ].join("-");
2188
- }
2189
- function normalizeCommentThreadRecord(value) {
2190
- const record = isRecord(value) ? value : {};
2191
- const authorId = typeof record.createdBy === "string" && record.createdBy.length > 0 ? record.createdBy : typeof record.authorId === "string" && record.authorId.length > 0 ? record.authorId : "unknown";
2192
- const createdAt = typeof record.createdAt === "string" && record.createdAt.length > 0 ? record.createdAt : (/* @__PURE__ */ new Date(0)).toISOString();
2193
- const entries = Array.isArray(record.entries) ? record.entries.filter((entry) => isRecord(entry)).map((entry, index) => ({
2194
- entryId: typeof entry.entryId === "string" && entry.entryId.length > 0 ? entry.entryId : `${String(record.commentId ?? "comment")}-entry-${index + 1}`,
2195
- authorId: typeof entry.authorId === "string" && entry.authorId.length > 0 ? entry.authorId : authorId,
2196
- body: typeof entry.body === "string" ? entry.body : "",
2197
- createdAt: typeof entry.createdAt === "string" && entry.createdAt.length > 0 ? entry.createdAt : createdAt,
2198
- metadata: isRecord(entry.metadata) ? {
2199
- ooxmlCommentId: typeof entry.metadata.ooxmlCommentId === "string" ? entry.metadata.ooxmlCommentId : void 0,
2200
- paraId: typeof entry.metadata.paraId === "string" ? entry.metadata.paraId : void 0,
2201
- parentParaId: typeof entry.metadata.parentParaId === "string" ? entry.metadata.parentParaId : void 0,
2202
- durableId: typeof entry.metadata.durableId === "string" ? entry.metadata.durableId : void 0,
2203
- initials: typeof entry.metadata.initials === "string" ? entry.metadata.initials : void 0
2204
- } : void 0
2205
- })) : [
2206
- {
2207
- entryId: `${String(record.commentId ?? "comment")}-entry-1`,
2208
- authorId,
2209
- body: typeof record.body === "string" ? record.body : "",
2210
- createdAt
2211
- }
2212
- ];
2213
- const resolution = isRecord(record.resolution) ? {
2214
- resolvedAt: typeof record.resolution.resolvedAt === "string" ? record.resolution.resolvedAt : typeof record.resolvedAt === "string" ? record.resolvedAt : createdAt,
2215
- resolvedBy: typeof record.resolution.resolvedBy === "string" && record.resolution.resolvedBy.length > 0 ? record.resolution.resolvedBy : authorId
2216
- } : typeof record.resolvedAt === "string" ? {
2217
- resolvedAt: record.resolvedAt,
2218
- resolvedBy: authorId
2219
- } : void 0;
2220
- const normalizedStatus = typeof record.status === "string" ? record.status : record.anchor && isRecord(record.anchor) && record.anchor.kind === "detached" ? "detached" : resolution || record.isResolved ? "resolved" : "open";
2221
- return {
2222
- commentId: typeof record.commentId === "string" && record.commentId.length > 0 ? record.commentId : "comment-generated",
2223
- anchor: isRecord(record.anchor) && typeof record.anchor.kind === "string" ? record.anchor : createDetachedAnchor({ from: 0, to: 0 }, "importAmbiguity"),
2224
- createdAt,
2225
- createdBy: authorId,
2226
- authorId,
2227
- body: entries.map((entry) => entry.body).join("\n"),
2228
- entries,
2229
- status: normalizedStatus === "resolved" || normalizedStatus === "detached" ? normalizedStatus : "open",
2230
- resolution,
2231
- resolvedAt: resolution?.resolvedAt,
2232
- warningIds: Array.isArray(record.warningIds) ? record.warningIds.filter((warningId) => typeof warningId === "string") : [],
2233
- isResolved: normalizedStatus === "resolved",
2234
- metadata: isRecord(record.metadata) ? {
2235
- source: record.metadata.source === "import" || record.metadata.source === "runtime" ? record.metadata.source : void 0,
2236
- rootOoxmlCommentId: typeof record.metadata.rootOoxmlCommentId === "string" ? record.metadata.rootOoxmlCommentId : void 0,
2237
- rootParaId: typeof record.metadata.rootParaId === "string" ? record.metadata.rootParaId : void 0
2238
- } : void 0
2239
- };
2240
- }
2241
-
2242
- export {
2243
- createCanonicalDocumentSignature,
2244
- projectCanonicalDocument,
2245
- validatePersistedEditorSnapshot,
2246
- createEmptyReviewStore,
2247
- createDefaultCanonicalDocument,
2248
- createSelectionSnapshot,
2249
- createEmptyCompatibilityReport,
2250
- createEditorState,
2251
- deriveDocumentStats,
2252
- deriveRenderSnapshot,
2253
- createPersistedEditorSnapshot2 as createPersistedEditorSnapshot,
2254
- createCanonicalDocumentId,
2255
- normalizeCommentThreadRecord
2256
- };
2257
- //# sourceMappingURL=chunk-5FN54NDH.js.map