@a3s-lab/office 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. package/COLLABORATION_ROADMAP.md +426 -0
  2. package/README.md +649 -10
  3. package/dist/0~1403.js +1 -1
  4. package/dist/0~2805.js +1279 -0
  5. package/dist/{0~use-office-draft.js → 0~345.js} +30 -1
  6. package/dist/0~3539.js +1 -1
  7. package/dist/0~3557.js +1 -1
  8. package/dist/0~3635.js +1 -1
  9. package/dist/0~4595.js +123 -12
  10. package/dist/0~4980.js +154 -0
  11. package/dist/0~5050.js +124 -113
  12. package/dist/{0~9512.js → 0~6090.js} +540 -3
  13. package/dist/0~7048.js +92 -66
  14. package/dist/0~7614.js +2 -1
  15. package/dist/0~7754.js +5653 -0
  16. package/dist/0~9445.js +1 -1
  17. package/dist/0~document-editor.js +4992 -3323
  18. package/dist/0~markdown-editor.js +250 -44
  19. package/dist/0~pdf-viewer.js +1016 -24
  20. package/dist/0~presentation-editor.js +179 -8
  21. package/dist/0~spreadsheet-editor.js +3371 -578
  22. package/dist/0~work-docx-export.js +6801 -658
  23. package/dist/0~work-docx-import.js +1388 -795
  24. package/dist/0~work-office-diagnostics.js +524 -30
  25. package/dist/0~work-pptx-export.js +2 -1
  26. package/dist/0~work-pptx-import.js +1 -2
  27. package/dist/0~work-presentation-charts.js +1 -1
  28. package/dist/2591.js +197 -0
  29. package/dist/3818.js +1090 -0
  30. package/dist/4104.js +970 -60
  31. package/dist/432.js +171 -14
  32. package/dist/4476.js +2008 -0
  33. package/dist/4560.js +674 -0
  34. package/dist/4650.js +70 -0
  35. package/dist/{1134.js → 5184.js} +183 -1
  36. package/dist/6489.js +18 -18
  37. package/dist/7060.js +132 -0
  38. package/dist/8715.js +2 -136
  39. package/dist/8928.js +16778 -0
  40. package/dist/9787.js +209 -0
  41. package/dist/core.d.ts +29 -9
  42. package/dist/core.js +10 -2
  43. package/dist/index.js +13 -3
  44. package/dist/internal/collaboration/office-collaboration-flat-json.d.ts +13 -0
  45. package/dist/internal/collaboration/office-collaboration-json.d.ts +4 -0
  46. package/dist/internal/collaboration/office-collaboration-presence.d.ts +86 -0
  47. package/dist/internal/collaboration/office-collaboration-transport.d.ts +42 -0
  48. package/dist/internal/collaboration/office-collaboration.d.ts +85 -0
  49. package/dist/internal/collaboration/office-document-collaboration-bibliography.d.ts +7 -0
  50. package/dist/internal/collaboration/office-document-collaboration-claims.d.ts +9 -0
  51. package/dist/internal/collaboration/office-document-collaboration-comments.d.ts +7 -0
  52. package/dist/internal/collaboration/office-document-collaboration-sidecar-utils.d.ts +27 -0
  53. package/dist/internal/collaboration/office-document-collaboration-sidecars.d.ts +16 -0
  54. package/dist/internal/collaboration/office-document-collaboration.d.ts +45 -0
  55. package/dist/internal/collaboration/office-markdown-collaboration.d.ts +31 -0
  56. package/dist/internal/collaboration/office-pdf-collaboration-claims.d.ts +4 -0
  57. package/dist/internal/collaboration/office-pdf-collaboration-conflicts.d.ts +2 -0
  58. package/dist/internal/collaboration/office-pdf-collaboration-model.d.ts +26 -0
  59. package/dist/internal/collaboration/office-pdf-collaboration-records.d.ts +21 -0
  60. package/dist/internal/collaboration/office-pdf-collaboration-types.d.ts +91 -0
  61. package/dist/internal/collaboration/office-pdf-collaboration-validation.d.ts +4 -0
  62. package/dist/internal/collaboration/office-pdf-collaboration.d.ts +35 -0
  63. package/dist/internal/collaboration/office-presentation-collaboration-model.d.ts +25 -0
  64. package/dist/internal/collaboration/office-presentation-collaboration-records.d.ts +22 -0
  65. package/dist/internal/collaboration/office-presentation-collaboration-validation.d.ts +4 -0
  66. package/dist/internal/collaboration/office-presentation-collaboration.d.ts +32 -0
  67. package/dist/internal/collaboration/office-spreadsheet-collaboration-cells.d.ts +13 -0
  68. package/dist/internal/collaboration/office-spreadsheet-collaboration-claims.d.ts +4 -0
  69. package/dist/internal/collaboration/office-spreadsheet-collaboration-conflicts.d.ts +2 -0
  70. package/dist/internal/collaboration/office-spreadsheet-collaboration-flat-json.d.ts +10 -0
  71. package/dist/internal/collaboration/office-spreadsheet-collaboration-model.d.ts +31 -0
  72. package/dist/internal/collaboration/office-spreadsheet-collaboration-records.d.ts +17 -0
  73. package/dist/internal/collaboration/office-spreadsheet-collaboration-validation.d.ts +4 -0
  74. package/dist/internal/collaboration/office-spreadsheet-collaboration.d.ts +32 -0
  75. package/dist/internal/design-system/primitives/navigation/tabs.d.ts +3 -1
  76. package/dist/internal/features/work/components/work-document-page-border.d.ts +6 -0
  77. package/dist/internal/features/work/editors/document-command-catalog.d.ts +536 -0
  78. package/dist/internal/features/work/editors/document-editor-focus.d.ts +1 -1
  79. package/dist/internal/features/work/editors/document-editor-support.d.ts +7 -3
  80. package/dist/internal/features/work/editors/document-editor.d.ts +8 -2
  81. package/dist/internal/features/work/editors/document-external-content.d.ts +14 -0
  82. package/dist/internal/features/work/editors/document-format-clipboard.d.ts +6 -0
  83. package/dist/internal/features/work/editors/document-format-tools.d.ts +4 -0
  84. package/dist/internal/features/work/editors/document-layout-panel.d.ts +4 -1
  85. package/dist/internal/features/work/editors/document-page-chrome-wps-shortcuts.d.ts +2 -0
  86. package/dist/internal/features/work/editors/document-page-layout-ribbon.d.ts +14 -0
  87. package/dist/internal/features/work/editors/document-page-stack.d.ts +10 -1
  88. package/dist/internal/features/work/editors/document-page-thumbnail.d.ts +2 -0
  89. package/dist/internal/features/work/editors/document-pagination-run-coordinator.d.ts +26 -0
  90. package/dist/internal/features/work/editors/document-picture-properties-dialog-model.d.ts +20 -1
  91. package/dist/internal/features/work/editors/document-review-navigation.d.ts +9 -0
  92. package/dist/internal/features/work/editors/document-statistics-dialog.d.ts +7 -0
  93. package/dist/internal/features/work/editors/document-status-bar.d.ts +2 -1
  94. package/dist/internal/features/work/editors/document-table-properties-dialog-model.d.ts +4 -1
  95. package/dist/internal/features/work/editors/document-toolbar.d.ts +19 -42
  96. package/dist/internal/features/work/editors/document-wps-shortcuts.d.ts +12 -0
  97. package/dist/internal/features/work/editors/document-zoom.d.ts +17 -0
  98. package/dist/internal/features/work/editors/markdown-editor-focus.d.ts +1 -1
  99. package/dist/internal/features/work/editors/markdown-editor.d.ts +5 -1
  100. package/dist/internal/features/work/editors/markdown-toolbar.d.ts +2 -1
  101. package/dist/internal/features/work/editors/office-collaboration-participants.d.ts +3 -0
  102. package/dist/internal/features/work/editors/office-collaboration-presence-context.d.ts +17 -0
  103. package/dist/internal/features/work/editors/office-collaboration-presence-ui.d.ts +25 -0
  104. package/dist/internal/features/work/editors/office-editor-focus-handoff.d.ts +27 -0
  105. package/dist/internal/features/work/editors/pdf-annotation-controller.d.ts +5 -0
  106. package/dist/internal/features/work/editors/pdf-collaboration-presence.d.ts +3 -0
  107. package/dist/internal/features/work/editors/pdf-collaboration-projection.d.ts +10 -0
  108. package/dist/internal/features/work/editors/pdf-evidence-contract.d.ts +36 -0
  109. package/dist/internal/features/work/editors/pdf-evidence-overlay.d.ts +37 -0
  110. package/dist/internal/features/work/editors/pdf-toolbar.d.ts +2 -1
  111. package/dist/internal/features/work/editors/pdf-viewer-controller.d.ts +7 -1
  112. package/dist/internal/features/work/editors/pdf-viewer.d.ts +11 -1
  113. package/dist/internal/features/work/editors/presentation-collaboration-presence.d.ts +5 -0
  114. package/dist/internal/features/work/editors/presentation-editor-focus.d.ts +3 -2
  115. package/dist/internal/features/work/editors/presentation-editor-types.d.ts +3 -0
  116. package/dist/internal/features/work/editors/presentation-editor.d.ts +1 -1
  117. package/dist/internal/features/work/editors/spreadsheet-auto-filter.d.ts +9 -0
  118. package/dist/internal/features/work/editors/spreadsheet-cell-clear.d.ts +3 -0
  119. package/dist/internal/features/work/editors/spreadsheet-cell-merge.d.ts +12 -0
  120. package/dist/internal/features/work/editors/spreadsheet-clipboard-shortcuts.d.ts +3 -7
  121. package/dist/internal/features/work/editors/spreadsheet-collaboration-presence.d.ts +9 -0
  122. package/dist/internal/features/work/editors/spreadsheet-command-catalog.d.ts +464 -0
  123. package/dist/internal/features/work/editors/spreadsheet-command-controller.d.ts +45 -9
  124. package/dist/internal/features/work/editors/spreadsheet-context-menu.d.ts +2 -0
  125. package/dist/internal/features/work/editors/spreadsheet-editor-ribbon.d.ts +9 -28
  126. package/dist/internal/features/work/editors/spreadsheet-editor.d.ts +8 -2
  127. package/dist/internal/features/work/editors/spreadsheet-format-painter.d.ts +27 -0
  128. package/dist/internal/features/work/editors/spreadsheet-freeze-panes.d.ts +14 -0
  129. package/dist/internal/features/work/editors/use-document-insert-commands.d.ts +3 -2
  130. package/dist/internal/features/work/editors/use-document-pagination.d.ts +6 -1
  131. package/dist/internal/features/work/editors/use-document-review-conflicts.d.ts +28 -0
  132. package/dist/internal/features/work/editors/use-spreadsheet-auto-filter.d.ts +21 -0
  133. package/dist/internal/features/work/editors/use-spreadsheet-collaboration.d.ts +27 -0
  134. package/dist/internal/features/work/editors/use-spreadsheet-format-painter.d.ts +18 -0
  135. package/dist/internal/features/work/editors/work-office-chrome.d.ts +22 -3
  136. package/dist/internal/features/work/editors/work-office-ribbon-overflow.d.ts +2 -0
  137. package/dist/internal/features/work/work-document-bookmark-references.d.ts +37 -0
  138. package/dist/internal/features/work/work-document-bookmarks.d.ts +29 -0
  139. package/dist/internal/features/work/work-document-caption-nodes.d.ts +4 -1
  140. package/dist/internal/features/work/work-document-comments.d.ts +1 -1
  141. package/dist/internal/features/work/work-document-equations.d.ts +513 -0
  142. package/dist/internal/features/work/work-document-extensions.d.ts +1 -0
  143. package/dist/internal/features/work/work-document-field-identity.d.ts +2 -0
  144. package/dist/internal/features/work/work-document-field-node.d.ts +2 -2
  145. package/dist/internal/features/work/work-document-fields.d.ts +7 -0
  146. package/dist/internal/features/work/work-document-image-identity.d.ts +30 -0
  147. package/dist/internal/features/work/work-document-image-layout.d.ts +46 -1
  148. package/dist/internal/features/work/work-document-image-wrap-contour.d.ts +16 -0
  149. package/dist/internal/features/work/work-document-incremental-layout.d.ts +2 -2
  150. package/dist/internal/features/work/work-document-model-codec.d.ts +4 -1
  151. package/dist/internal/features/work/work-document-note-integrity.d.ts +2 -0
  152. package/dist/internal/features/work/work-document-page-borders.d.ts +25 -0
  153. package/dist/internal/features/work/work-document-page-capture.d.ts +8 -0
  154. package/dist/internal/features/work/work-document-page-frames.d.ts +15 -0
  155. package/dist/internal/features/work/work-document-page-margins.d.ts +56 -0
  156. package/dist/internal/features/work/work-document-page-size.d.ts +47 -0
  157. package/dist/internal/features/work/work-document-pagination-measurement.d.ts +1 -2
  158. package/dist/internal/features/work/work-document-pagination-types.d.ts +7 -2
  159. package/dist/internal/features/work/work-document-pagination.d.ts +2 -2
  160. package/dist/internal/features/work/work-document-paragraph-borders.d.ts +32 -0
  161. package/dist/internal/features/work/work-document-paragraph-identity.d.ts +26 -0
  162. package/dist/internal/features/work/work-document-paragraph-shading.d.ts +18 -0
  163. package/dist/internal/features/work/work-document-review-conflicts.d.ts +35 -0
  164. package/dist/internal/features/work/work-document-section.d.ts +4 -0
  165. package/dist/internal/features/work/work-document-snapshot.d.ts +19 -0
  166. package/dist/internal/features/work/work-document-source.d.ts +23 -0
  167. package/dist/internal/features/work/work-document-table-column-widths.d.ts +7 -0
  168. package/dist/internal/features/work/work-document-table-property-changes.d.ts +3 -0
  169. package/dist/internal/features/work/work-document-table-row-identity.d.ts +15 -0
  170. package/dist/internal/features/work/work-document-table-sizing.d.ts +3 -0
  171. package/dist/internal/features/work/work-document-text-layout.d.ts +3 -1
  172. package/dist/internal/features/work/work-document-word-line-metrics.d.ts +2 -0
  173. package/dist/internal/features/work/work-docx-bookmark-diagnostics.d.ts +3 -0
  174. package/dist/internal/features/work/work-docx-bookmark-import.d.ts +24 -0
  175. package/dist/internal/features/work/work-docx-bookmarks.d.ts +17 -0
  176. package/dist/internal/features/work/work-docx-comment-durable-id-preservation.d.ts +2 -0
  177. package/dist/internal/features/work/work-docx-comment-export.d.ts +3 -0
  178. package/dist/internal/features/work/work-docx-comment-metadata.d.ts +2 -0
  179. package/dist/internal/features/work/work-docx-drawing-extension-preservation.d.ts +4 -0
  180. package/dist/internal/features/work/work-docx-equation-diagnostics.d.ts +3 -0
  181. package/dist/internal/features/work/work-docx-equation-export.d.ts +14 -0
  182. package/dist/internal/features/work/work-docx-equation-import.d.ts +30 -0
  183. package/dist/internal/features/work/work-docx-equation-story.d.ts +9 -0
  184. package/dist/internal/features/work/work-docx-export-formatting.d.ts +3 -1
  185. package/dist/internal/features/work/work-docx-export-image.d.ts +5 -1
  186. package/dist/internal/features/work/work-docx-export.d.ts +1 -1
  187. package/dist/internal/features/work/work-docx-field-instructions.d.ts +8 -0
  188. package/dist/internal/features/work/work-docx-font-table-preservation.d.ts +3 -0
  189. package/dist/internal/features/work/work-docx-ignorable-extension-preservation.d.ts +15 -0
  190. package/dist/internal/features/work/work-docx-image-crop.d.ts +12 -0
  191. package/dist/internal/features/work/work-docx-image-identity.d.ts +17 -0
  192. package/dist/internal/features/work/work-docx-image-layer.d.ts +12 -0
  193. package/dist/internal/features/work/work-docx-image-layout-import.d.ts +14 -2
  194. package/dist/internal/features/work/work-docx-image-wrap.d.ts +15 -0
  195. package/dist/internal/features/work/work-docx-import.d.ts +13 -3
  196. package/dist/internal/features/work/work-docx-list-export.d.ts +18 -0
  197. package/dist/internal/features/work/work-docx-list-import.d.ts +14 -0
  198. package/dist/internal/features/work/work-docx-note-comment-content-control-block-preservation.d.ts +18 -0
  199. package/dist/internal/features/work/work-docx-note-comment-content-control-model.d.ts +47 -0
  200. package/dist/internal/features/work/work-docx-note-comment-content-control-preservation.d.ts +4 -0
  201. package/dist/internal/features/work/work-docx-note-comment-content-control-properties.d.ts +17 -0
  202. package/dist/internal/features/work/work-docx-note-comment-content-control-table-model.d.ts +17 -0
  203. package/dist/internal/features/work/work-docx-note-comment-content-control-xml.d.ts +14 -0
  204. package/dist/internal/features/work/work-docx-note-comment-extension-preservation.d.ts +2 -0
  205. package/dist/internal/features/work/work-docx-note-comment-hyperlink-content.d.ts +40 -0
  206. package/dist/internal/features/work/work-docx-note-comment-hyperlink-preservation.d.ts +5 -0
  207. package/dist/internal/features/work/work-docx-note-comment-hyperlink-relationships.d.ts +35 -0
  208. package/dist/internal/features/work/work-docx-note-comment-identity.d.ts +15 -0
  209. package/dist/internal/features/work/work-docx-note-comment-run-preservation.d.ts +4 -0
  210. package/dist/internal/features/work/work-docx-note-comment-run-properties.d.ts +2 -0
  211. package/dist/internal/features/work/work-docx-note-image-import.d.ts +12 -0
  212. package/dist/internal/features/work/work-docx-note-image-relationships.d.ts +1 -0
  213. package/dist/internal/features/work/work-docx-numbering-extension-preservation.d.ts +6 -0
  214. package/dist/internal/features/work/work-docx-numbering.d.ts +1 -0
  215. package/dist/internal/features/work/work-docx-page-borders-diagnostics.d.ts +3 -0
  216. package/dist/internal/features/work/work-docx-page-borders-import.d.ts +10 -0
  217. package/dist/internal/features/work/work-docx-page-margins-diagnostics.d.ts +3 -0
  218. package/dist/internal/features/work/work-docx-page-margins-import.d.ts +18 -0
  219. package/dist/internal/features/work/work-docx-page-size-diagnostics.d.ts +2 -0
  220. package/dist/internal/features/work/work-docx-page-size-import.d.ts +17 -0
  221. package/dist/internal/features/work/work-docx-paragraph-borders-diagnostics.d.ts +3 -0
  222. package/dist/internal/features/work/work-docx-paragraph-borders-export.d.ts +18 -0
  223. package/dist/internal/features/work/work-docx-paragraph-borders-import.d.ts +24 -0
  224. package/dist/internal/features/work/work-docx-paragraph-default-collapsed.d.ts +19 -0
  225. package/dist/internal/features/work/work-docx-paragraph-extension-preservation.d.ts +2 -0
  226. package/dist/internal/features/work/work-docx-paragraph-identity-import.d.ts +10 -0
  227. package/dist/internal/features/work/work-docx-paragraph-identity.d.ts +18 -0
  228. package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +6 -1
  229. package/dist/internal/features/work/work-docx-paragraph-shading-diagnostics.d.ts +3 -0
  230. package/dist/internal/features/work/work-docx-paragraph-shading-export.d.ts +5 -0
  231. package/dist/internal/features/work/work-docx-paragraph-shading-import.d.ts +18 -0
  232. package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +3 -0
  233. package/dist/internal/features/work/work-docx-settings-preservation.d.ts +10 -0
  234. package/dist/internal/features/work/work-docx-settings-xml.d.ts +16 -0
  235. package/dist/internal/features/work/work-docx-style-extension-preservation.d.ts +2 -0
  236. package/dist/internal/features/work/work-docx-table-cell-export.d.ts +2 -1
  237. package/dist/internal/features/work/work-docx-table-cell-import.d.ts +3 -0
  238. package/dist/internal/features/work/work-docx-table-extension-preservation.d.ts +2 -0
  239. package/dist/internal/features/work/work-docx-table-row-import.d.ts +2 -0
  240. package/dist/internal/features/work/work-docx-table-sizing-import.d.ts +1 -0
  241. package/dist/internal/features/work/work-docx-theme-reference.d.ts +23 -0
  242. package/dist/internal/features/work/work-docx-theme.d.ts +4 -1
  243. package/dist/internal/features/work/work-docx-twips.d.ts +12 -0
  244. package/dist/internal/features/work/work-file-contract.d.ts +1 -0
  245. package/dist/internal/features/work/work-file-io.d.ts +1 -1
  246. package/dist/internal/features/work/work-markdown-extensions.d.ts +4 -1
  247. package/dist/internal/features/work/work-ooxml-package-preservation.d.ts +12 -0
  248. package/dist/internal/features/work/work-ooxml-package-security.d.ts +6 -0
  249. package/dist/internal/features/work/work-ooxml-relationship-preservation.d.ts +10 -0
  250. package/dist/internal/features/work/work-ooxml-xml.d.ts +2 -0
  251. package/dist/internal/features/work/work-pdf-export.d.ts +10 -0
  252. package/dist/internal/features/work/work-repository.d.ts +2 -0
  253. package/dist/internal/features/work/work-types.d.ts +15 -2
  254. package/dist/internal/kernel/office-kernel-client-types.d.ts +1 -0
  255. package/dist/internal/kernel/office-kernel-protocol.d.ts +7 -0
  256. package/dist/internal/kernel/office-kernel-version.d.ts +1 -1
  257. package/dist/office-kernel.wasm +0 -0
  258. package/dist/office-kernel.worker.js +93 -41
  259. package/dist/react.d.ts +18 -12
  260. package/dist/react.js +1 -1
  261. package/dist/styles.css +1367 -16
  262. package/dist/vue.d.ts +48 -5
  263. package/dist/vue.js +42 -3
  264. package/dist/web-component.d.ts +24 -2
  265. package/dist/web-component.js +101 -2
  266. package/docs/latest/en/browser-editor-architecture.md +262 -47
  267. package/package.json +29 -4
  268. package/dist/0~152.js +0 -94
  269. package/dist/0~2582.js +0 -485
  270. package/dist/0~4750.js +0 -939
  271. package/dist/0~5861.js +0 -596
  272. package/dist/0~work-document-extensions.js +0 -3045
  273. package/dist/0~work-document-model-codec.js +0 -42
  274. package/dist/0~work-docx-bibliography.js +0 -347
  275. package/dist/0~work-docx-page-color.js +0 -42
  276. package/dist/2881.js +0 -1455
  277. package/dist/8728.js +0 -723
package/dist/0~5050.js CHANGED
@@ -1,8 +1,114 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { Copy, Languages, MessageSquareText, Sparkles, TextQuote, WandSparkles } from "lucide-react";
3
3
  import { showToast, createAgentProposalRequest as createWorkAgentProposalRequest } from "./6489.js";
4
- const MIN_DOCUMENT_ZOOM = 50;
5
- const MAX_DOCUMENT_ZOOM = 200;
4
+ const SURROUNDING_TEXT_LIMIT = 2000;
5
+ function createWorkDocumentSelectionSnapshot(editor, content) {
6
+ const { from, to, empty } = editor.state.selection;
7
+ if (empty) return null;
8
+ const rawText = editor.state.doc.textBetween(from, to, '\n');
9
+ const text = rawText.trim();
10
+ if (!text) return null;
11
+ const beforeText = editor.state.doc.textBetween(0, from, '\n').slice(-SURROUNDING_TEXT_LIMIT);
12
+ const afterText = editor.state.doc.textBetween(to, editor.state.doc.content.size, '\n').slice(0, SURROUNDING_TEXT_LIMIT);
13
+ const selectedContent = editor.state.selection.content().content.toJSON();
14
+ return {
15
+ selection: {
16
+ from,
17
+ to,
18
+ text,
19
+ rawText,
20
+ beforeText,
21
+ afterText,
22
+ model: {
23
+ type: 'doc',
24
+ ...selectedContent?.length ? {
25
+ content: selectedContent
26
+ } : {}
27
+ }
28
+ },
29
+ document: {
30
+ content,
31
+ html: editor.getHTML(),
32
+ text: editor.state.doc.textBetween(0, editor.state.doc.content.size, '\n')
33
+ }
34
+ };
35
+ }
36
+ function createWorkDocumentSelectionAction(editor, snapshot, getTrackChanges) {
37
+ let from = snapshot.selection.from;
38
+ let to = snapshot.selection.to;
39
+ let stale = false;
40
+ let disposed = false;
41
+ const handleTransaction = ({ transaction })=>{
42
+ if (!transaction.docChanged || stale || disposed) return;
43
+ const mappedFrom = transaction.mapping.mapResult(from, 1);
44
+ const mappedTo = transaction.mapping.mapResult(to, -1);
45
+ from = mappedFrom.pos;
46
+ to = mappedTo.pos;
47
+ stale = mappedFrom.deletedAcross || mappedTo.deletedAcross || from > to || transaction.doc.textBetween(from, to, '\n') !== snapshot.selection.rawText;
48
+ };
49
+ editor.on('transaction', handleTransaction);
50
+ const currentRange = ()=>{
51
+ if (disposed || editor.isDestroyed) return 'editor-unavailable';
52
+ if (!editor.isEditable) return 'read-only';
53
+ if (stale || from < 0 || to < from || to > editor.state.doc.content.size || editor.state.doc.textBetween(from, to, '\n') !== snapshot.selection.rawText) return 'stale-selection';
54
+ return {
55
+ from,
56
+ to
57
+ };
58
+ };
59
+ const editText = (text, placement)=>{
60
+ if ('string' != typeof text || 'replace' !== placement && !text) return {
61
+ applied: false,
62
+ reason: 'invalid-text'
63
+ };
64
+ const range = currentRange();
65
+ if ('string' == typeof range) return {
66
+ applied: false,
67
+ reason: range
68
+ };
69
+ const editRange = 'before' === placement ? {
70
+ from: range.from,
71
+ to: range.from
72
+ } : 'after' === placement ? {
73
+ from: range.to,
74
+ to: range.to
75
+ } : range;
76
+ const applied = getTrackChanges() ? editor.commands.replaceDocumentTextWithTrackedChange(editRange.from, editRange.to, text) : editor.chain().focus().setTextSelection(editRange).insertContent(documentPlainTextAsHtml(text)).run();
77
+ return applied ? {
78
+ applied: true
79
+ } : {
80
+ applied: false,
81
+ reason: 'command-rejected'
82
+ };
83
+ };
84
+ return {
85
+ context: {
86
+ ...snapshot,
87
+ commands: {
88
+ copyText: async ()=>{
89
+ try {
90
+ if ("u" < typeof navigator || !navigator.clipboard?.writeText) return false;
91
+ await navigator.clipboard.writeText(snapshot.selection.rawText);
92
+ return true;
93
+ } catch {
94
+ return false;
95
+ }
96
+ },
97
+ insertAfter: (text)=>editText(text, 'after'),
98
+ insertBefore: (text)=>editText(text, 'before'),
99
+ replaceText: (text)=>editText(text, 'replace')
100
+ }
101
+ },
102
+ dispose: ()=>{
103
+ if (disposed) return;
104
+ disposed = true;
105
+ editor.off('transaction', handleTransaction);
106
+ }
107
+ };
108
+ }
109
+ function documentPlainTextAsHtml(value) {
110
+ return value.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#39;').replace(/\r?\n/g, '<br>');
111
+ }
6
112
  function documentAgentMenuItems(selection, onAgentRequest, proposalOptions) {
7
113
  return [
8
114
  {
@@ -173,8 +279,21 @@ function documentCurrentPage(editor) {
173
279
  function documentWordCount(value) {
174
280
  return Array.from(value.matchAll(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]|[\p{L}\p{N}]+/gu)).length;
175
281
  }
176
- function clampDocumentZoom(zoom) {
177
- return Math.min(MAX_DOCUMENT_ZOOM, Math.max(MIN_DOCUMENT_ZOOM, Math.round(zoom)));
282
+ function documentTextStatistics(editor) {
283
+ const text = editor.getText({
284
+ blockSeparator: '\n'
285
+ });
286
+ const characters = Array.from(text).filter((character)=>'\n' !== character && '\r' !== character);
287
+ let paragraphCount = 0;
288
+ editor.state.doc.descendants((node)=>{
289
+ if (node.isTextblock) paragraphCount += 1;
290
+ });
291
+ return {
292
+ characterCountWithSpaces: characters.length,
293
+ characterCountWithoutSpaces: characters.filter((character)=>!/\s/u.test(character)).length,
294
+ paragraphCount,
295
+ wordCount: documentWordCount(text)
296
+ };
178
297
  }
179
298
  async function copyDocumentSelection(selection) {
180
299
  try {
@@ -185,114 +304,6 @@ async function copyDocumentSelection(selection) {
185
304
  showToast('无法访问剪贴板,请使用系统复制快捷键。', 'error');
186
305
  }
187
306
  }
188
- const SURROUNDING_TEXT_LIMIT = 2000;
189
- function createWorkDocumentSelectionSnapshot(editor, content) {
190
- const { from, to, empty } = editor.state.selection;
191
- if (empty) return null;
192
- const rawText = editor.state.doc.textBetween(from, to, '\n');
193
- const text = rawText.trim();
194
- if (!text) return null;
195
- const beforeText = editor.state.doc.textBetween(0, from, '\n').slice(-SURROUNDING_TEXT_LIMIT);
196
- const afterText = editor.state.doc.textBetween(to, editor.state.doc.content.size, '\n').slice(0, SURROUNDING_TEXT_LIMIT);
197
- const selectedContent = editor.state.selection.content().content.toJSON();
198
- return {
199
- selection: {
200
- from,
201
- to,
202
- text,
203
- rawText,
204
- beforeText,
205
- afterText,
206
- model: {
207
- type: 'doc',
208
- ...selectedContent?.length ? {
209
- content: selectedContent
210
- } : {}
211
- }
212
- },
213
- document: {
214
- content,
215
- html: editor.getHTML(),
216
- text: editor.state.doc.textBetween(0, editor.state.doc.content.size, '\n')
217
- }
218
- };
219
- }
220
- function createWorkDocumentSelectionAction(editor, snapshot, getTrackChanges) {
221
- let from = snapshot.selection.from;
222
- let to = snapshot.selection.to;
223
- let stale = false;
224
- let disposed = false;
225
- const handleTransaction = ({ transaction })=>{
226
- if (!transaction.docChanged || stale || disposed) return;
227
- const mappedFrom = transaction.mapping.mapResult(from, 1);
228
- const mappedTo = transaction.mapping.mapResult(to, -1);
229
- from = mappedFrom.pos;
230
- to = mappedTo.pos;
231
- stale = mappedFrom.deletedAcross || mappedTo.deletedAcross || from > to || transaction.doc.textBetween(from, to, '\n') !== snapshot.selection.rawText;
232
- };
233
- editor.on('transaction', handleTransaction);
234
- const currentRange = ()=>{
235
- if (disposed || editor.isDestroyed) return 'editor-unavailable';
236
- if (!editor.isEditable) return 'read-only';
237
- if (stale || from < 0 || to < from || to > editor.state.doc.content.size || editor.state.doc.textBetween(from, to, '\n') !== snapshot.selection.rawText) return 'stale-selection';
238
- return {
239
- from,
240
- to
241
- };
242
- };
243
- const editText = (text, placement)=>{
244
- if ('string' != typeof text || 'replace' !== placement && !text) return {
245
- applied: false,
246
- reason: 'invalid-text'
247
- };
248
- const range = currentRange();
249
- if ('string' == typeof range) return {
250
- applied: false,
251
- reason: range
252
- };
253
- const editRange = 'before' === placement ? {
254
- from: range.from,
255
- to: range.from
256
- } : 'after' === placement ? {
257
- from: range.to,
258
- to: range.to
259
- } : range;
260
- const applied = getTrackChanges() ? editor.commands.replaceDocumentTextWithTrackedChange(editRange.from, editRange.to, text) : editor.chain().focus().setTextSelection(editRange).insertContent(documentPlainTextAsHtml(text)).run();
261
- return applied ? {
262
- applied: true
263
- } : {
264
- applied: false,
265
- reason: 'command-rejected'
266
- };
267
- };
268
- return {
269
- context: {
270
- ...snapshot,
271
- commands: {
272
- copyText: async ()=>{
273
- try {
274
- if ("u" < typeof navigator || !navigator.clipboard?.writeText) return false;
275
- await navigator.clipboard.writeText(snapshot.selection.rawText);
276
- return true;
277
- } catch {
278
- return false;
279
- }
280
- },
281
- insertAfter: (text)=>editText(text, 'after'),
282
- insertBefore: (text)=>editText(text, 'before'),
283
- replaceText: (text)=>editText(text, 'replace')
284
- }
285
- },
286
- dispose: ()=>{
287
- if (disposed) return;
288
- disposed = true;
289
- editor.off('transaction', handleTransaction);
290
- }
291
- };
292
- }
293
- function documentPlainTextAsHtml(value) {
294
- return value.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#39;').replace(/\r?\n/g, '<br>');
295
- }
296
307
  function mergeOfficeTiptapExtensions(editorName, builtInExtensions, additionalExtensions) {
297
308
  const names = new Set();
298
309
  for (const extension of builtInExtensions)names.add(extension.name);
@@ -305,4 +316,4 @@ function mergeOfficeTiptapExtensions(editorName, builtInExtensions, additionalEx
305
316
  ...additionalExtensions
306
317
  ];
307
318
  }
308
- export { clampDocumentZoom, createWorkDocumentSelectionAction, createWorkDocumentSelectionSnapshot, customSelectionMenuItems, documentAgentMenuItems, documentCurrentPage, documentCustomSelectionMenuItems, documentPageCount, documentPlainTextAsHtml, documentWordCount, mergeOfficeTiptapExtensions };
319
+ export { createWorkDocumentSelectionAction, createWorkDocumentSelectionSnapshot, customSelectionMenuItems, documentAgentMenuItems, documentCurrentPage, documentCustomSelectionMenuItems, documentPageCount, documentPlainTextAsHtml, documentTextStatistics, mergeOfficeTiptapExtensions };