@beyondwork/docx-react-component 1.0.29 → 1.0.31

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